0

I am using QGIS print composer. I have so many images to export with a specific label. The text of the label is existing in a field of a layer.

I have tried to use this expression attribute( get_feature( 'Metro_Ring','S','1'),'Route') but the result is NULL.

where:

Metro_Ring --> name or ID of the table

'S' --> the field for selection.

1 --> the value that selects the row of interest.

'Route' --> the name of the field of interest.

I wonder if there is any error or a different method to get the value of the field 'Route' in the label.

4
  • 1
    Is field S numeric? In which case try referring to value 1 as numeric (1) - without using quotes as that might suggest it is a a string. Also, all layer and field references here are case sensitive so make sure they match.
    – she_weeds
    Apr 13, 2020 at 21:51
  • Field S is numeric and I have written value 1 without quotes but I have got the same result. also, I have checked the layer and fields name and it does match.@she_weeds
    – Ahmed Alaa
    Apr 14, 2020 at 5:08
  • OK, well I'm assuming you're using this expression in a text box in Print Composer? Perhaps we could narrow down the problem a bit. When you open the expression editor (by clicking Insert Expression), what does the Output preview show when you use just the get_feature('Metro_Ring','S',1) expression - does it return NULL or <feature : 0> (or some number other than 0)? If it's NULL then either the feature doesn't exist or you still have the layer/field reference wrong (maybe there is a trailing space in the layer name? Note this is the layer name in QGIS, not necessarily the filename)
    – she_weeds
    Apr 14, 2020 at 5:16
  • It is my fault. I have tested the function on a feature with a NULL value in 'Route' field. But the main problem solved by removing the quotes from value 1 because field 'S' is a numeric field. many thanx for you.@she_weeds
    – Ahmed Alaa
    Apr 14, 2020 at 5:32

1 Answer 1

1

S field is numeric so value 1 should be reffered as numeric (1).

The function would be as follow attribute( get_feature( 'Metro_Ring','S',1),'Route')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.