It's taken me nearly 8 years but I finally found the answer!
- Open Field Calculator to update field "VALUE_A" in Layer A, and use the following expression:
-
aggregate('Layer B', 'sum', "VALUE_B", within(centroid($geometry), geometry(@parent)))
...................... Open Field Calculator to update field "VALUE_A"
in Layer A, and use the following expression:
aggregate('Layer B', 'sum', "VALUE_B", within(centroid($geometry), geometry(@parent)))
Use Show Help to learn other functions you can use in each of the arguments:
-
aggregate(layer,aggregate,expression[,filter][,concatenator=''][,order_by])
aggregate(layer,aggregate,expression[,filter][,concatenator=''][,order_by])
I have found this does time out for larger datasets, if this is an issue then you can select a subset of overlapping polygons in both Layer A and Layer B, check 'Only update selected features' (in Layer A), and use the following modified expression:
-
aggregate('Layer B', 'sum', "VALUE_B", is_selected('Layer B', @feature) AND within(centroid($geometry), geometry(@parent)))
aggregate('Layer B', 'sum', "VALUE_B", is_selected('Layer B', @feature) AND within(centroid($geometry), geometry(@parent)))
Finally, if you wanted to update with a text value from the containing polygon you can use 'min''min'
as the aggregate instead of 'sum''sum'
.
:)