[postgis-users] Distance between points
Charles Galpin
cgalpin at lhsw.com
Sun Aug 28 18:16:20 PDT 2011
On Aug 28, 2011, at 1:22 PM, Marcelo Pereira wrote:
> I would like to know the distance between "one fixed point" (42.331002 -71.112678) and all points in this table.
This is untested but you'd do a self join for this
select p1.longitude, p1.latitude, p2.longitude, p2.latitude, ST_Distance(
ST_GeomFromText('POINT(' || p1.longitude || ' ' || p1.latitude || ')',4326),
ST_GeomFromText('POINT(' || p2.longitude || ' ' || p2.latitude || ')',4326)) as distance
from places p1, places p2
where p1.id = p2.id
and p1.id = 1
and p2.id != 1
hth,
charles
More information about the postgis-users
mailing list