7

I have a shapefile with buildings defined as polygons. Some of them are partially overlapped. They are all in the same layer. I can identify the overlapping using the "Topology Checker" but I cannot solve the overlapping issue.

What I would like is to obtain separate polygons, without overlapping but contiguous.

I have this:

enter image description here

enter image description here

and I would like to have this:

enter image description here

I tried without success:

  • GRASS > v.clean - nothing changed
  • SAGA > Vector polygon tools > Intersect
  • SAGA > Vector polygon tools > Self intersection - they both break the the 2 polygons on 3 (2+intersected area).
2
  • You could try geometry checker: docs.qgis.org/3.16/en/docs/user_manual/plugins/core_plugins/…
    – Babel
    Commented Dec 11, 2020 at 19:23
  • 1
    If there aren't many of these you can fix them manually, best done with snapping on. Note that any time a polygon has a vertex the abutting one must have one added there as well. The GRASS v.clean settings aren't stated in your question. You might start with inputs of line, boundary & area, with break, snap, bpol and rmarea tools, thresholds of 0,1,0,5 and a v.in.ogr snap of 1 (thresholds and snap hinge on your layer's units and tolerance but those with 0 don't use a threshold) with an output type of area. I like to assign unique id prior to clean to help find new polys if any.
    – John
    Commented Dec 15, 2020 at 18:22

2 Answers 2

14

First make sure your Buildings have a unique "id" (which does not contain a | character, you will see why below). You can add it for example via field calculator by adding a new field with the expression $id if they do not have one already.

Then run the "Polygon Self-Intersection" from SAGA Processing tools and choose this "id" as Identifier:

enter image description here

Which will create a new layer, where the overlapping Parts become their own polygons.

enter image description here

This new layer will contain a new "id" field, containing the "id"s of their original buildings split by a | sign.

Now open the field calculator of this new layer and calculate a new field with this expression:

if(regexp_match("ID",'\\|') > 0, regexp_substr("ID",'[^|]*'), "ID")

to get the second "ID" as "mergeID" or

if(regexp_match("ID",'\\|') > 0, regexp_substr("ID",'(?<=\\|).*'), "ID")

to get the first "ID" as "mergeID":

This expression looks up in your "ID" field, whether it contains a | character. If so, it chooses the ID before or after the | character. If it does not contain this character, it will just copy over the ID to the "mergeID".

enter image description here

Then run the "Dissolve" from processing toolbox and choose this "mergeID" as dissolve field:

enter image description here

Your final result:

enter image description here

0
1

I have written the algorithm "Remove Self-Overlapping Portions by Condition" for this usecase. It is part of the ProcessX-PlugIn.

You can choose which polygons should keep their parts. Whether it is the larger or the smaller one. Or you can use a custom sorting expression. Optionally you can set up to two expression conditions about which geometries should or should not be compared against each other. It does also work with lines.

For the purpose of this question, you can use the default settings:

enter image description here

Input:

enter image description here

Output:

enter image description here

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.