iduedu.consolidate_intersections

iduedu.consolidate_intersections(graph, tolerance=10.0, *, max_span=None, return_mapping=False)[source]

Merge groups of nearby nodes, such as the several nodes of one junction of dual carriageways, into one.

Two nodes closer than tolerance belong to one cluster, and clusters chain (single linkage). A cluster is then split into the parts that edges inside the cluster connect, so nodes that are merely close (a bridge above a road) stay apart. Each part with several nodes becomes one node at the mean position of its members, keeping the id and attributes of its first member in nodes_gdf order; single nodes are unchanged. Edges inside a part are removed. The other edges keep their geometry with the end points moved to the new nodes; length_meter is the new geometry length and time_min is scaled with it.

Chaining can join long runs of closely spaced nodes (dense footpath networks); a part whose bounding box is wider than max_span is therefore left unmerged.

Meant for network statistics and centralities, where one junction drawn as several nodes inflates the counts. It changes routing: turns and one-way links inside a junction disappear.

Parameters:
  • graph (UrbanGraph) – Graph with point nodes and line edges in a projected (metric) CRS.

  • tolerance (float) – Distance in CRS units under which two nodes are joined.

  • max_span (float | None) – Largest bounding-box diagonal of a part that is still merged, in CRS units. None means 4 * tolerance.

  • return_mapping (bool) – Also return the mapping from old to new node ids.

Return type:

UrbanGraph | tuple[UrbanGraph, Series]

Returns:

New UrbanGraph of the same kind (directed or not, multigraph or not; a simple graph keeps the lighter of the parallel edges that merging creates), and with return_mapping the Series from every old node id to its new one.

Raises:
  • TypeError – If graph is not an UrbanGraph.

  • ValueError – If tolerance is negative, the CRS is geographic or an edge is not a LineString.