cartagen.generalize_boundaries

cartagen.generalize_boundaries#

generalize_boundaries(polygons, algorithm, *args, **kwargs)#

Generalize shared polygon boundaries while strictly preserving topology.

This function applies a simplification or smoothing algorithm to a set of adjacent polygons. By isolating and processing only the shared boundary segments (lines) before reconstructing the polygons, it prevents gaps, overlaps, or topological disconnections from forming between neighboring features.

Parameters:
  • polygons (GeoDataFrame of Polygon) – The input layer containing adjacent polygons to be generalized.

  • algorithm (callable) – The simplification or smoothing function to apply to the boundaries.

  • *args (tuple) – Additional positional arguments forwarded to the algorithm.

  • **kwargs (dict) – Additional keyword arguments forwarded to the algorithm.

Returns:

GeoDataFrame of Polygon

Example

>>> poly1 = Polygon([(0, 0), (5, 0), (5, 2.5), (6, 2.5), (5, 5), (0, 5)])
>>> poly2 = Polygon([(5, 0), (10, 0), (10, 5), (5, 5), (6, 2.5), (5, 2.5)])
>>> gdf = gpd.GeoDataFrame(geometry=[poly1, poly2])
>>> list(c4.generalize_boundaries(gdf, c4.simplify_douglas_peucker, 5.0).geometry)
[ <POLYGON ((5 5, 5 0, 0 0, 5 5))>, <POLYGON ((5 0, 10 0, 10 5, 5 5, 6 2.5, 5 2.5, 5 0))> ]

(Source code)

../_images/generalize_boundaries.png