[Gdal-dev] Creation of geotiff files with gdalwarp that have a transparent background

Eric Sokolowsky eric.sokolowsky at gsfc.nasa.gov
Tue Mar 2 18:03:54 EST 2004


On Mon, 1 Mar 2004, Frank Warmerdam wrote:

> Eric Sokolowsky wrote:
> > I have been experimenting with the gdal library, specifically the
> > gdalwarp tool included with the library.  It is very useful, and I have
> > been able to transform images to a geographic projection.  Is there is a
> > way to specify a default background color?  Specifically, I wish to
> > create a geotiff file where the areas not covered by the original source
> > file are transparent.  Is this possible, or do I need to start hacking
> > gdal?  Would this change be generally useful to others?
> > 
> 
> Eric,
> 
> The default output value of a raster can be set with the INIT_DEST
> warp options.
> 
> eg.
> 
> gdalwarp in.tif out.tif -t_srs WGS84 -wo INIT_DEST=255

Hmm.  I tried the "-wo" option but when I used it the program just 
printed the usage statement.  Perhaps I have a version that is too old.
No matter; I got the images I wanted by using my recipe below.


> One issue you face is how to make something transparent in
> TIFF format.  TIFF supports transparency if you use RGBA format.  That
> is four bands with red, green, blue and alpha (transparency).  But if
> your inputs is just RGB there is no obvious way to force gdalwarp to
> produce an RGBA output file, and to treat the alpha band as a proper
> transparency overlay.

I have developed a recipe to create the images that I want.  Thanks for
pointing me in the right direction.  Here is what I do:

My source image is a geotiff file in Lambert Azimuthal Equal Area projection.
I use ImageMagick's convert tool with the "-matte" option to add a matte
channel to the image.  (I also have to use "-compress none" to get around
lzw patent issues.)  This step, unfortunately, strips out the georegistration
information, but I can put it back with geotifcp, using the "-g" option on
the georegistration information (which itself is produced with listgeo).
Then I can use gdalwarp to produce the final image.

Of course, making the transparency work properly in gdalwarp would be
nice.  Fortunately, I can script all of these steps and I don't really
have that many to do.


-- 
    ____   __     Eric Sokolowsky    (GST)  NASA Goddard Space Flight Center 
   / __/__/_/__  Visualization Programmer    Scientific Visualization Studio
  / __/ _/ / _/ 301.286.3751                  Mailstop 935.0 Bldg 28 Rm E102
 /___/_//_/__/ eric.sokolowsky at gsfc.nasa.gov   Greenbelt, MD 20771




More information about the Gdal-dev mailing list