My layer contains overlapping polygons, as seen with some transparency.
What could I do to remove the overlapping parts (in dark on the screenshot) without merging any polygon in order to obtain the result opposite?
My layer contains overlapping polygons, as seen with some transparency.
What could I do to remove the overlapping parts (in dark on the screenshot) without merging any polygon in order to obtain the result opposite?
If I understood you correctly, all you need to is an intersect of the poylgon layer with itself, and in the resulting attribute table you will have the intersections of polygons with all other overlapping polygons (if any):
AFTER:
Attribute table (AFTER):
Then in the attribute table, all you need to do is a Select features using an expression
and enter the following expression (assuming your input has an id
field):
"id" = "id_2"
That will select only the non-overlapping parts of each polygon which you can then export to its own layer.
You can use the following script if it is not important which polygon part to delete. (after selecting the layer)
layer = iface.activeLayer()
dpr = layer.dataProvider()
# iterate over the layer
for feature1 in layer.getFeatures():
# iterate over the same layer
for feature2 in layer.getFeatures():
if feature1.id() < feature2.id():
geometry1 = feature1.geometry()
geometry2 = feature2.geometry()
diff_geometry = geometry2.difference(geometry1)
dpr.changeGeometryValues({feature2.id(): diff_geometry})
Before:
After:
if feature1.geometry().area() < feature2.geometry().area()