I have large single layers with many features overlapping.
Simplified example with 50% transparency:
Where the features overlap I want the attributes added together. I manually created the output I want below.
I have large single layers with many features overlapping.
Simplified example with 50% transparency:
Where the features overlap I want the attributes added together. I manually created the output I want below.
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
)
(2) We obtain Union
layer (now broken into 12 parts...sorry mostly hidden...)
(3) Aggregate (Processing Toolbox | Vector geometry | Aggregate
)
Note: Group by
expression is geom_to_wkt( $geometry )
and the Aggregate function
is sum
(4) Final output is Aggregated
layer.
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.
(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).
(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.
Let's assume there is a polygon layer called 'test2' with some overlapping features in it, see the image below.
Step 1. Apply the SAGA's "Polygon Self-Intersection" tool
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: