# How to measure length of line accurately?

In postgis 1.5 for the below given query the answer is 1540651.62674101 meters ,

``````SELECT ST_Length(ST_GeomFromText('LINESTRING(77.83042478941326
9.98463896136159,78.03469506809812 23.90398909552571 )',4326),true);
``````

but in google earth the same line gives 1538923 meters in its properties, around 0.1% error between the two readings.

Which one is accurate, if Google earth reading is accurate, how to get it in postgis1.5 ...

any idea...

• According to postgis.org/docs/ST_Length.html, ST_Length(Geometry) should return degrees in your example. There is no ST_Length(Geometry,boolean) in PostGIS 1.5. Commented May 24, 2011 at 9:20
• There could be difference in the coordinate systems parameters between the two...which would lead to the disparity. Commented May 24, 2011 at 9:23

Apart from, as @underdark says ST_Length() returns a cartesian distance between the two points which in an unprojected CS is meaningless in this case, I would go with the answer you get from PostGIS. Google Earth uses a spherical globe, whereas the WGS84 globe is a spheroid - it is slightly squashed at the poles. Over short distances, there won't be much difference between the two, but at 1500km, there will be a more significant difference, more so as your line deviates from east/west.

Also, because the WGS84 spheroid is just an idealised model of the earth, don't be fooled by the precision of the result, the accuracy is going to be much lower. If you used WGS84 to guide a missile over that sort of distance, you're likely to hit the next street over.

You can get the same result as GE in PostGIS should you want, by using `ST_Distance_Sphere()` this is useful if you're using PostGIS as a data provider to GE.

Running your example on my PostGIS 1.5 system, I get:

``````SELECT ST_Distance_Sphere(
ST_GeomFromText('POINT(77.83042478941326 9.98463896136159)',4326),
ST_GeomFromText('POINT(78.03469506809812 23.90398909552571)',4326));

st_distance_sphere
--------------------
1547914.78948724

SELECT ST_Distance_Spheroid(
ST_GeomFromText('POINT(77.83042478941326 9.98463896136159)',4326),
ST_GeomFromText('POINT(78.03469506809812 23.90398909552571)',4326),
'SPHEROID["WGS 84",6378137,298.257223563]');

st_distance_spheroid
----------------------
1540651.62674101
``````