so I have a shapefile with buildings and the shapefile has the height of the buildings in the attribute table. I have a second shapefile with the districts the buildings are located in. Now I would like to count the mean height of the buildings in each district and add it to the attribute table of the districts.

For raster data it would be easy using zonal statistics to get the mean for a specific area, but I cant figure out the solution for 'shapes within shapes'.

  • 1
    Have you tried Join attributes by location(summary)?
    – Taras
    Commented Jul 1, 2020 at 13:54
  • Okay so I think thats exactly what I am looking for but I have a problem. When I run the process it would give me an empty mean column in the new layer. I adjusted the CRS of the layer and I fixed the geometry of the layer with the buildings because the tool gave me an error regarding the geometry. Now there is no error but still no results and im running out of ideas. Do you may have something in mind?
    – Tim
    Commented Jul 4, 2020 at 11:18
  • 1
    I suggest applying additionally "Fix geometries", "Remove null geometries" and "Delete duplicate geometries". Can you tell me what happens afterwards? Please, text me here discord.gg/h2rks6N, perhaps you can share your data with me
    – Taras
    Commented Jul 4, 2020 at 11:55
  • After some attempts on another computer it finally worked, thanks a lot for your help!
    – Tim
    Commented Jul 23, 2020 at 14:08

1 Answer 1


If the data is static, @Taras solution is the way to go.

Else, if the data changes frequently, you can create a virtual layer to compute the mean

Go to the menu Layer > Add Layer > Add/Edit Virtual Layer... and enter the following query. Replace the layer name for yours

SELECT poly.*, avg(pt.height) as mean_height
FROM my_polygon_layer poly
    JOIN my_point_layer pt ON st_intersects(poly.geometry, pt.geometry)
GROUP BY poly.id
  • Its static data, but thanks for your idea!
    – Tim
    Commented Jul 4, 2020 at 11:19

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.