I want to create a rule for applying a particular symbology to a raster in QGIS. I do not know if this is possible. In detail, I would like to classify (as discrete) values of a raster1 based on its values and those of another raster (raster2). Both rasters are completely overlapping.

As an example, I want pixels colored in green when values of raster2 are 1 and values of raster1 are <= 5 otherwise pixels must be in red; similarly when values of raster2 are 2 and values of raster1 are <=1.5 color pixels in green otherwise in red; etc.

1 Answer 1

  1. Use Raster Calculator to create a new (binary) raster based on the conditions you have with the following expression that creates a value 1 if one of the conditions is fulfilled (green) or 0 (red) if none of the conditions is fulfilled. You can add more lines for your further conditions:

    "raster2@1" = 1 and "raster1@1" <=5 or
    "raster2@1" = 2 and "raster1@1" <=1.5
  2. The resulting raster has values of 0 or 1. Set this raster's color to Singleband pseudocolor (see screenshot) and use a color ramp from red to green.

By the way: red/green colors can be problematic due to color blindness issues, see e.g.:

It’s important to emphasize here that using red and green, while intuitive, should be avoided. https://seaborn.pydata.org/tutorial/color_palettes.html

Resulting raster, clicked a green pixel (value=1, color=green) with underlaying raster1=1.33883 and raster2=1: enter image description here

  • 1
    Just a correction. It doesn't work with the formulation you posted. I have changed it: IF(("raster2@1" = 1) and ("raster1@1" <=5)) or IF(("raster2@1" = 2) and ("raster1@1" <=1.5))
    – AUS85
    Commented Jan 23 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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