I have a polygon layer and want to check if there are some polygons overlapping within the same layer. How can I do this?
In ArcGIS, I could run the Intersect tool only by adding the layer I want to check. This doesn't work in QGIS because it requires an overlaying layer.
I tried to add the Topology check "overlap", but this only finds overlapping errors of newly drawn polygons, not existing ones.
I also tried the "Select by Attribute" with overlay_within(@layer)
but:
- It only finds completely overlapping (identical) polygons (I also need to find the polygons that overlap only slightly)
- It does not create a layer (which would be handy)
5 Answers 5
You can create a Virtual Layer with DB Manager which joins the table to itself on intersecting polygons, where the id isnt the same.
You need a unique identifier field, mine is named id
. My layer is named qwerty. Modify layer name (row 3 and 4) and the id column name (row 6) in the query below and execute:
select row_number() over() as newid,
st_intersection(a.geometry, b.geometry) as geometry
from "qwerty" as a
join "qwerty" as b
on st_intersects(a.geometry, b.geometry)
and a.id<>b.id
where st_area(st_intersection(a.geometry, b.geometry))>0
The same logic using QGIS processing tools:
- Field calculate the integer field
tempid
as@row_number
- Intersection (multiple) with Field calculator output as input and overlay layer
- Extract by expression
"tempid"<"tempid_2"
You can use the Polygon Self-Intersection
tool if you have SAGA installed.
- Polygons: the input polygon layer
- Identifier: the field name that you want to use to identify the intersected polygons.
- Intersection: The output intersected polygons.
Then open the attribute table and in the newly added field, look at the attribute values where the pipe character exists |. These are the polygons that have self-intersections.
Example:
Original polygons:
After running the tool:
I suggest you run join attributes by location
, with both inputs being your polygon layer, using "overlap" as condition and discard all features which haven't been joined to something. Now you're left with all the overlapping features.
If you really need only the overlapping parts, we need to go down the rabbit hole (at least a bit).
- Add the
$area
to your polygons. - Then run
union
with your overlapping polygons as both inputs. Select by expression
all polygons in your "unionized" layer with an area = 0 or an area equal to the area added in step 1.- Delete the selected polygons.
- Run
delete duplicate geometries
on the overlaps you got.
This probably is also possible using expressions, overlay_intersects or aggregate and whatsoever, but I prefer a working solution over something I need to fiddle around with two hours.
You can use the expression
array_length(overlay_intersects(@layer,$id))>0
Either use it via Select by Expression or run it in Extract by Expression to create a new layer containing the overlapping polygons.
Depending on your exact usecase, you may also want to try one of the other overlay expressions.
You can download the LF Tools plugin and run the Overlapping polygons tool.
I made a scratch layer with overlapping polygons (brown polygons) then ran the tool and it made a new layer of the parts that overlapped (maroon polygons) enter image description here
Explore related questions
See similar questions with these tags.