Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)   

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

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
Many thanks - this is spot on! – dreab Sep 2 '14 at 13:17
I'm glad it helped. please consider accepting the answer. – Alexandre Neto Sep 2 '14 at 13:41
I wanted to! But I couldn't find anywhere where to do this. Now I looked again and I have seen the green tick. Thanks – dreab Sep 3 '14 at 14:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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