4

I have a raster file with two different nodata values: -32768 and -3.40282347e+38. This happened because I am using -32768 as my nodata value, and the georeferencer in QGIS adds nodata pixels as -3.40282347e+38. I would like to have all my nodata pixels as a single value, which I would like to be -32768.

If the no data value is -32768 (or any other reasonable number), it is easy to change the value of the no data pixels into any other number using the raster calculator in QGIS.

NOTE: For this to work, you first have to uncheck "No data value" in the Transparency window of Layer Properties, otherwise the raster calculator won't recognize the no data pixels.

To change nodata pixels with a value of -32768 to -999 using the raster calculator, you can use the following formula:

("RasterFileName@1"=-32768)*(-999)+("RasterFileName@1"!=-32768)*("RasterFileName@1")

However, this will not work for nodata pixels with a value of -3.40282347e+38. The raster calculator does not recognize these pixels, and they do not get changed.

I thought that this might because the raster calculator did not like the format of -3.40282347e+38, so I tried using the raster calculator to change any pixel that was less than -10000, using the following formula:

("RasterFileName@1"<-10000)*(-999)+("RasterFileName@1">=-10000)*("RasterFileName@1")

This correctly finds all the pixels that are -32768, but still ignores the pixels with a value of -3.40282347e+38.

Is there any way to get the raster calculator to recognize pixels with a value of -3.40282347e+38? Or some other strategy of getting rid of this noxious number?

  • ("RasterFileName@1"<-10000)*(0) will always be 0, no matter what "RasterFileName@1"<-10000 evaluates to. Anything times zero always equals zero. – csk Nov 6 at 20:42
  • Correct. That term in the formula is unnecessary if you want to change the pixel value to zero. However, this is a general formula that can be used to change the pixel number to any value you want. For any desired value other than 0, that term is necessary. I don't actually want to change the pixel value to 0, I was just using that as a simple example. But maybe 0 is a poor example for that reason. I will change it in the question. – stu Nov 7 at 8:33
3

If you start QGIS with GRASS, you can use r.null from processing toolbox. Enter the value you want to change and its new value.

enter image description here

  • Thank you! This works perfectly. – stu Nov 6 at 7:49

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.