iduedu.get_closest_nodes¶
- iduedu.get_closest_nodes(gdf_from, to_nx_graph)[source]¶
Find the nearest graph node for each geometry in a GeoDataFrame.
Reprojects gdf_from to the graph CRS if needed, then builds a KD-tree over node coordinates (x, y) and queries nearest nodes for point representatives of the input geometries (handles points/lines/polygons via representative_point()).
- Parameters:
gdf_from (
geopandas.GeoDataFrame) – Input geometries to snap (any geometry type).to_nx_graph (
networkx.Graph) – Graph with node attributes x, y and graph[“crs”] set.
- Returns:
- Tuple of:
nearest_nodes: list of node IDs (in the graph index space),
distances: NumPy array of Euclidean distances in the graph CRS units.
- Return type:
(list, np.ndarray)