# How can I measure linestring on postgis?

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

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 '14 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 '14 at 21:50
• The first PostGIS value is 0.005986... degrees, not km – Vince Dec 3 '14 at 21:52

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.