I am trying to perform some calculations on a polygons layer I have, but there is a bit of complexity to it. I have this polygons layer, and underneath that layer, I have a population count data layer (1 dot = 1 person). I then draw 1-mile buffers around the centroid of each polygon (These are conceptual examples of course as I have not actually figured out yet how to do this with my own data):
Then I want to count, for each polygon, how many people fall within that polygon's buffer, regardless of whether that buffer overlaps with the buffer from another polygon. I want to calculate this value for each polygon and append it as a column to the layer's attribute table (we'll call this column "raw_count"). Now here is the complicated part. For every polygon, I now want to calculate the count value within that polygon's buffer, but where the dots that are overlapped by the buffer of another polygon are not counted. I want to create a new column with this new count value for each polygon and then append it to the layer's attribute table (we'll call this new column "clipped_count"
. Here is an example for polygon 1 (in grey):
There are 5 dots within the buffer for polygon 1 (both green and red). I only want to count the green dots. Since the red dots are overlapped with another buffer, I do not want to count them for polygon 1. And so the "clipped"
count for polygon 1 would be 3. Then I want to move to polygon 2 (in grey):
There are a total of 6 dots within polygon 2's buffer. I only want to count the green dots. I do not want to count the red dots, because they overlap with the buffers of other polygons. And so the "clipped"
count for polygon 2 would be 3. Now I want to do the same for polygon 3 (in grey):
The buffer for polygon 3 has 4 dots within it, all green. Since there are no overlapped buffers, I only need to worry about counting those 4 green dots. And so the "clipped" count for polygon 3 would be 4. (Note that all dots are the same throughout this post and I just change from red/green to indicate which ones I want to count at the moment).
I want to repeat this entire counting process for every polygon in the layer (hundreds of polygons), so essentially iterating through every polygon with this process. So the end goal would be to have my polygons layer with two additional columns appended to the attribute table: 1) "raw_counts"
and 2) "clipped_counts"
.
Can this be done in QGIS? Or would this require Python? I am unsure of how to iterate through all polygons in the layer with these processes. How can I accomplish this?