I have a large vector shapefile dataset containing polygons, many of which overlap.
I want to assign each overlapping section to one of the original overlapping polygons. E.g. if polygon A overlaps polygon B, create a polygon C consisting of only the overlapping section of A and B and assign C to either A or B. The polygons are not continuous. Some non-overlapping polygons share boundaries and some are separated and they need to stay this way.
Is there a straightforward way of doing this in QGIS?
The data originally contained lots of invalid polygons so I started by cleaning it using 'LWGEOM Make Valid' plugin, then used the 'Saga Self-intersect' tool to create the 'C' polygons, The 'C' polygons have no attributes.
I exported the 'C' polygons into their own shapefile.
I exported the 'AB' polygons into their own shapefile.
How to merge the 'C's' into the 'AB's'?
I thought a nearest neighbour solution would work, merging or dissolving the 'C' polygons with their nearest 'AB' polygon.
I'm in the process of running the 'QGIS NN Join plugin' using 'AB' as input layer and 'C' as join layer. So far this has been running for 2 hours and has hit 2% which would consume a lot of time for 11 datasets.
I would prefer a solution in QGIS but could also access ArcGIS or try in R if necessary.
Best Answer
The
SAGA Polygon self-intersection
would have created newID
field to store the combination of overlapped polygons. Please keep it when you export it asPolygon C
.Example output of
Polygon self-intersection
With a bit of editing, this can be used as id field to put together with
Polygon A
(orPolygon B
).For instance, if we want to use second number from
ID
, expression like:will return below.
(Please modify it to fit with your data. If you want to use the first one, it will be
substr( "ID", strpos("ID", '|')-1, 1)
. )After merging them,
Collect geometries
(QGIS 3.0) orSingleparts to multipart
using this field (overlap in the above example) as Unique ID will do the job.