GeoTIFF NoData – Changing GeoTIFF ‘No Data’ Color to White/Transparent

arcgis-desktopgdalgeonetworkgeoservergeotiff-tiff

I am preparing data for inclusion into a geonetwork node, where the maps are displayed via geoserver.

The problem is that cells that have"no data" are displaying as black in the geotiff and I am would like the color to be set to white or transparent.

I am using ArcView and do not have access to either Spatial Analyst or 3D analyst.

I would prefer not to have to assign a new sld file and am presently using "Use colormap" when exporting from ArcGIS Desktop.

Best Answer

The gdal_edit utility allows changing the NODATA value without editing any pixels, just changing the metadata value.

gdal_edit -a_nodata 255 somefile.tif

will instruct programs to treat white (255) as nodata or null. It applies the same value for all bands of a multiband image, so if the above were an RGB image 255,255,255 becomes nodata.

gdalsetnull.py is a simple python script to set specified raster value NODATA, without creating a new raster. The easiest route to installing GDAL on windows is via OSGeo4W. Examples:

python gdalsetnull.py foobar.tif 0            # pure black is transparent
python gdalsetnull.py foobar.tif 0 255 0      # pure green is
python gdalsetnull.py foobar.tif 50 23 77 100 # arbitrary value in 4 band image

If you don't mind some processing overhead and creating a new image rather than editing in place there is also gdal_calc which allows actually changing the cell values rather than just updating the metadata.

Set values of zero and below to null:

gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0

Update 2020-Feb: added gdal_edit.