1

Using QGIS, I want to display points on a basemap, the color of the point (symbol) I need to change from a 'rule based' expression.

I have loaded a basemap, imported my data, a .csv file containing amongst others a lat column, a lon column and a 'level' column, containing values from -30 to -140.

I have selected 'rule based' and in the 'expression' I have "level" >-108. This puts me a colored dot on the map at the correct point when the value in the 'level field is greater than -108, but what I want is for the dot to be a different color if 'level is less than -108, (there are some other fields that I will deal with later, hence needing a rules based expression).

So, basically, my question is how do I make the symbol a different color depending on the value when using expressions? I have tried color_rgb and symbol_color, neither worked.

  • 1
    Welcome to GIS:SE @tsteele! Perhaps an expression like: if("level" > -108, color_rgb(0, 255, 0), color_rgb(255, 0, 0)) – Joseph Dec 5 '17 at 14:32
  • Hi Joseph, I tried that, as you wrote, but the symbol (point) didn't change color. – user110549 Dec 5 '17 at 14:48
  • You don't need to use rule-based for the expression, you can use Single symbol, click the Simple marker to open all the options. Then click the little box icon on the right of the Fill option and enter the expression there :) – Joseph Dec 5 '17 at 15:02
  • Hi Joseph, Fabulous, doing it like hat worked, but.... I have another colums 'Channel' which is a radio channel. – user110549 Dec 5 '17 at 15:58
  • Apologies, hit enter by mistake. The radio channel column has radio channels from lets say 1 - 5. Now, and this was my reason for entering the expression as rule based, if the channel is 1, the level would be -108, if the channel was 2, it would be -110 if channel was 3, the level would be -115 and so on. Can I put multiple expressions for a single point to change the color depending on the channel and the level? – user110549 Dec 5 '17 at 16:01
2

Following conversations between @tsteele and @Joseph, this is a summary of steps to set colors using both "level" and "channel" fields.

enter image description here

  1. Start with Rule-based symbology. Create five groups by "channel" fields (1 - 5).
  2. Double-click on "channel"=1 group to open an edit window. Select Simple marker and Data defined override icon at the right-hand side of the Fill color. Select Edit option.
  3. Enter the expression provided by @Joseph (if("level" > -108, color_rgb(0, 255, 0), color_rgb(255, 0, 0))). Hit OK to close.
  4. Repeat this to channel = 2 - 5 as well. The expression is kept in Recent group, so repeating it is quite easy task.

There is an option to set sub-rules (pull-down menu is shown in the above picture) but setting expression would be easy enough.

Your Answer

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