[postgis-users] Path to closest neighbor
Stephen Woodbridge
woodbri at swoodbridge.com
Sat Nov 28 20:39:07 PST 2009
Nalin C wrote:
> Hi,
>
> I have two tables for roads and hospitals. I'm looking for suitable
> pgrouting function(s) for following scenario.
>
> Given the accident point (in point geometry), finding the least distant
> hospital and draw the path.
>
> Following functionality is needed.
>
> 1. One end of the drawn path needs to start from in front of the closest
> hospital (which is in hospitals table).
> 2. Path needs to stop from the accident point on road.
>
> I'm new to pgrouting and appreciate your help.
You have a few discrete tasks. Assuming you have the location of the
accident:
1) Select say the three closest hospitals based on straight line
distance. (x,y) is the location of the accident.
select name, the_geom from hospitals where order by
distance_sphere(setsrid(makepoint(x,y), 4326), the_geom) asc limit 3;
2) then use pgRouting to use the Hospital location as start and the
accident as end and comput the routes
3) compare the routed distances and select the shortest.
-Steve W
More information about the postgis-users
mailing list