0

I have a raster layer in QGIS that is stored as a three color image. I want to do some analyses on it and would like to have it just as values 1,2,3 (and then I can leave the presentation to later)

The raster is red, yellow, green and the band values are

255,0,0
0,245,0
240,240,0

So I should be able to use either the red band or the yellow band to extract my information.

This could easily be coded as

value=redband.value
if value==255:
    return(3)
if value==240:
    return(2)
if value==0:
    return(1)

To return red yellow and green as 3,2 and 1 respectively.

But in the field calculator, I can only see how to do mathematical expressions. Is it possible to run a script in the field calculator or do I have to rewrite this as a python script to run in the python console?

(I know it possible to turn a raster with only three distinct values into a polygon layer, but due to the structur of the raster, the polygon gets quite unwieldy and the analysis I am going to do on this later requires a raster)

2