neatnet.consolidate_nodes#
- neatnet.consolidate_nodes(gdf, tolerance=2.0, preserve_ends=False)[source]#
Return geometry with consolidated nodes.
Replace clusters of nodes with a single node (weighted centroid of a cluster) and snap linestring geometry to it. Cluster is defined using hierarchical clustering with average linkage on coordinates cut at a cophenetic distance equal to
tolerance
.The use of hierachical clustering avoids the chaining effect of a sequence of intersections within
tolerance
from each other that would happen with DBSCAN and similar solutions.- Parameters:
- gdf
geopandas.GeoDataFrame
GeoDataFrame with LineStrings (usually representing street network).
- tolerance
float
= 2.0 The maximum distance between two nodes for one to be considered as in the neighborhood of the other. Nodes within tolerance are considered a part of a single cluster and will be consolidated.
- preserve_endsbool =
False
If
True
, nodes of a degree 1 will be excluded from the consolidation.
- gdf
- Returns:
geopandas.GeoSeries
Updated input
gdf
of LineStrings with consolidated nodes.