I am using 3.12 QGIS version. I have got two point layers, and one line layer.

I wanna put a label on line layer, that calculate "sum" of intersected points or any mathematical calculation.

The main purpose is collecting any points (value) which intersected with line, but to keep in mind, we assume there are thousands point intersected, so when we build the code in expression dialog, we dont need to define the points layer, because generalizing the solution would be better.

enter image description here


1 Answer 1


You can use aggregate function in the expression. I show you an example. I have a point layer 'pnt' and a line layer 'ln'. Point are not necessary the vertices of the line, those are near to the line (in my expression the limit is 20 map units).

  1. Open the labelling tab for the line layer in layer styling or in layer properties.
  2. Set labelling to Single Labels
  3. Push the expression button on the right of the Value field
  4. Enter the following expression:

    aggregate( 'pnt', 'count', 'id', contains(buffer(geometry(@parent),20), $geometry))


The aggregate function can collect data from other layers in the project. First you have to add the layer name or layer ID, then the name of aggregate function (there are 10+ functions), a column name the aggregate function works (in the case of count any column can be used), the last parameters is a filter. In the filter I used buffer for lines to find points very near to line (it may not need for you).

For several point layers, I suppose you can make a OGR virtual format from your point layers and add it to QGIS.

enter image description here

  • first thank you mate for the answer. your solution counts the dots, not the attribute value inside the dots layer. besides, i prefer to count the dot only once even if thousands of line intersected there. Commented Apr 19, 2020 at 11:09
  • anyway, is there solution that doesnt require defining points layer ? Commented Apr 19, 2020 at 11:11
  • You can replace 'count' to 'sum' and 'id' to the column you would like to sum up. Your comment makes your question not clear. Update your question and tell us what you want, what you tried so far and what your real question.
    – Zoltan
    Commented Apr 19, 2020 at 11:45
  • i have update the description, do you get my purpose of the question ? sorry if my english is bad Commented Apr 20, 2020 at 1:15
  • 1
    No, this is a forum to answer direct questions, not for "please solve my problem".
    – Zoltan
    Commented Apr 20, 2020 at 7:18

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.