5

I have a layer (called here 'layer_top') made of multiple polygons (in orange in the picture). Each polygon of the 'layer_top' overlaps with polygons of other different layers (called here 1,2,3,...). Each of these layers, within the 'layer_top', has a column with a score value (like in the picture). I would like to get the sum of the scores of all polygons of the layers 1,2,3, ... contained in each polygon of the layer_top. I have searched for a solution in this forum and tried to join attributes by location (including summary), but the result is not what I want. enter image description here enter image description here

AUS85
  • 446
  • 3
  • 12
  • 1
    are there any preferences regarding the geometric predicate between polygons e.g. they must be fully inside or partial overlap is also allowed ? https://gis.stackexchange.com/questions/217444/understanding-join-attributes-by-location-in-qgis/305193#305193 – Taras Dec 05 '22 at 15:28
  • Thank you for the comment. Fully inside – AUS85 Dec 05 '22 at 15:49
  • See my answer. Depending on the number of layers you have in your project, their name as well as the name of the attributes, you could use array_foreach() function to avoid repeating the same part over and over again. If interested, please provide information about the number of layers, their names and name of attributes. – Babel Dec 05 '22 at 16:31
  • thank you. Where do you use that function? in the field calculator of the 'layer_top'? the number of layers within each polygon of the 'layer_top' are different (range between zero and ten). The name of the attributes are different except for the name of the score column – AUS85 Dec 05 '22 at 18:39
  • Ok, then probably indeed naming layers and attribute field manually is the best solution – Babel Dec 05 '22 at 18:51

2 Answers2

4

Use QGIS expressions with overlay_contains(). Use this expression where score1-3 are the names of the attribute you want to get the sum from:

array_sum (overlay_contains ('layer1', score1)) +
array_sum (overlay_contains ('layer2', score2)) +
array_sum (overlay_contains ('layer3', score3))
Babel
  • 71,072
  • 14
  • 78
  • 208
  • Thank you. Where do you use that function? in the field calculator of the 'layer_top'? – AUS85 Dec 05 '22 at 18:40
  • Yes, exactly there! – Babel Dec 05 '22 at 18:50
  • It says invalid expression. I think this is also time-consuming. What if I create a raster above the layers 1,2,3... and I calculate the highest score under each pixel? I mean I want to assign to each pixel the score of the layer below it that has the maximum value. How can I do that eventually? – AUS85 Dec 06 '22 at 11:32
0

I have found a solution for this question: transform all layers in raster and then sum the values with r.series of GRASS. Easy!

AUS85
  • 446
  • 3
  • 12