windkit.snap_to_layer#
- windkit.snap_to_layer(gdf, tolerance=0.1)[source]#
Snaps the geometries in a GeoDataFrame to each other within a specified tolerance.
This function iterates over each geometry in the GeoDataFrame. For each geometry, it finds all other geometries that intersect it. It then snaps the geometry to each of the intersecting geometries within the specified tolerance. Snapping is repeated until an iteration inserts no new vertices.
- Parameters:
gdf (gpd.GeoDataFrame) – The GeoDataFrame containing the geometries to snap. The GeoDataFrame should contain a ‘geometry’ column with polygons.
tolerance (float, optional) – The tolerance within which to snap geometries, by default 0.1. This is the maximum distance that points can be moved, in the GeoDataFrame’s CRS units (metres for a projected CRS, degrees for a geographic one). Must be strictly greater than the median vertex spacing of every ring in the map.
- Returns:
The GeoDataFrame with the snapped geometries.
- Return type:
GeoDataFrame
- Raises:
ValueError – If the GeoDataFrame contains invalid geometries, or if any ring’s median vertex spacing is at or below
tolerance. In the latter case, snapping cannot distinguish an intentional small gap between neighbouring polygons from the ring’s own, normal vertex spacing, and will splice unrelated nearby vertices into every ring instead.- Warns:
UserWarning – If the GeoDataFrame is in a geographic CRS, as a reminder that
toleranceis in degrees rather than metres.