I am looking for an answer to this question, for overlapping polygons, but in Python and preferably with GeoPandas.
Background
I have files with up to 90'000 polygons, see Tab. 1 in the Minial Working Example (MWE) attached. These polygons sometimes overlap to a large extent (see Fig. 1 in MWE attached, e.g. the polygons "One", "Two", and "Three" all overlap with each other.)
Aim
I would like to to get Tab. 2 in the MWE attached, i.e. merging/dissolving the polygons within one GeoDataFrame and keeping all polygon IDs that were merged/dissolved to create the new shapes. Shapes that do not overlap with anything should be preserved (see "No Overlap" in Tab. 2 in the MWE attached).
What I have tried
- '''geopandas.overlay(gdf1, gdf1, 'how'='union')''' -> does not seem to give back merged shapes, but rather intersections, whether I set the 'how' to 'union' or 'intersection' (see here for details)
- Using this idea with Shapely. Seems tedious to me and I would prefer a Geopandas approach if possible. Plus I also did not find a way to do ID preservation
- Using this idea I retrieve the right shapes, but loose as my Polygon IDs, respectively only keep the first one
I am sure there must be an easy pythonic way, but I think I lack the terminology to find the solution.