3

I have multiple layer containing each a different point object. I want to label those points with their coordinates in the legend of my print layout. I tried saving the coordiantes as attributes and using an expression(legend -> expression string builder) like: @layer_name +"attribute_name" to label the object, but according to this answer thats not an option.

1 Answer 1

4

You may refer to non-geometry-attributes of any map layer in the legend item.

After saving the coordinates to one or two fields, you may use something like the following:

[%aggregate('Your layer name from the map layer dropdown in the expression builder','max',"coordinates")%]

This returns the maximum value for the "coordinates" attribute of your layer.

If you saved your coordinates to two fields, run something like the following: [%aggregate('Your layer name from the map layer dropdown in the expression builder','max',"X-coordinate")%], [%aggregate('Your layer name from the map layer dropdown in the expression builder','max',"Y-coordinate")%]

If your layer contains several features, e.g. one per category, but several categories per layer, you need to add a filter e.g. for the fid or the field you categorized by, resulting in [%aggregate('Your layer name from the map layer dropdown in the expression builder','max',"coordinates",filter:="fid"='ID of that one feature')%]

5
  • Im kinda new to the syntax so i copied your second expression for two fields and adjusted the layer and the atrribute but the brackets are marked as syntax errors
    – KJ2024
    Apr 22 at 13:45
  • 1
    Then close the expression after the first aggregate, enter your comma outside of the expression and open a second aggregate. Like... twice the first expression with different fields.
    – Erik
    Apr 22 at 13:54
  • So it should be something like this? [%aggregate('coordinates','max',"x")%] ||', '|| [%aggregate('coordinates','max',"y")%] That would create three syntax errors with "unexpected '[' " so i think im missing something
    – KJ2024
    Apr 23 at 12:00
  • 1
    without the ||', '||, only with, . The [% ... %] encloses the expression you're using, outside of that you may write "normal". I edited my answer, now it should work.
    – Erik
    Apr 23 at 12:48
  • Works perfectly, thank you very much
    – KJ2024
    Apr 23 at 14:12

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.