2

I have created a shapefile with lines which I use to place labels exactly where I want them relative to map features. The shapefile has a field for the name that will appear as the label and also a field called Terrain Type.

I am trying to get the label colour to set based upon the value in the Terrain Type field.

(I am new to QGIS, not using real world data and haven't programmed since using OpenScript with Toolbook about 20 years ago)

Here is what I was trying to do... Based on another help response I found online, I right clicked on the drop down for the colour in the labels section of the Text section and wrote the following code:

Program Screenshot

CASE
WHEN "Terrain Type" = "Coniferous  Forest" 
THEN Color_rgb (18,95,27)
WHEN "Terrain Type" = "Hill" 
THEN Color_rgb (231,238,239)
WHEN "Terrain Type" = "Coastal Plain" 
THEN Color_rgb (35,209,16)
WHEN "Terrain Type" = "Bay" 
THEN Color_rgb (101,78,240)
WHEN "Terrain Type" = "Scrub" 
THEN Color_rgb (155,222,61)
END

It returns an error message saying "Eval Error: Column 'Coniferous Forest' not found".

I have checked the set of similar questions and they don't seem to get me where I need to go.

  • 1
    Sorry, forgot to mention I am using QGIS 3.10 – Really New User Nov 10 at 14:59
3

Set your string into simple quotes ' e.g. 'Hill'. Double quotes refer to fields. So the error you are getting means, that your shapefile does not contain a field named "Coniferous Forest".

Try this:

CASE
WHEN "Terrain Type" = 'Coniferous  Forest'
THEN Color_rgb (18,95,27)
WHEN "Terrain Type" = 'Hill' 
THEN Color_rgb (231,238,239)
WHEN "Terrain Type" = 'Coastal Plain'
THEN Color_rgb (35,209,16)
WHEN "Terrain Type" = 'Bay' 
THEN Color_rgb (101,78,240)
WHEN "Terrain Type" = 'Scrub' 
THEN Color_rgb (155,222,61)
END
  • Brilliant! Thank you, that worked perfectly. – Really New User Nov 10 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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