11

I have large single layers with many features overlapping.

Simplified example with 50% transparency:

enter image description here

Where the features overlap I want the attributes added together. I manually created the output I want below.

enter image description here

1
  • Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq.
    – underdark
    Commented Sep 17, 2016 at 9:16

3 Answers 3

17

QGIS 3.2

Thanks to new Union tool in QGIS 3.2, this has become quite easy!!!

What we do, is just use Union and Aggregate tools.

(1) Union (Processing Toolbox | Vetor Overlay | Union)

enter image description here

(2) We obtain Union layer (now broken into 12 parts...sorry mostly hidden...)

enter image description here

(3) Aggregate (Processing Toolbox | Vector geometry | Aggregate)

Note: Group by expression is geom_to_wkt( $geometry ) and the Aggregate function is sum

enter image description here

(4) Final output is Aggregated layer.

enter image description here

1
  • Any tip on how to achieve the same result in posgis SQL ? Commented Oct 18, 2023 at 16:17
7

Before QGIS 3.2

This example requires MS-Excel function, along with SAGA in QGIS Processing Toolbox.

(1) Start Polygon self-intersection tool in QGIS Processing Toolbox | SAGA | Vector polygon tools. A trick here is to select your value field as Identifier.

enter image description here

(2) This tool adds an attribute field ID which shows values of all intersected polygons, separated by a | (pipe) in between.

do not use id

So, please avoid using id for a fieldname. (The id above is really bad example, which will be troublesome later when we save it as csv). Maybe fid or code would be fine.

(3) All overlapping feature will be given id: zero (0). Please edit and assign unique number. Save it as a csv file, and open by Microsoft Excel.

(4) In Excel, run Convert Text to Columns Wizard tool. (Choose | as the separator). Calculate sum of them (eg column F as sum of C,D,E in this example).

enter image description here

(5) Keep columns fid and sum and remove all the others. Save it as new csv file.

(6) Join the new csv file with the polygon layer using fid as the key field.

Lots of things to do... Not a pleasant way, but hope this helps.

4

Let's assume there is a polygon layer called 'test2' with some overlapping features in it, see the image below.

input

Step 1. Apply the SAGA's "Polygon Self-Intersection" tool

step1

Note: After applying this algorithm some fields from the input original layer become meaningless. Therefore the "Drop field(s)" algorithm can be useful.

Step 2. Use a bit of the "Field Calculator" for:

  1. counting overlaps

    array_length(string_to_array("ID",'|',1))
    

    result1

  2. summing values of a certain field e.g. "num"

     array_sum(
         array_foreach(
             string_to_array("ID",'|',"ID"),
             attribute(
                 get_feature('test2', 'id', to_int(@element)),
                 'num'
                 )
             )
         )
    

    result2

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.