[postgis-users] Newbie - get total distance travelled from query of points

Stephen Woodbridge woodbri at swoodbridge.com
Sun Jun 22 15:25:15 PDT 2008


Joe Roberts wrote:
> Hi,
> 
> I am very new to PostGIS, and I'm stuck with what I hope is an easy
> problem to solve.
> 
> I have a table which contains a list of points, originating from a GPS
> device's lat/long output. I want to get the distance travelled. I have
> the following query, but the result (distance) looks far to low:
> 
> SELECT ST_Length(St_MakeLine(point))/1000 as distance
> FROM (
>       SELECT point FROM points
>       ORDER BY timestamp
> ) as p
> 
> I know the route was over 5 miles (probably about about 8.4 km), but
> the query returns 0.000106496.
> 
> Can anyone see what I am doing wrong? Is it my query, or could it be
> my data?
> 
> Many thanks
> 
> Joe

So assuming your GOS is return LAT, LON in WGS84

ST_Length is returning the length in degrees (IE: the Cartesian distance 
in the units of the geometry) and that return 0.106496 degrees. If you 
want miles you can multiple that by the number of miles/degree and 
assuming a great circle like path there are approximate 69.172 miles per 
degree along the Equator so you distance is 7.366541312 miles which 
seems to fit with your statements above.

http://www.google.com/search?hl=en&q=miles+per+degree&btnG=Google+Search

-Steve



More information about the postgis-users mailing list