From a layer with point geometry 'POINTS' and a layer with polygon geometry 'POLY'. Both layers have a common attribute field "UNIONCODE".
To the 'POINTS' layer I apply the following expression for Geometry Generator that draws a line to the center of the polygon with which it shares the same code 'UNIONCODE'.
make_line($geometry,point_on_surface(geometry(get_feature('POLY','UNIONCODE',attribute($currentfeature,'UNIONCODE')))))
To count the joining points that join each polygon with the shared attribute, I use the following expression:
aggregate(
layer:='POINTS',
aggregate:='count',
expression:="UNIONCODE",
filter:=intersects(
make_line($geometry, point_on_surface(geometry(get_feature('POLY','UNIONCODE',attribute($currentfeature,'UNIONCODE'))))),
$geometry
)
)
As you can see, this expression only counts the total points and does not filter for each different polygon.
I would like to count the unions that are generated for each different polygon with an expression for Geometry Generator applicable to Labels.
1 Answer 1
As you already have an attribute that identifies the polygon each point is assigned to, you can count the points, grouped by this value - simply:
count (@id, group_by:=UNIONCODE)
If you want to count based on the geometry (no. of points within each polygon), use this expression:
count (@id, group_by:=overlay_within ('POLY',@id)[0])