Created
October 4, 2022 19:01
-
-
Save rjsheperd/d1403ea19eee33f5a93b7026f9ce70a3 to your computer and use it in GitHub Desktop.
Converts nodata value in a GeoTiff using GDAL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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