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.

Similar Reads

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 nodesX (float or list) – points’ x (longitude) coordinates, in same CRS/units as graph and containing no nullsY (float or list) – points’ y (latitude) coordinates, in same CRS/units as graph and containing no nullsreturn_dist (bool) – optionally also return distance between points and nearest nodesReturns: 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...

Nearest Node to a Point for an Unprojected Graph Using OSMnx Module

If graph is unprojected, OSMnx distance module uses Ball Tree algorithm for nearest neighbor search. In Ball Tree algorithm, the total space of training data is divided into multiple circular blocks. Each circular block has a centroid point and has set of node points (location points)....

Nearest Node to a Point for an Projected Graph Using OSMnx Module

If graph is projected, OSMnx distance module uses KD tree algorithm for nearest neighbor search. In K-D tree algorithm, the points can be organized in a K-Dimensional space. A non-leaf node in K-D tree divide the space into two parts. Points to the left of the space are represented by the left subtree of the node and points to the right of the space are represented by the right subtree....