# Calculating overlap percent of multiple features in same layer using QGIS

I'm trying to find a way of identifying features in a layer that are at least 50% within another feature in the same layer so that I can remove them.

I've discovered SAGA's `Polygon self-intersection` which creates a new feature that delineates the overlapped section, but this isn't quite what I want. I found some other methods where people manage to delete the overlapped section between features, but again, I'm looking to be able to select the entire feature and not just the overlapped portion. Deleting slivers won't work either as not all overlaps are particularly small.

• What should happen if the feature overlaps 20% with feature1, 20% with feature2, 20% with feature3 and 20% with feature4? Commented Mar 22, 2022 at 13:02
• @til_b that's fine. I'm mostly interested in eliminating cases where one is mostly contained within one other. Commented Mar 22, 2022 at 13:08
• be careful if two polygons are almost the same (like `polygonA = buffer(polygonB,0.01)`) as both will be considered "mostly contained" within the other one
– JGH
Commented Mar 22, 2022 at 13:22

You can identify the IDs to be deleted using a virtual layer. the idea is to join the layer with itself where the polygons intersects - but excluding intersection with the same polygon -, then to compute the intersection area and to compare with the original area.

Go the the menu `layer / add layer / add-edit virtual layer` and enter the following query.

``````select p1.id
from myPolygonLayer p1
join myPolygonLayer p2
on st_intersects(p1.geometry,p2.geometry)
where
p1.id != p2.id
and st_area(st_intersection(p1.geometry,p2.geometry)) / st_area(p1.geometry) >= 0.5
``````
• I tried to do this via the field calculator, but sure, SQL is way easier.
– Erik
Commented Mar 22, 2022 at 13:29

You can use QGIS expression with select by expression to select those polygons that A) overlap with another polygon of the same layer and where B) the overlapping area is larger than a cetrtain percentage of the polygon - let's say at least 50%.

Use this expression:

``````array_max (
array_foreach(
overlay_intersects(
@layer,
\$geometry
),
area (
intersection (
\$geometry,
@element
)
)/\$area
)
) >=0.5  -- here: overlap of 50% or more - change this value accordingly (between 0 and 1)
``````

Polygons selected by this expression in yellow

• I am getting Invalid expression error. What I am doing wrong. Using above expression only. When I am closing the last parenthesis all expression started to highlight by red lines. Commented Jun 21, 2022 at 12:51