Skip to content

Instantly share code, notes, and snippets.

@rjsheperd
Created October 4, 2022 19:01
Show Gist options
  • Save rjsheperd/d1403ea19eee33f5a93b7026f9ce70a3 to your computer and use it in GitHub Desktop.
Save rjsheperd/d1403ea19eee33f5a93b7026f9ce70a3 to your computer and use it in GitHub Desktop.
Converts nodata value in a GeoTiff using GDAL
#!/usr/bin/env bash
cp "${INPUT}.tif" "${INPUT}-removed-nodata.tif"
INPUT="${INPUT}-removed-nodata.tif"
OUTPUT="${OUTPUT}.tif"
# Use gdal_edit.py to unset nodata metadata so we can use them in gdal_calc.py
gdal_edit.py -unsetnodata $INPUT
# Use gdal_calc.py to replace all values below 0 with -999, keep all other values.
rm $OUTPUT
gdal_calc.py -A $INPUT --outfile=$OUTPUT --calc="-999*(A<0)+A*(A>=0)" --NoDataValue=-999
gdalinfo -stats $OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment