# PostGIS - incorrect result distance between two points

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.

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;


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...

• 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 '13 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 '13 at 7:18
• 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. – Paul Ramsey Feb 7 '13 at 19:28