简体   繁体   中英

In PostGIS which one is the most accurate way to calculate distance between two points?

I'm having problems with st_distance function in postgis. I have three ways to calculate the distance, but I don't know which one is the most accurate.

SELECT ST_Distance('POINT(115.25 39.26)'::geography, 'POINT(117.30 41.04)'::geography) as distance;
--result is 263753.911823565
SELECT ST_Distance_Sphere(ST_GeomFromText('POINT(115.25 39.26)',4326), ST_GeomFromText('POINT(117.30 41.04)',4326)) as distance;
--result is 263674.468686404
SELECT ST_Distance( ST_Transform(ST_GeomFromText('POINT(115.25 39.26)',4326),32650),ST_Transform(ST_GeomFromText('POINT(117.30 41.04)', 4326),32650)) as distance;
--result is 263669.651755417

The difference between the 3 measurement calculations is the following:

  1. The distance is calculated over the spheroid, a mathematical approximation of the earth's surface taking the flattening at the poles into consideration. This is also called the "great arc distance". In this case the default spheroid is WGS84, which is also used by the GPS system and satellite imagery.
  2. The distance is calculated over a sphere, which does not considering flattening (the shape is effectively like a ball). Usually the sphere has the same volume as some spheroid so it is slightly smaller at the equator and slightly bulging at the poles. It is mathematically much simpler than the spheroid and therefore lots faster to calculate.
  3. The distance is calculated on a cartesian coordinate reference system (a plane) established by transforming from geographic coordinates, in this case UTM50N from a WGS84 spheroid.

The first method usually gives the best result (of these 3), but for coordinates that are close together or close to the Equator, the difference would be negligible compared to the faster second method.

The third method is not particularly accurate with the UTM50N(WGS84) coordinate reference system, but a cartesian coordinate system has important other benefits, such as calculating angles between triplets of points or areas of polygons. Also note that some datums in use with local CRSes give a much better local representation of the earth's irregular surface than WGS84 does, in which case a local CRS becomes much more accurate than a great-arc calculation. You would have to look up all the geodetic details of your area to assess that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM