I have a linestring and I want to measure this line. I try it on google maps. the result is that 0,65 km https://www.google.com/maps/dir/40.144048,26.45235/40.138443+26.450246/@40.1412448,26.4467258,16z/data=!3m1!4b1!4m6!4m5!1m0!1m3!2m2!1d26.450246!2d40.138443

Also I try it bing maps. the result isthat 0,60 km. http://www.bing.com/maps/?FORM=Z9LH3#Y3A9NDAuMTQxMjM3fjI2LjQ1MTMyMSZsdmw9MTYmc3R5PXImcnRwPXBvcy40MC4xNDQwNDhfMjYuNDUyMzUwX0QtNTUwJTIwJTI2JTIwJUMzJTg3YW5ha2thbGUlMjBLYXYlQzUlOUZhJUM0JTlGJUM0JUIxJTJDJTIwMTcwMDAlMjAlQzMlODdhbmFra2FsZSUyQyUyMFQlQzMlQkNya2l5ZSUyMHlhayVDNCVCMW5sYXIlQzQlQjFuZGFfX19hX35wb3MuNDAuMTM4NDQzXzI2LjQ1MDI0Nl9ELTU1MCUyQyUyMDE3MDAwJTIwJUMzJTg3YW5ha2thbGUlMkMlMjBUJUMzJUJDcmtpeWUlMjB5YWslQzQlQjFubGFyJUM0JUIxbmRhX19fYV8mbW9kZT1EJnJ0b3A9MH4wfjB+

and I measure it with postgis sql;

SELECT ST_Length(ST_GeomFromText('LINESTRING(40.144048 26.45235,40.138443 26.450246)'));

the result is :0.00598688909200328 km

SELECT ST_Length_Spheroid('LINESTRING(40.144048 26.45235,40.138443 26.450246)', 
                          CAST('SPHEROID["WGS 84",6378137,298.257223563]' As spheroid) );

the result is :605.657141879302 km

I wonder that which one is correct lenght? please say some advice for me ?

  • POSTGIS is your Data in Geography TYPE? gis.stackexchange.com/questions/6681/… then it should be correct
    – Mapperz
    Dec 3, 2014 at 21:34
  • Are you sure that second value isn't 606 meters (not km) which would correspond to ~0.61 km?
    – Vince
    Dec 3, 2014 at 21:50
  • 1
    The first PostGIS value is 0.005986... degrees, not km
    – Vince
    Dec 3, 2014 at 21:52

2 Answers 2


In your ST_GeomFromText code, you are putting the lat and long in EPSG:4326 coordinate system, so your distance is in degrees. Means 0.00598 is in degrees, not in km. Try to enter the coordinates in EPSG:3857, the result should be around 650 meters.

I am not sure about your another approach.

As far as I know, google maps are considering the DEM (ie the height on the surface) also, so should be the best one.

  • The WKT is not necessarily EPSG:4326 lon/lat. You'd need to use ST_GeomFromText('LINESTRING(40.144048 26.45235,40.138443 26.450246)', 4326)
    – BradHards
    Dec 3, 2014 at 23:43

When you wrote: LINESTRING(40.144048 26.45235,40.138443 26.450246) as the WKT, the results are Cartesian. It isn't necessarily degrees (in particular, it isn't in EPSG:4326). So the result of measuring it is just arbitrary Cartesian distance. So you can calculate it with a simple square-root of sum of squares. If you're assuming the input is in degrees, then the output is in degrees. If you're assuming the input is in nautical miles, the the output is in nautical miles.

If you what to do some kind of spheroid calculation, then it depends on the spheroid that you choose. Choosing EPSG:3857 is almost always a bad idea - the world is not a sphere. Therefore, don't use Google.

I'd use the postgis result on geography, noting that the results of the ST_Length on geography are in metres.

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.