I have a little question for Change No Data Value Geotiff File with Qgis or Gdal by another value. Usually one imports or exports a file with no data value -9999, but sometimes we need to change that number for another on raster calculator the expression != but it seems not to work with No data value any idea

Nice discussion, Carlos but at same Kurt this option is for a range of data. I was user syntax band math of ENVI and I thought to apply something like this on Raster Calculator

( "MCD10A1_2018266@1" != -9999) * -8888 AND  ( "MCD10A1_2018266@1" >=  0 )  * "MCD10A1_2018266@1"

But I do not understand does not work!!


5 Answers 5


Another possibility

You could to use this tool Menu >> Raster >> Conversion >> Translate (convert format)

And assign the new value to no-data values,

enter image description here

  • does also not work for me: a "no data" value cant be set to a valid value e.g. 0 or 100 or whatever
    – Kurt
    Oct 9, 2018 at 16:25

To change No Data values of a raster to something else, like 0 or 1 or whatever, you can use the GRASS tool r.null.

enter image description here


I use this script:


basename=$(echo "$1" | cut -f 1 -d '.')
nodata=$(gdalinfo $1 | grep "NoData" | cut -d "=" -f 2)
gdal_calc.py --NoDataValue=$2 --calc="A!=${nodata}" --outfile="$mask" -A $1
gdal_calc.py --NoDataValue=$2 --calc="A*B" --outfile="$output" -A $1 -B $mask

First it gets the current no data value, then it creates a mask where the data is set as 1 and then multiplies that mask to get new image where no data is set with a parameter.

To run it just write it e.g. as gdal_change_nodata.sh and run it typing:

bash gdal_change_nodata.sh PATH_TO_YOUR_IMAGE.tif NEW_NO_DATA_VAL

or just change the values of $1 param by the path to your original file and $2 by the no data value that you want to set.


when you export the raster, context menu

"Export --> Export Raster Layer As..."

You could to change the no data value, see the picture

From -99999 To -88888 (per example)

enter image description here

  • did NOT work for me, when you have "no data" instead of say -9999
    – Kurt
    Oct 8, 2018 at 17:44
  • replace -99999 for the value that your raster use to "No data value" Oct 8, 2018 at 17:50
  • 1
    See the Layer properties (your raster) >> Information >> Bands >> No-Data Oct 8, 2018 at 17:52
  • 1
    ah , Layer properties (your raster) >> Information >> Bands >> No-Data shows which value is used for no data, thx
    – Kurt
    Oct 8, 2018 at 18:12
  • 2
    Is there a way to recode a "no data"-value to a valid value, e.g. 0 ?
    – Kurt
    Oct 8, 2018 at 18:15

I wanted to accomplish this within a Python script using GDAL personally. The following script worked for me

dataset = gdal.Open('path/to/image.tif')
band = dataset.GetRasterBand(1)
band.SetNoDataValue(2**16 - 1) # my No Data value was '65536'.. or 2^16 - 1
del dataset

Your Answer

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

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