I have a dataset of circular polygons that correspond to tree crowns. Many polygons overlap with each other, and some are even completely covered by larger polygons (or larger polygons covered by many small polygons). I would like to clip polygons based on attribute value (tree height), where the maximum height polygons clip the polygons with lower height values.
Image below describes the situation, where 1 is the lowest tree height and 3 is the tallest:
I attempted using this workflow in QGIS (Cut polygons with each other based on attribute value), but it takes very long and was unusable for larger datasets. I would prefer to use Python.
Test dataset located here
I attempted but only got as far as splitting the polygon with the boundaries (lines) of each polygon, creating smaller polygons where they overlap
import shapely import geopandas as gpd # 1. convert polys to lines tree_lines = tree_polys_valid.boundary # 2. Split polygons by lines merged_lines = shapely.ops.linemerge(tree_lines.values) border_lines = shapely.ops.unary_union(merged_lines) decomposition = shapely.ops.polygonize(border_lines) # 3. Convert into GeoSeries poly_series = gpd.GeoSeries(list(decomposition))