TransWikia.com

Get feature value to use in print composer label

Geographic Information Systems Asked on May 18, 2021

I’m trying to get the value of a feature (the area) to use as label in the print composer, but I’m not getting much success.

This is the expression I’m using in the text label in composer:

attribute(get_feature_by_id ('POLIGONAL_FNHIS2008A_8babdf78_50dc_480f_b811_0da927b7c9a5',1),'area')

The program shows me this message: No feature was found on this layer to evaluate the expression.

But the image bellow contains the information about my layer I’m referring in the expression, showing the fields and the values. What am I doing wrong?

enter image description here

One Answer

You are doing nothing wrong here. The expression is correct. It just seems like, the attribute() as well as attributes() function does not work in print layout (at least in 3.16). I dont know why. I can only provide a rather poor workaround:

Instead of a textfield, add an attribute table and select your layer as datasource and remove the header as well as the frame:

enter image description here

Now click on "attributes" and open the expression builder:

enter image description here

Enter your text, concatenated with your attribute, e.g. 'The area is: ' || "test" || ' square meters':

enter image description here

Result...

enter image description here

Correct answer by MrXsquared on May 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP