Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgis st_distance returning incorrect results

I am using postgis to calculate distance between 2 geo co-ordinates.

select st_distance(
  'POINT(15.651955 73.712769)'::geography, 
  'POINT(14.806993 74.131451)'::geography) AS d;

It's returning me 53536.743496517meters which is approximately equal to 54km, but the actual distance is 103km which I have calculated via http://boulter.com/gps/distance/

Am I doing anything wrong in the query ?

like image 278
scanE Avatar asked Mar 02 '13 07:03

scanE


1 Answers

POINT() takes its arguments in longitude, latitude. Swap your arguments.

select st_distance(
  'POINT(73.712769 15.651955)'::geography, 
  'POINT(74.131451 14.806993)'::geography) AS d;

st_distance
--
103753.197677054

I make this mistake regularly, because I think in terms of latitude and longitude, not longitude and latitude.

like image 86
Mike Sherrill 'Cat Recall' Avatar answered Nov 16 '22 00:11

Mike Sherrill 'Cat Recall'