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'.


enter image description here

To count the joining points that join each polygon with the shared attribute, I use the following expression:

    make_line($geometry, point_on_surface(geometry(get_feature('POLY','UNIONCODE',attribute($currentfeature,'UNIONCODE'))))),

enter image description here

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])

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.