[GIS] GDAL 2.2.2 Checking all NoData Values in a directory of tifs are the same

gdalraster

How do I check if all the NoData Values of my rasters (.tif) are the same in a directory in a python script/command line/bash using ubuntu?

I am using Ubuntu 16.4 LTS and using the Terminal Command Line to look at and edit rasters.

These rasters will be processed and the area with values will eventually be polgonized, the NoData values will need to be the same therefore I need to check them.

Also my NoData Values for each individual tif files are not showing up as a raster band, they are embedded in the file itself;

RasterBand

Best Answer

If you're on Linux or Mac, Python is not needed.
The following bash script will do it:

for f in *.tif; do
    gdalinfo "$f" | grep -o 'NoData Value\=[-0-9]*' || echo "NoData Value=None";
done | uniq

This outputs one line for each unique NoData Value found in *.tif.