For an agroforestry design in QGIS I am trying to add dynamic labels to an area polygon that displays the number of rows, total length and the total number of trees that are in the design.

So far I manged to create a label for the area that list the name of the area & number of rows, but I am struggling to add the total sum of tree row lenght and the total number of tree to be planted to the labels.

I managed to add a new field (number_of_rows) to the attribute table and using the attribute form I linked this function expression layer_property(´treeLinelayer_ID´),´features_count´ function, so that it always has an up to date count of tree rows (the designs are still changing)

I was able to add dynamic line length and number_of tree labels to the individual tree lines, but not to the polygon file. there are many lines and in the end there will be many different areas, so I would really like to show the total length and number of trees per area.

Any suggestions on how to go about this? The sum line lengths in the vector analysis tools does not seem to be useful in this case, because first of all, the labels need to automatically change according to future updates in design parameters (distance between tree rows & distance between trees).

1 Answer 1


You can use the overlay_intersects() function to grab aggregates from another layer.

For example to count the number of features from your Tree Line layer intersecting the polygon:


To sum the number of trees from the Tree Line features intersecting the polygon:


To sum the length of Tree Line features intersecting the polygon:


You can use this in the label expression for your polygon and it will dynamically update:

enter image description here

  • Great. Thats looks exactly like what I am trying to achieve. Thank you! I will try it out later today and will ley you know if it worked.
    – Adamski
    Dec 6, 2022 at 10:19
  • If the solution works don't forget to mark your question as answered to help others who might have a similar question in the future :)
    – she_weeds
    Dec 6, 2022 at 21:38

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.