0

I have a point whose latitude and longitude (only) are known, and a table of nodes with their geom. I want to find the closest node in the table to the given point.

I think I can achieve this with pgr_findNearestNodeDwithin function, but i cannot find the exact syntax of the function and the parameters it takes.

Any pointers in this direction will be appreciated.

3

To find the nearest point you only need a little bit PostGIS. With PostGIS 2.0 or higher you can use nearest neighbor KNN gist functionality.

I assume you have a table with all nodes ("vertices"):

SELECT * FROM vertices 
    ORDER BY the_geom <-> ST_GeometryFromText('POINT(lon lat)',4326) 
    LIMIT 1;
-2

find_nearest_node_within_distance, in matching.sql

SELECT * FROM ( SELECT find_nearest_node_within_distance( 'POINT(x y)', 0.5, 'test_2po_4pgr') as x ) AS foo

  • is that function available for pgrouting version 2? – user1628340 Jul 31 '13 at 14:40
  • It is in matchinq.sql which is part of pgrouting or postgis ( i do not remember exactly ). – Matus Jul 31 '13 at 14:41
  • matching.sql is not included in pgRouting 2 anymore. – dkastl Jul 31 '13 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.