3

Could someone please explain why there is such a significant difference between the results of this query:

SELECT 
    ST_Distance(ST_Transform(previous_geom,3857), ST_Transform(current_geom,3857)) AS distance_transform_exp,
    ST_Distance(previous_geom::geography, current_geom::geography) AS distance_geometry_exp
FROM
(
    SELECT 
        ST_SetSRID(ST_MakePoint(-111.9096893, 40.7411742),4326) AS previous_geom,
        ST_SetSRID(ST_MakePoint(-111.9092079, 40.74135181),4326) AS current_geom
) points_table

Results:

 distance_transform_exp | distance_geometry_exp
+-----------------------+-----------------------
       59.6050787601899 |           45.19182216
(1 row)

I understand there would be a difference between geometric (Cartesian) calculation results and geodetic (spheroid) alas for the example points which are relatively close, the discrepancy would be expected to be negligible.

Vince
  • 20,017
  • 15
  • 45
  • 64
Nona Bene
  • 33
  • 3
  • try this function on the geographies https://postgis.net/docs/ST_Distance_Spheroid.html – ziggy Dec 11 '17 at 14:47

1 Answers1

5

Although the question is different, the answer is the same as this one.


ST_Distance(previous_geom::geography, current_geom::geography) is the correct result.

WGS 84 / Pseudo-Mercator (EPSG:3857) projection is heavily distorted when moving away from the equator. Thus, it could be discussed if the units should be called "Pseudo-meters". One meter in reality is approximately 1/cos(lat) pseudo-meters.

45.19 m / cos(40.7°) = 59.6 pseudo-meters

enter image description here

CC BY-SA 3.0, Author: Stefan Kühn

pLumo
  • 6,489
  • 20
  • 41
  • so distances should never be measured in 3857? – ziggy Dec 11 '17 at 15:18
  • Exactly. Better to use postgis' geography type or the local standard CRS, e.g. the UTM zones. – pLumo Dec 11 '17 at 15:20
  • so if google maps is in 3857 how do they give back accurate distances? – ziggy Dec 11 '17 at 15:24
  • 1
    The pictures are 3857 but not the measurements probably ... – pLumo Dec 11 '17 at 15:26
  • right, and there geocoder returns 4326 lat longs – ziggy Dec 11 '17 at 15:27
  • @RoVo: Thank you for your answer. Since EPSG:3857 has meters as its unit of measurement why would it not be a reliable medium for distances calculations? I imagine the stretching of a spheroid onto a planar surface introduces errors, would an infinitesimally small area on a sphere not be flat enough to approximate a 2D plane? – Nona Bene Dec 11 '17 at 15:29
  • because its not meters. only pseudo-meters – pLumo Dec 11 '17 at 15:33
  • 1
    It is flat but it is made flat by stretching the world balloon very heavily near the poles. Meter was meter only before the stretch. – user30184 Dec 11 '17 at 15:43
  • 1
    The only "latitude of true scale" in a mercator projection is at the equator. So you can do direct planar calculations as long as your working area is (a) small and (b) at the equator. If you're willing to scale your results by 1/cos(phi) you can do direct planar calculations as long as (a) your area of interest is small (b) you remember to scale your result. – Paul Ramsey Dec 11 '17 at 16:57