Sunday, 23 December 2018

openstreetmap - PGROuting 2 : Getting nearest node to a given point (with lat - long given)


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.



Answer



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;

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...