Saturday, 3 December 2016

qgis - What's wrong with my expression to control label colors?


I am struggling to alter the label colours according to field values (as strings) in the attributes table.



In my mind what I want is:


If the string in column X = 'Proposed' Then label the point using the string in column Y, with color A


Else Label the point using the string in column Y, with color B End


I have tried a bit, but struggling with the syntax


case when  "ownerenc" = 'Proposed' 
then (color_rgb(256,256,256))
else color_rgb(56,56,0)
end

But I realise this is quite wrong! Many thanks for your suggestions.




Answer



The syntax is almost correct (see the note in the end), but you might be using it in the wrong place.


The correct way of doing it is like this.



  1. Label your layer using your "Column Y" field, in the example below that's field "codigo".

  2. go to the "text" sub-menu, color and click the data defined button;

  3. There choose the edit... option below Expression;


enter image description here




  1. Put the desired expression in the expression builder (in the example).


enter image description here


Note: The rgb() function will only accept values from 0 to 255 to the red, green and blue arguments.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...