0

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

  • 2
    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
5

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
3

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 Falsethe 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.

1

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.

Your Answer

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

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