2

I am blocked on trying to work with Layer Properties Rule-based Expressions.

For a simple example in expression string builder: I have a column field named HOUSE. A list of values within that field show SMALL, MEDIUM, LARGE. What rule expression would I use to allow different colors for each of the values?

I tried this:

CASE WHEN "HOUSE" = 'SMALL' THEN color_  rgb(255,0,0) END

but got this message:

Parser Error: syntax error, unexpected COLUMN_REF, expecting WHEN or ELSE or END Eval Error: No root node! Parsing failed?

Can someone please reply with a correct expression I can use?

11
  • Why don't you use "Categorized" symbolic method on HOUSE A ?
    – gisnside
    Sep 23, 2017 at 20:13
  • Not test but CASE might need several WHEN conditions Sep 23, 2017 at 20:19
  • Hi there. A typo with field just named HOUSE. I will look up and see how to use "Categorized" symbols. Thanks much!
    – qb7
    Sep 23, 2017 at 20:19
  • Hi Hugo. I am really a novice, so will try what gisnside suggested. Thank you.
    – qb7
    Sep 23, 2017 at 20:22
  • gisnside....thank you! I did not go far enough in my reading to understand the categorized style. Your suggested instantly resolved the issue. You are awesome :)
    – qb7
    Sep 23, 2017 at 20:33

2 Answers 2

7

You just need to use the Categorized" symbolic method on HOUSE A, this way, you will have a different symbolic on each size of house.

house size

If you really need to get the rule based style on your different types of attributes for other reasons, first do the categorized, apply, then select "rule based", the filter will already have been entered by the software :)

house size rule based

3
  • Oh wow...just saw this second reply of yours, gisnside. Thank you ever so much for the precise process description and diagram. This will certainly allow me to expand on what I can do. I was using DIVA to perform basic requirements for sometime; it did what I needed. But QGIS appears to allow far more capabilities. Thank you once again!
    – qb7
    Sep 23, 2017 at 20:49
  • 1
    @qb7 please, accept this answer if it solves the issue: it will help future readers to understand that this solution works.
    – mgri
    Sep 23, 2017 at 22:00
  • @qb7 my pleasure helping out :)
    – gisnside
    Sep 24, 2017 at 8:23
2

You get the parse error because you inserted a blank in color_rgb. So the THEN part has two expressions that QGIS can not understand.

This would not work anyway, because you don't tell QGIS what to do with the colour value: style the fill or style the outline?

Apart from the categorized styling described in the other answer, you can use rule-based expressions on colors for fill and outline as well. You need to click on the symbol right to the color bar of the Simple marker (not Marker!), and select edit ... : At this point, a string is allowed, so you may enter this condition:

CASE WHEN  "HOUSE"  = 'SMALL' THEN color_rgb(255,0,0)
ELSE 
  CASE WHEN  "HOUSE"  = 'MEDIUM' THEN color_rgb(0,255,0)
  ELSE
    CASE WHEN  "HOUSE"  = 'LARGE' THEN '0,0,255'
    END
  END
END

Note that you can leave out the color_rgb() and use a simple string as well.

1
  • AndreJ...thank you very much also for your input. It is good to have your correction on the rule-based expressions formula I attempted. It will certainly be beneficial to understand more about ruled-based and categorized ways. Slow but sure...cheers!
    – qb7
    Sep 25, 2017 at 23:37

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.