In QGIS, how do you remove overlapping polygons and control which polygon gets deleted? I’ve used the delete geometries tool to remove overlapping polygons within a layer but this doesn’t allow me to specify which overlapping polygon gets deleted. This is a problem because some polygons are more important than others. Can I use an attribute value to establish an order of priority when deleting overlapping polygons? I have a lot of polygons so manually removing overlap between them isn’t an option.
1 Answer
I try to give you a solution using a sample data set of three polygons. Polygons have a unique ID and a PRIORITY columns. (polygon fill is 50% transparent to see the overlapping parts).
Convert the polygons to lines (we'll use these lines to split the polygon layer) using Vector/Geometry Tools/Polygons to Lines... from the menu. You'll get layer Lines memory layer if you don't change settings.
Split the original polygon layer by the Lines layer using Processing Toolbox/Vector Overlay/Split with lines
You get a Split layer where the overlapping areas are separated (but duplicated):
Using the DB Manager plug-in let's select only the necessary elements:
select a.geometry, a.id, a.priority from Split as a
where st_area(a.geometry) > 0.001 and not exists (select b.id from Split as b
where a.id <> b.id and st_contains(a.geometry, st_centroid(b.geometry))
and a.priority > b.priority)
This Query Layer doesn't contain duplicates, but it should be dissolved by the original unique IDs. Using Dissolve from the Processing Toolbox we can join the areas with common IDs.
And here is the result: