[postgis-users] identfying a nearest point

Stephen Woodbridge woodbri at swoodbridge.com
Thu Apr 23 07:17:56 PDT 2009


Supunmali Ahangama wrote:
> Please suggest me with the POSTGIS/pgrouting function to identify the nearest
> point from set of points (vertices in a graph) to a particular point
> (outside the graph)? 

You typically want to search within some radius so you do not have to do 
a full table scan.

select * from vertices_tmp where st_expand(setsrid(makepoint(x,y),4326)) 
&& the_geom order by distance(setsrid(makepoint(x,y),4326),the_geom) asc 
limit 1;

Should do what you want.

-Steve



More information about the postgis-users mailing list