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.


3 Answers 3


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.

  • Nicely done Matt!
    – DavidF
    Oct 26, 2010 at 18:31
  • Does this really answer the question? Your (nice!) script will set a color to NULL, but I guess it is still WMS-implementation specific, in which color (let's say transparent is a color, too) the NODATA values are rendered.
    – alfonx
    May 14, 2011 at 13:27
  • @alfonx, yes there's a difference between a cell that's recorded as nodata and cell that says I am 0 and the application decides whether it or some other value should be ignored. ArcGIS does respect the results of gdalsetnull.py; I've no experience with GeoServer. May 16, 2011 at 19:27
  • 1
    Looks like it's moved again, now at: github.com/maphew/maphew-gcode-archive/blob/… Apr 4, 2015 at 2:21
  • link fixed, thanks for note! @SteveBennett we should delete these meta comments now. Apr 22, 2015 at 17:48

In concept, you need to figure out what pixel values represent cells with no data and then edit your color table to assign the RED,GREEN,BLUE (RGB) values in the color table to be 255,255,255 for that cell value.

If you don't have the appropriate license to do this in Arc, you could use the gdal_translate tool (one of the gdal/ogr commandline tools)

  1. export the color table for your tif as an XML file.
    gdal_translate -of VRT myImage.tif outColorTable.vrt

  2. open up the .vrt file in a text editor and find the entry for the value of your no data pixels. There isn't an index number for the cell values, so you have to count down to the correct entry.

  3. edit this value to be <Entry c1="255" c2="255" c3="255" c4="255"/>

  4. now, create a new tif based on the new color table
    gdal_translate outColorTable.vrt newCorrected.tif

(example added based on comment below)

When I run the command in item #2 above and open up the .vrt file in a text editor, I see XML contents.

Part of the file includes lines that look like this, I have snipped most of them out.

  • Hi DavidF. Thanks fot the answer which I have been trying to carry out with FWTools (a bit easier to navigate for the novice). But I am having trouble finding the "value" in the vrt file because when I open the file with notepad their are now discernable words and it is composed mainly of random (code) text. Am I doing something wrong? - any additional help greatly appreciated.
    – enmapping
    Oct 27, 2010 at 20:01
  • @user1106 - Try the above commands again, I had left out output format option. It should work now!
    – DavidF
    Oct 27, 2010 at 21:19

Besides that you preferred NOT to create a new SLD file, here is a blog entry on how to convert the internal colormap of a GeoTIFF to a SymbologyEncoding/SLD and define another colour there. In the derived SLD it is easy to define exactly which values to render with a 100% transparent color.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.