1

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: enter image description here

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))
5
  • What should happen when two geometries of the same hierarchy overlap?
    – Felipe D.
    Commented May 24, 2022 at 22:40
  • Good question. That would be extremely rare, since the attribute is height values in meters (e.g. one could be 4.4, another 4.3 meters). If geometries of the same hierarchy overlap, they could just ignore each other (not clip).
    – Clouseau
    Commented May 25, 2022 at 0:53
  • Same but using Postgis: gis.stackexchange.com/questions/379300/…
    – Bera
    Commented May 25, 2022 at 5:12
  • Please decide whether it is R or Python that you wish to ask about in this particular question and in either case please include a code attempt.
    – PolyGeo
    Commented May 25, 2022 at 12:00
  • I prefer Python, but I mention both because I would accept whichever anyone can accomplish the task. I edited to add some code.
    – Clouseau
    Commented May 25, 2022 at 14:01

1 Answer 1

2

I had to do something like this a long time ago, here is the repo and a description.

https://github.com/debboutr/overlapTopoTool

If you identify the column you want to use as the weight on line 84 of the overlap.py script. If it's not straight-forward enough to use easily, comment below and I can try to help explain.

2
  • Wow, thank you so much for this! It is very straight forward. I am going to review the output later this afternoon and will give you an update on how it looks.
    – Clouseau
    Commented May 26, 2022 at 17:59
  • 1
    Ok, I was able to get the code working! Upon visual inspection all seems good. Changes I made to code were: ability to add multipolygons to single cell in geometry column, merge 2 sets of multi polygons, and remove polygons that are completely covered by higher order polygons (larger height polys). Thanks again! Were going big.
    – Clouseau
    Commented May 27, 2022 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.