# [postgis-users] Path to closest neighbor

Nalin C nalinchandrawansha at gmail.com
Sun Nov 29 00:16:42 PST 2009

```Also, can you please suggest me the functions that can be used for points 2
and 3 ?  I'm totally a newbie to postgis.

In point 2, it would be great if the path can start from in front of the

Nalin C wrote:
>
> Hi Steve,
>
> Thank you for the quick reply.
>
> I observed that the results returned by :
>
> select name, the_geom from hospitals order by
> distance_sphere(setsrid(makepoint(79.877778, 6.914722), 4326), the_geom)
> asc limit 3;
>
> are not the closest hospitals to the given accident point. I'm not sure
> what has gone wrong.
>
>
> Thanks,
>
> Nalin
>
>
>
> Stephen Woodbridge wrote:
>>
>> 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
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>>
>
>

--
View this message in context: http://old.nabble.com/Path-to-closest-neighbor-tp26559254p26560083.html
Sent from the PostGIS - User mailing list archive at Nabble.com.

```