2

I am trying to find the distance between two points (in meters and not degrees) using GIS Tools for Hadoop by ESRI. The ST_Length provides distance in degrees and hence I used the ST_GeodesicLengthWGS84 function. However, I noticed that the distances are not what I would expect to see. Below are the queries I tried:

SELECT  ST_GeodesicLengthWGS84(ST_SetSRID(ST_Linestring(0.0,0.0, 0.3,0.4), 4326))/1000;
SELECT ST_GeodesicLengthWGS84(ST_SetSRID(ST_Linestring(40.773773, -73.872307, 40.973773, -73.772307), 4326))/1000;
SELECT ST_GeodesicLengthWGS84(ST_SetSRID(ST_Linestring(40.773773, -73.872307, 33.944115, -118.40377), 4326))/1000;

I also used the distance calculator to check the distance (http://andrew.hedges.name/experiments/haversine/) and also google maps for directional reference (Google is a road distance, so it cannot be less than the distance from the above queries)

Here are the results I see for the three queries:
1) 55.42 (55.615 KM from distance calculator)
2) 12.77 (23.73 KM from distance calculator and 33.2 KM from google maps)
3) 4962.36 (3966.188 from distance calculator and 4536 KM from google maps)

Can someone tell me in case I misunderstood the use of this formula? And what would be the right way to get the distance in meters/KM?

4
  • The distance calculator in that URL uses the Haversine formula on a sphere, so the results will not be very accurate.
    – Mintx
    Commented Feb 1, 2016 at 22:12
  • @Mintx: The haversine formula is certainly not very accurate but if you look at some of the numbers i got, they are very different. For short distances like the second example, I do not expect such a difference. And on the third example, google maps distance (road distance) is less than the distance from the query(straight line distance) and that raises a red flag
    – Harish
    Commented Feb 2, 2016 at 5:51
  • ST_Linestring may be expecting (X, Y) so try swapping your latitude and longitude values.
    – Mintx
    Commented Feb 2, 2016 at 16:44
  • @Mintx: Seems like that was the case - thank you very much
    – Harish
    Commented Feb 2, 2016 at 20:06

1 Answer 1

0

ST_Linestring expects arguments in (Longitude, Latitude) so just switch the coordinates around.

1
  • Correct, just like X,Y coordinate order in a plane. [collaborator] Commented Feb 26, 2016 at 16:23

Your Answer

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

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