cityImage.clean_duplicate_edges#
- cityImage.clean_duplicate_edges(nodes_gdf, edges_gdf, preserve_direction=False)[source]#
Cleans and deduplicates network edges, and removes unused nodes.
- The function performs the following:
Generates a unique ‘code’ for each edge, based on node IDs, with or without preserving direction.
Removes self-loop edges (edges from a node to itself).
Drops duplicate edges based on geometry (including reversal if direction is not preserved).
Removes edges that are geometrically duplicates, even if node order is reversed (for undirected graphs).
Updates the node GeoDataFrame to keep only those nodes actually used by the remaining edges.
- Parameters:
nodes_gdf (GeoDataFrame) – GeoDataFrame containing nodes, must include a ‘nodeID’ column.
edges_gdf (GeoDataFrame) – GeoDataFrame containing edges, must include ‘u’, ‘v’, and ‘geometry’ columns.
preserve_direction (bool, optional) – If True, edge direction is preserved; edges (u,v) and (v,u) are considered distinct. If False, edges are treated as undirected and geometric duplicates (with reversed coords) are removed. Default is False.
- Returns:
nodes_gdf (GeoDataFrame) – Filtered nodes GeoDataFrame, containing only nodes referenced by the cleaned edges.
edges_gdf (GeoDataFrame) – Cleaned edges GeoDataFrame, deduplicated and without self-loops.