cityImage.consolidate_nodes#
- cityImage.consolidate_nodes(nodes_gdf, edges_gdf, consolidate_edges_too=False, tolerance=20)[source]#
Consolidates nodes in a spatial network that are within a given distance (tolerance), preserving topology and unclustered nodes.
Nodes within tolerance distance are clustered together and represented by a single consolidated node at the cluster centroid. For clusters containing disconnected components, each connected component is further split into its own consolidated node. Optionally, edges can be updated to reference the new consolidated node IDs and geometries.
- Parameters:
nodes_gdf (GeoDataFrame) – GeoDataFrame of nodes, must include columns ‘nodeID’ and ‘geometry’. If present, ‘z’ is averaged for clusters.
edges_gdf (GeoDataFrame) – GeoDataFrame of edges for checking network connectivity.
consolidate_edges_too (bool, optional) – If True, also returns the updated edges GeoDataFrame (default: False).
tolerance (float, optional) – Distance threshold for clustering nodes (in CRS units). Nodes within this distance are merged (default: 20).
- Returns:
consolidated_nodes_gdf (GeoDataFrame) –
- GeoDataFrame of consolidated nodes. Columns include:
’old_nodeIDs’: list of merged node IDs
’x’, ‘y’: centroid coordinates
’z’ (optional): averaged elevation for the cluster
’nodeID’: new node ID
’geometry’: consolidated node Point geometry
consolidated_edges_gdf (GeoDataFrame (optional)) – Only returned if consolidate_edges_too is True. Edges with endpoints mapped to new consolidated node IDs and geometries