[postgis-users] nearest neighbor search
Stephen Woodbridge
woodbri at swoodbridge.com
Fri Mar 25 14:07:28 PST 2005
If you computed the distance from some point (x,y) to all points in the
table and sorted the results the first (or last) would be the nearest.
select point_id, Distance(...) as distance from mytable order by
distance asc limit 1;
should give you the point_id and distance from (x,y). I'm still to much
of a newbie to postGIS to fill in the exact syntax, if someone else can
help. This can probably be accellerated greately if you can limit you
search to some BBOX if you have lots of points.
-Steve
Robert Helmer wrote:
> Hello,
>
> I have been trying to find info on how to do a "nearest neighbor"
> search on point data I have loaded into my PostGIS/PostgreSQL
> database.. the only thing I've found so far is messages in
> the archive of this mailing list, suggesting using Distance()
> and a temp table.
>
> Does anyone have any pointers for how to do this? I'd sure
> appreciate it!
>
>
> Thanks,
> Rob Helmer
>
> _______________________________________________
> 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