4

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

enter image description here

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

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.

asked Jun 14, 2024 at 5:43

1 Answer 1

5

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])
answered Jun 14, 2024 at 6:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.