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 Nov 20 '17 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. – Yjelza Nov 20 '17 at 10:22
  • I've updated the question with the correct format – Yjelza Nov 20 '17 at 10:23

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)"
| improve this answer | |
  • 1
    As far as I understood, OP wants to change the data itself. Not setting the nodata value. – pLumo Nov 20 '17 at 10:36
  • @RoVo that is correct – Yjelza Nov 20 '17 at 10:41
  • 2
    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 Nov 20 '17 at 10:46

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.