2

I have joined Argentina's census data wich has small area divisions, with electoral disctrict data wich has a bigger area than those of the census. In QGIS, I've calculated centroids for the census data and joined through the "join attribute by location (summary) tool".

Census data i aggregated to get the population in electoral disctrict, but i've found no way to caculate a census index which i would want to take to the electoral level by doin a weighted average:

(sum (index * total_pop)) / sum(total_pop)

The question sums as: Is there a way to add a statistic function (a user edited one) to the spatial join of the census centroids to the electoral disctrict polygons? This are the two layers i have

1 Answer 1

0

I suppose you have a polygon layer called district and a point layer census with attributes named index, pop (for population) and id for the polygon feature from the layer district that the point is within. To calculate for each district separately the sum of pop muliplied by index, use this expression:

sum( index*pop, group_by:=id)

In case you don't yet have an attribute id that links to the district the the census-centroid is in, create it using Join attribute by location or by creating a new field with field calculator and this expression (instead of name use any attribute name of the district layer - or $id if you have no attributes there):

array_first (overlay_within( 'districts', name))
3
  • Hey! thanks for the answer. The problem though is that there is no "id" columns. (or rather, the id's are not matchable). So the only way i can do the join is spatialy. The workaround i have right now is selecting each district, the census points within and manually calculating that through field caclulator. but it's kind of tiresome.
    – Juan Cib
    Commented Aug 31, 2021 at 16:55
  • Why are the id's not matchable? It can be any kind of attribute - the one you created by join attribute by location - that's what I understood. If not net done, create it.
    – Babel
    Commented Aug 31, 2021 at 16:57
  • ohh, i se your point. I'm going to try that! Thanks!
    – Juan Cib
    Commented Aug 31, 2021 at 16:59

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.