2

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.

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

1 Answers1

8

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)"
Vladimir
  • 1,569
  • 7
  • 15
  • 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 – Francis Nov 20 '17 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 Nov 20 '17 at 10:46