For context I am working with a .tif file that I have warped and changed all nodata values to -9999.

Is there any way with GDAL to take all values from this .tif file that are greater than -9999 and convert them to another value?

I have tired to do this with ogr2ogr but I don't know enough SQL to make that work.

  • are you sure you're working with a shape file (=vector format)? Your problem description fits more to the raster format..
    – pLumo
    Commented Nov 20, 2017 at 10:19
  • Sorry, you are completely right, I've been staring at this code for too long. I'm working with a .tif file that has been rastered.
    – Francis
    Commented Nov 20, 2017 at 10:22
  • I've updated the question with the correct format
    – Francis
    Commented Nov 20, 2017 at 10:23

1 Answer 1


Nodata value can be changed with gdalwarp utility:

gdalwarp -srcnodata "-9999" -dstnodata "0" original_raster.tif new_raster.tif

To change raster data (values greater then -9999 to 100) use calculator:

 gdal_calc.py -A original_raster.tif --outfile=new_raster.tif --calc="100*(A>-9999)+A*(A<=-9999)"
  • 1
    As far as I understood, OP wants to change the data itself. Not setting the nodata value.
    – pLumo
    Commented Nov 20, 2017 at 10:36
  • @RoVo that is correct
    – Francis
    Commented Nov 20, 2017 at 10:41
  • 3
    Use calculator then (for example to convert values greater then -9999 to 100): gdal_calc.py -A original_raster.tif --outfile=new_raster.tif --calc="100*(A>-9999)+A*(A<=-9999)"
    – Vladimir
    Commented Nov 20, 2017 at 10:46

Your Answer

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

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