Counting population within polygons

I am really new with QGIS

I have a quadratic grid with different populations in each square and I have made polygons with the ORS plugin. The polygons cover some squares in full and some squares only partially. I need to count how much of the population is in each of the polygons. I am fine with assuming that the population is evenly spread within each square. I have tried to do that with MMQGIS, but I could not go further for my next step.

I am wondering if there is any other tool or way to do this. I hope to be able to do it automatically since I have to do it with lots of polygons.

• You say, you tried to achieve this using MMQGIS. Can you elaborate?
– Erik
Aug 24, 2021 at 13:27
• Maybe this gives you some ideas: gis.stackexchange.com/a/397101/88814 Aug 24, 2021 at 14:17
• Hi Erik, I have used special join in MMQGIS. I have used the quadratic grid's layer as the data layer and the polygon’s layer as the output shape layer. I thought I have gotten good results, but It was not. I am still stuck with a problem when I trying to move to my next step, which is that I have to split the population between overlapping polygons at that time. So I am trying to find a solution. I am really happy with your help and your way to solve the first step. I prefer to work with your solution. Thanks, Erik. gis.stackexchange.com/questions/409232/splitting-population Aug 26, 2021 at 11:09

2 Answers

This is a rather straightforward workflow heavily relying on the field calculator:

1. Get the size of your grid cells, using `\$area` in the field calculator (let's call this new field `grid-area`).
2. Assign an ID to each of your polygons using `\$id` in the field calculator (field `ID`).
3. Use the vector tool `intersect`, the first input being your polygons, the second your grid. This combines overlapping geometries and assigns them the attributes of both geometries.
4. Calculate the `\$area` of your intersected polygons (call it e.g. `area-new`).
5. Calculate the ratio between the area of the intersected polygons and the original grid cell using `"area-new"/"grid-area"`.
6. Multiply the population with the ratio (new field called `pop-new`).
7. Create the sums for each polygon based on the `pop-new` field and the `ID`, using `sum("pop-new","ID")`.
8. If you want to clean everything up, you may use the `dissolve`-tool your intersected polygons based on the `ID`-field.

My suggestions would be to transform the raster cells into polygons or points.

Then you could use spatial join function to sum up all the intersecting points or polygons in your area polygons.

The disadvantage is, when more than one polygon intersects the cells, the value will be added to all intersecting polygons. And with points it will be assigned just to the one, which intersects the center of the cell.