Cleaning geometries

coverage_clean(gdf, tolerance, mask=None, *, duplicate_action='fix', grid_sizes=(None,), logger=None)[source]

Fix thin gaps, holes, slivers and double surfaces.

Rules: - Holes (interiors) thinner than the tolerance are closed. - Gaps between polygons are filled if thinner than the tolerance. - Sliver polygons thinner than the tolerance are eliminated into the neighbor polygon with the longest shared border. - Double surfaces thinner than the tolerance are eliminated. If duplicate_action is “fix”, thicker double surfaces will be updated from top to bottom of the GeoDataFrame’s rows. - Line and point geometries are removed. - MultiPolygons are exploded to Polygons. - Index is reset.

Parameters:
  • gdf (GeoDataFrame) – GeoDataFrame to be cleaned.

  • tolerance (int | float) – distance (usually meters) used as the minimum thickness for polygons to be eliminated. Any gap, hole, sliver or double surface that are empty after a negative buffer of tolerance / 2 are eliminated into the neighbor with the longest shared border.

  • mask – Unused.

  • duplicate_action (str) – Either “fix”, “error” or “ignore”. If “fix” (default), double surfaces thicker than the tolerance will be updated from top to bottom (function update_geometries) and then dissolved into the neighbor polygon with the longest shared border. If “error”, an Exception is raised if there are any double surfaces thicker than the tolerance. If “ignore”, double surfaces are kept as is.

  • grid_sizes (tuple[None | int]) – One or more grid_sizes used in overlay and dissolve operations that might raise a GEOSException. Defaults to (None,), meaning no grid_sizes.

  • logger – Optional.

Return type:

GeoDataFrame

Returns:

A GeoDataFrame with cleaned polygons.

get_angle_between_indexed_points(point_df)[source]

Get angle difference between the two lines.

Return type:

GeoDataFrame

Parameters:

point_df (GeoDataFrame)

remove_spikes(gdf, tolerance)[source]

Remove thin spikes in polygons.

Note that this function might be slow. Should only be used if nessecary.

Parameters:
  • gdf (GeoDataFrame) – GeoDataFrame of polygons

  • tolerance (int | float) – distance (usually meters) used as the minimum thickness for polygons to be eliminated. Any spike thinner than the tolerance will be removed.

Return type:

GeoDataFrame

Returns:

A GeoDataFrame of polygons without spikes thinner.

safe_simplify(gdf, tolerance)[source]

Simplify only if the resulting area is no more than 1 percent larger.

Because simplifying can result in holes being filled.

Return type:

GeoDataFrame

Parameters:

tolerance (float | int)