[postgis-users] deriving distance between lat/long points.

Ethan Alpert ealpert at digitalglobe.com
Wed Aug 17 10:25:40 PDT 2005


Is the function distance_spheroid not available in v0.8? This does the
trick without reprojecting the data.

-e

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
Brent Wood
Sent: Tuesday, August 16, 2005 7:07 PM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] deriving distance between lat/long points.



Hi y'all...

I am often being asked to work out the distance between two points
(lat/long WGS84), for genetic cline or mark recapture type studies. 

I figured to make my life easier by writing a shell script to invoke
PostGIS to do this. But it seems not, at least so far  :-)


The first problem is that I'm stuck (for now) with PostGIS v0.8, but
this should be able to do what I want, and proj version 4.4.7

The second is probably my failure to understand projections properly.

I looked for global equidistant projections, which seemed a sensible
option and found a few: World_Azimuthal_Equidistant (54032)
World_Plate_Carree          (54001)
World_Equidistant_Conic     (54027)


So, my questions:

1. Is it feasible to have a simple script like this to return the
distance? 2. Which is the "best" projection to use? 3. Which is the
"best" Postgis function to use? 4. Any other advice/suggestions?

Thanks,

  Brent Wood





The results for 3 iterations, one for each projection, were: (script
called arc_dist with 2 coord pairs on the command line)

I have not been able to get distance_spheroid or length_spheroid to
work, & distance_sphere doesn't exist in postgis.sql. I have no say on
the versions to be installed, and can but hope for an upgrade someday.


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[woodb at otter ~]$ arc_dist -45 160 -45 180

Parameters:
Line:        GeometryFromText('LINESTRING(160 -45,180 -45)', 4326)
Start point: GeometryFromText('POINT(160 -45)', 4326)
End point:   GeometryFromText('POINT(180 -45)', 4326)
Spheroid = SPHEROID["WGS_1984",6378137,298.257223563]
SRID:      54001

distance(point,point)
ERROR:  tranform: couldnt parse proj4 output string
CONTEXT:  PL/pgSQL function "transform" line 2 at return
distance_spheroid(point, point, spheroid) NaN [woodb at otter ~]$ arc_dist
-45 160 -45 180

Parameters:
Line:        GeometryFromText('LINESTRING(160 -45,180 -45)', 4326)
Start point: GeometryFromText('POINT(160 -45)', 4326)
End point:   GeometryFromText('POINT(180 -45)', 4326)
Spheroid = SPHEROID["WGS_1984",6378137,298.257223563]
SRID:      54027

distance(point,point)
4616.85
distance_spheroid(point, point, spheroid)
NaN
[woodb at otter ~]$ arc_dist -45 160 -45 180

Parameters:
Line:        GeometryFromText('LINESTRING(160 -45,180 -45)', 4326)
Start point: GeometryFromText('POINT(160 -45)', 4326)
End point:   GeometryFromText('POINT(180 -45)', 4326)
Spheroid = SPHEROID["WGS_1984",6378137,298.257223563]
SRID:      54032

distance(point,point)
1747.37
distance_spheroid(point, point, spheroid)
NaN
[woodb at otter ~]$

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The postgis lines from the script are:

echo "distance(point,point)"
psql $DB -U woodb -q -A -t -c "select (distance(transform($START,$SRID
), 
                        transform($END,$SRID ))/1000)::decimal(9,2) as
Km;"    
                              

echo "distance_spheroid(point, point, spheroid)"
psql $DB -U woodb -q -A -t -c "select (distance_spheroid($START , $END,
'$SPHEROID' )/1000)::decimal(9,2) as Km;"




_______________________________________________
postgis-users mailing list postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list