I have a street layer which consists of many segments. I would like to count the number of points that have the same "name" attribute as my street layer and are nearest to the geometry of my line layer. Multiple lines have the same name, even so points should only be counted once.

I have attached a screenshot [edit: I made an example project to keep things simple] to help illustrate my problem.

enter image description here It should look something like this :

  filter:=intersects(closest_point($geometry, geometry(@parent)), geometry(@parent)))

1 Answer 1



You could use join by nearest in order to add the fid of the closest line to the points. Then determine how many points with the same joined fid are there using the count() expression. Finally run join attributes table (aka "join attributes by (attribute)value") in order to add the count from the points back to the lines.

Obviously this creates new layers, but you get your result. If you need to continue working with the exact same line layer, you might need to use the overlay_equals() expression on your original line layer in order to add the count of points to it.


I suspect using overlay_nearest() could replace join attributes table, which leads me to the realisation, that you can simply run overlay_nearest() in order to add the fid to the points, then count(), and again overlay_nearest().


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.