# Changing pixel values using QGIS raster calculator?

How could I convert values of 32767 to 0 using raster calculator in QGIS?

• Would you consider using GDAL_Calc? Do you want to change the values in the current raster or create an output raster with the values changed? – Michael Stimson Jan 8 '15 at 2:39
• Thanks, I will try :) I would like to have a new raster... – Nadia Jan 8 '15 at 23:10

If you have SAGA installed you could use the raster calculator in QGIS processing (SAGA-> Grid - Calculus-> Raster calculator) with the formulae:

``````ifelse(a=32767, 0, a)
``````
• I like that method, it gives the possibility of enforcing values other than 0, so it's more versatile, like for example anything greater than 255 to become 255: ifelse(a>255, 255, a). The Calc method only works for 0. – Michael Stimson Jan 11 '15 at 22:01

Nadia, I have used GDAL_Calc (python script) to change one value (or a range of values) into 0. This can be achieved because `False` is 0 (`True` is 1) on the conditional statement. The calculation is `Condition * Raster`, where the condition is `True` the output is the raster value, where it is `False`the value is 0.

Using the 3rd example:

``````gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
``````

The conditional statement becomes:

``````gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A!=32767)"
``````

Which is true wherever the raster is not equal (!=) to 32767.

If your raster layer name is `RasterA`, QGIS Raster Calculator expression is:

``````("RasterA@1" != 32767) * "Raster@1"
``````

The logic has been clearly explained by @MichaelStimson, but just for clarity...

• `("RasterA@1" != 32767)` is `0` if the cell value is `32767`.
• Otherwise `("RasterA@1" != 32767)` is `1`.