cityImage.clean_network#
- cityImage.clean_network(nodes_gdf, edges_gdf, dead_ends=False, remove_islands=True, same_vertexes_edges=True, self_loops=False, fix_topology=False, preserve_direction=False, nodes_to_keep_regardless=None)[source]#
Cleans a street network by applying a series of topology and geometry corrections to nodes and edges GeoDataFrames.
- This function can:
Remove pseudo-nodes
Remove duplicate nodes and edges (by geometry or node pairing)
Remove disconnected islands (optional)
Remove edges with the same vertexes but different geometry (optional)
Remove dead-ends (optional)
Remove self-loops (optional)
Fix topology by breaking lines at intersections (optional)
- Parameters:
nodes_gdf (GeoDataFrame) – Point GeoDataFrame containing network nodes (junctions), must include a unique node ID column.
edges_gdf (GeoDataFrame) – LineString GeoDataFrame containing street segments, must include columns for start/end node IDs and geometry.
dead_ends (bool, optional) – If True, removes dead-end nodes and corresponding edges. Default is False.
remove_islands (bool, optional) – If True, removes disconnected components (“islands”) in the network. Default is True.
same_vertexes_edges (bool, optional) – If True, treats multiple edges between the same pair of nodes as duplicates. Keeps only the longest edge when it is at least 10% longer than the others, otherwise replaces them with a center line. Default is True.
self_loops (bool, optional) – If True, removes self-loop edges (where start and end node are the same). Default is False.
fix_topology (bool, optional) – If True, breaks lines at intersections with other lines in the streets GeoDataFrame. Default is False.
preserve_direction (bool, optional) – If True, considers edge direction: edges with the same coordinates but opposite directions are not considered duplicates. If False, such edges are treated as duplicates. Default is False.
nodes_to_keep_regardless (list, optional) – List of node IDs to always keep, even if they would otherwise be removed (e.g. for transport stations). Default is empty list.
- Returns:
nodes_gdf (GeoDataFrame) – Cleaned nodes GeoDataFrame.
edges_gdf (GeoDataFrame) – Cleaned edges GeoDataFrame.