[FWTools] Converting a black border to transparent in geotifs

Simon Hook simon.j.hook at jpl.nasa.gov
Mon Feb 12 22:33:28 EST 2007


Hi Frank,

The second approach works like a champ:

gdalwarp -srcnodata 0 -dstalpha in.tif out.

and the regionator respects the transparency. It would be great if there 
was an fwtools for python 2.4 (required by regionator) because even 
though I used a windows binary form of GDAL from

http://www.urbansim.org/opus/opus_manual/docs/gdalinstall.html#quick

there were some bugs.

By comparison fwtools contains a whole bunch of useful tools, solid installation and GDAL. It might even make sense to include it with Enthon (www.enthought.com)?

Thanks again for the help, Simon

Simon Hook wrote:
> Hi Frank,
>
> I want to generate kml files from the final images (I got the google 
> regionator code working BTW). In the past we have generated a kml "by 
> hand" this involved opening a png in photoshop, changing the border 
> (zero values) to transparent, saving the png. Then placing the png 
> with google earth at the location on the earth and setting the 4 
> corners of the png. If the transparency step was done in photoshop the 
> black border does not show, if it has not been done you see the black 
> border. Now I only know how to use the regionator code with geotifs 
> (not pngs). So I think if I can ad an alpha channel that will work.
>
> I will try that and see what happens
>
> Best wishes,
>
> S.
>
> Frank Warmerdam wrote:
>> Simon Hook wrote:
>>> Hi,
>>>
>>> I apologize if I sent a similar post last night but for some reason 
>>> I did not get a copy thro' the list.
>>>
>>> I have some geotif images with a black border. I want to make the 
>>> border transparent. Is there a way to do this with FWTools?
>>
>> Simon,
>>
>> In part this depends on what software you want it to be transparent in.
>> In some software packages (like MapServer or OpenEV) you can pick a
>> "nodata value" such as 0 to be treated as transparent.  In some cases
>> the packages can also recognise nodata values as a kind of metadata from
>> the file.  The gdal_translate -a_nodata switch can be used to assign 
>> this
>> nodata value to an output file though it is only preserved in some 
>> formats.
>>
>> eg.
>> gdal_translate -a_nodata 0 in.tif out.tif
>>
>> Another approach to transparency is to add an alpha channel with
>> explicit transparency.  I think you could essentially assign all "zero"
>> pixels in an input greyscale image to have an alpha of zero in the 
>> output
>> using something like:
>>
>> gdalwarp -srcnodata 0 -dstalpha in.tif out.
>>
>> This whole area though is rife with challenges because:
>>
>>  o many software packages don't automatically support nodata values.
>>  o some software packages don't recognise alpha bands for transparency
>>  o some file formats don't support saving nodata values.
>>  o some formats don't support alpha bands.
>>  o GDAL's "nodata" data model treats nodata values as independent for
>>    each band.
>>  o all black pixels will get treated as transparent, not just border 
>> values.
>>
>> There are still a variety of issues I haven't addressed, but I think 
>> I'll
>> let you clarify what you want to do before I write more.
>>
>> Best regards,
> _______________________________________________
> FWTools mailing list
> FWTools at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/fwtools
> http://fwtools.maptools.org/


More information about the FWTools mailing list