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

  • 1
    are there any preferences regarding the geometric predicate between polygons e.g. they must be fully inside or partial overlap is also allowed ? gis.stackexchange.com/questions/217444/…
    – Taras
    Commented Dec 5, 2022 at 15:28
  • Thank you for the comment. Fully inside
    – AUS85
    Commented Dec 5, 2022 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
    Commented Dec 5, 2022 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
    Commented Dec 5, 2022 at 18:39
  • Ok, then probably indeed naming layers and attribute field manually is the best solution
    – Babel
    Commented Dec 5, 2022 at 18:51

2 Answers 2


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))
  • Thank you. Where do you use that function? in the field calculator of the 'layer_top'?
    – AUS85
    Commented Dec 5, 2022 at 18:40
  • Yes, exactly there!
    – Babel
    Commented Dec 5, 2022 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
    Commented Dec 6, 2022 at 11:32

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

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.