Syntax of osmnx.distance.nearest_nodes() Function
osmnx.distance.nearest_nodes(G, X, Y, return_dist=False)
Parameters:
- G (networkx.MultiDiGraph) – graph in which to find nearest nodes
- X (float or list) – points’ x (longitude) coordinates, in same CRS/units as graph and containing no nulls
- Y (float or list) – points’ y (latitude) coordinates, in same CRS/units as graph and containing no nulls
- return_dist (bool) – optionally also return distance between points and nearest nodes
Returns: nn or (nn, dist) – nearest node IDs or optionally a tuple where dist contains distances between the points and their nearest nodes
Return Type: int/list or tuple
Note: install geopandas==0.14.3, osmnx==1.9.1, notebook==7.0.7, folium==0.15.1, matplotlib==3.8.2, mapclassify==2.6.1
Find the Nearest Node to a Point Using OSMnx Distance Module
Nearest neighbor search algorithms are crucial for robust navigation. OSMnx makes use of different types of nearest neighbor search algorithms for the projected and unprotected graph. In this article, we will see how we can find the nearest node to a point using OSMnx distance module in Python.