3

In QGIS I've set up some project variables called rv_farbe1, rv_farbe2 and so on. The contain color values in html notation like '#ff0080'.

enter image description here

Now in rule base labels I would like to setup data defined override by selecting the text color based on an attribute value sektor_lfd_nr. The idea is to concatenate a string @rv_farbe and the sektor_lfd_nr and evaluate the result in order to access the variable value like

eval('@rv_farbe' ||  "sektor_lfd_nr")

As far as I understand, in expression editor preview I should get the color value, but preview (german: 'Ausgabevoransicht') displays nothing:

enter image description here

Furthermore, the text with data defined override set for it's color does not display.

Both using the variable directly (@rv_farbe1) as well as using the html style color code directly ('#ff00bb') works, so do I miss something about eval() statement, or what might be wrong here?

1
  • not sure how to do this with vanilla expressions. You could use a python function instead, such as this one to take a field name and look up (then return) the corresponding variable?
    – Steven Kay
    Commented Jul 16, 2017 at 19:16

1 Answer 1

3

After a night of forensics, I found that the problem is not the eval() statement.

The Layer for which I tried what I described above is based on a PostgreSQL view, which under very special conditions is caused to be empty by a division by zero error.

So the message is: The eval() statement works fine and can be used to retrieve variable values from a prefix/attribute value combination, i.e. eval('@rv_farbe'||"sektor_lfd_nr")

After fixing my view definition, the result is as expected (note the output preview):

[Image 2b added]

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.