17

Is there a way to set all the 0 value pixels on a raster to nodata using GDAL?

I would like to use fillnodata to fill some holes, but holes are set to 0, so I need to delete them first

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Andrea Ghensi
  • 173
  • 1
  • 1
  • 4

2 Answers2

15

You could try something like this with gdal_translate

gdal_translate -of GTiff -a_nodata 0 input.tif output.tif
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
dango
  • 771
  • 4
  • 16
  • Note: This only works if the raster does not have existing nodata values. It will set zero to be nodata, but existing nodata values will no longer be considered nodata. – Sheldonfrith Apr 25 '23 at 13:15
5

with gdal:

  1. gdalbuildvrt -of GTIFF -srcnodata 0 input.tif myVrt.vrt
  2. gdal_translate -of GTIFF -scale -a_nodata 0 myVrt.vrt output.tif

beside this you can use raster calculator plugin or grass in qgis too. and arcpy SetNull method.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
urcm
  • 22,533
  • 4
  • 57
  • 109