3

This is my problem that I first present using a Screenshot:

enter image description here

In a layer, I have many cases of figures like this one: Polygons that overlap in the same place. Each of its polygons represents different data and they have no common columns. My question is twofold:

  • I would like to create a column in the attribute table that would give an identical identifier to all polygons in the same place.

  • In addition, I would then like to count the number of polygons that overlap in the same place.

I could do this manually by selecting polygons with the location or intersect function but this is not possible due to the very large size of my dataset. I can't use tools like merge/union because it overwrites my various data.

Do you have any ideas?

  • Interesting question! In your project, is there any case that each of (Polygon1 - Polygon2) and (Polygon2 - Polygon3) pair is overlapping set, but (Polygon1 - Polygon3) set is merely connected via Polygon2 in between? (I mean, Polygon1 and Polygon3 are not intersecting/touching each other but still in a group). – Kazuhito Feb 1 at 15:17
  • There is something that needs to be clarified first off. What happens if one polygon has more than one place where it intersects with other polygons that are themselves intersecting with different polygons? Every overlap might have a different number of polygons involved and they then certainly can't have the same intersection ID. – Gabriel C. Feb 1 at 15:28
3

I took for granted that some polygons will overlap separately with several polygons. This makes it so one ID cannot describe all overlaps. A list of overlaps in your original layer's table can work for queries if you have another layer with overlap IDs. I use QGIS 3.4 so if you're using 2.x, it might be different.

  1. First, create a field in the attribute table of your polygon layer called for example orig_id and with the field calculator, fill it using the expression $id
  2. Then, use the vector geoprocessing tool Union to create a new layer where all overlapping parts are split. The result will contain duplicate polygons for every original polygon that overlaps (we'll deal with them later on).
  3. Then use the Join attributes by location (summary) from the processing toolbox with these parameters:
    • Input layer: step 2's resulting layer
    • Join layer: step 2's resulting layer
    • Geometric predicate: equals
    • Field to summarize: orig_id
    • Summaries to calculate: count
  4. Again with Join attributes by location(summary), calculate the number of overlapping polygons with these settings:
    • Input layer: your original polygons layer
    • Join layer: step 3's resulting layer
    • Geometric predicate: overlaps
    • Field to summarize: orig_id_count (provided you called the field orig_id earlier)
    • Summaries to calculate: max

The number of overlaps with other polygons is now settled in a new layer that you could rename (to avoid getting lost in the temporary names) but let's keep going:

  1. Using the Delete duplicate geometries tool from the processing toolbox, get rid of identical copies in step 3's result layer.
  2. With the Extract by attribute tool, get rid of the parts that don't overlap using these parameters:
    • Input layer: step 5's resulting layer
    • Selection attribute: orig_id_count provided you named your fields like I did
    • Operator: ≠
    • Value: 1
  3. In step 6's resulting layer, create a new field called for example over_id and, with the field calculator, copy the feature ID into it using the expression $id

This layer is now your index from which you can look for unique overlap IDs. Keep it!

  1. Then, using the Join attributes by location (not the same as earlier), match the overlapping polygon IDs with the polygon layer, using these settings:
    • Input layer: step 4's resulting layer
    • Join layer: step 6's resulting layer (with the field added at step 7)
    • Geometric predicate: overlaps
    • Fields to add: over_id
    • Join type: one-to-many

The result is one copy of the original polygons for each unique overlap combination.

  1. It is now possible to simply fill a new field (for example called over_con) in that layer for each feature using an expression that will concatenate overlap IDs for each original polygon ID. The expression looks like this:

    concatenate( to_string("over_id"),group_by:="orig_id",concatenator:=',')
    
  2. Finally, use the Delete duplicate geometries tool on the final layer to get back to the original number of polygons. You can delete the over_id field as it isn't needed anymore.

The result of the whole operation for your original layer is two additional fields:

  • one that contains a comma separated list of overlap IDs that can be queried to return polygons that do overlap each other.
  • one that contains the number of overlaps that a particular polygon shares with other polygons.

Combined with the overlap layer, these can help select polygons that overlap at specific locations.

  • @Gabriel.C : Thank you very much for your help. Unfortunately I had already tried to make a Union and for reason that I do not understand I get an error message. I am using version 3.4 of QGis – Katlan34 Feb 4 at 10:32
  • @Katlan34 Verify that your file names, paths, etc. don't have special characters or spaces and try again (or simplify the paths to the maximum). It might do the trick. – Gabriel C. Feb 4 at 14:28
2

First question -

  1. Dissolve the "polygons" layer creating new layer "dissolved"
  2. Give consecutive ID to each of the "dissolved" features
  3. Attach the "dissolved" layer ID back to the original "polygons" layer using spatial join based on intersection
  4. As a result you should have a new ID attribute in "polygons", which is identical for all overlapping polygons

Second question -

  1. Summarizing the number of occurrences for each value in the new "polygons" ID column will give the count of overlapping polygons per area

If you can post a small sample dataset, I'll be happy to prepare a reproducible example.

  • Thank you very much for your answer. But just like Gabriel, I have a error message when i use dissolve with Grass in 3.4 of QGis. – Katlan34 Feb 4 at 10:35
  • I'm using R for this sort of things. If that's relevant for you, I can try the procedure in R, on sample data. – Michael Dorman Feb 4 at 15:36
  • I was just looking at R but I'm also stuck. I'm going to open a new topic for R. – Katlan34 Feb 6 at 15:48
0

Thank you for your answers, by using an earlier version of QGis and using the dissolve function and multiple to single entities, I was able to answer my question. Thank you again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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