4

I am quite confused the way PostGIS is returning the result for this basic query.

So I am trying to find the distance between two points 45.2714,71.2087 and 42.3739,66.39

and the distance should be ~505 km

but when I ran the query (considering 1 degree = 111km)

select st_distance (st_setsrid(st_makepoint(71.2087,45.2714),4326), 
      st_setsrid(st_makepoint(66.39,42.3739),4326))*111 as d 

I get the result as 624 km.

Can anyone please tell what I am doing wrong here ?

Thanks.

2 Answers 2

4

One degree does not "equal 111km" in generality.

select st_distance(
  'POINT(71.2087 45.2714)'::geography, 
  'POINT(66.39 42.3739)'::geography) AS d;

Or

select st_distance_spheroid(
  'SRID=4326;POINT(71.2087 45.2714)'::geometry, 
  'SRID=4326;POINT(66.39 42.3739)'::geometry,
  'SPHEROID["WGS 84",6378137,298.257223563]') AS d;
2

try to use metric transformation:

SELECT ST_Distance(
            ST_Transform(ST_GeomFromText('POINT(71.2087 45.2714)',4326),900913),
            ST_Transform(ST_GeomFromText('POINT(66.39 42.3739)', 4326),900913)
        );

i hope it helps you...

3
  • Thanks for the reply @Aragon. But the problem was the result was coming out to be wrong. I have calculated the distance between the two mentioned points as ~505km from movable-type.co.uk/scripts/latlong.html and also from Google maps. But your query and also mine returns the result to be ~698 km.
    – reeuv
    Feb 6, 2013 at 21:31
  • Thanks for the reply @aragon. But the problem was the result was coming out to be wrong. I have calculated the distance between the two mentioned points as ~505km from movable-type.co.uk/scripts/latlong.html and also from Google maps. But your query and also mine returns the result to be ~698 km
    – reeuv
    Feb 7, 2013 at 7:18
  • 3
    Mercator (900913) will only give you a "correct" answer at/near the equator (which is the latitude of "true scale" for that parameterization of the Mercator projection). You need a projection better suited to the region of interest, or to do the calculation directly in geodetic space. Feb 7, 2013 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.