iduedu.nearest_edges

iduedu.nearest_edges(urban_graph, gdf, *, max_dist=None)[source]

Return the nearest graph edge for each input geometry, with the distance and the position along it.

Objects are matched by their representative_point() in the graph CRS, as in nearest_nodes(). This does not change the graph; use project_objects2urban_graph() to insert objects into it.

Parameters:
  • urban_graph (UrbanGraph) – Graph whose edges_gdf contains line geometries.

  • gdf (GeoDataFrame) – GeoDataFrame with geometries to match to graph edges.

  • max_dist (float | None) – Optional search radius in graph CRS units; objects farther from every edge get missing values. None searches without a limit.

Return type:

DataFrame

Returns:

DataFrame indexed like gdf with columns edge (label of the edge in edges_gdf), u, v (and k for multigraphs), dist (distance from the object to the edge) and along (distance from the start of the edge geometry to the closest point on it). When several edges are equally near, one of them is returned.

Raises:
  • TypeError – If gdf is not a GeoDataFrame.

  • ValueError – If the graph has no edges or geometries cannot be matched safely.