[gdal-dev] Warp to GeoTIFF with Transparency?
Even Rouault
even.rouault at mines-paris.org
Tue Sep 18 14:12:26 PDT 2012
Le mardi 18 septembre 2012 05:15:03, Nik Sands a écrit :
> I'm very new to GDAL so please be gentle. My searching has found many
> references to this problem, but no complete solutions that are explained
> clearly enough for me to work through.
The Warp API is powerful, and thus admitedly complex to master.
>
> I'm using the GDAL API to read in a source image (could be from a variety
> of formats), warp it to Spherical Mercator, and then write out the
> reprojected image as a GeoTIFF. I would like the parts of the warped TIFF
> that are not included in the original image to be represented by fully
> transparent pixels instead of the black pixels that are being generated.
>
> I've set "ALPHA" to "YES" in the warp options but this has not helped.
> I've also tried adding an extra transparent band, but this made the entire
> output image transparent.
Strange, perhaps you should retry.
To have a transparency band added in the output of the warping, you need to
set the band number in the GDALCreate() call to 1 +
GDALGetRasterCount(hSrcDS), and also set psWarpOptions->nDstAlphaBand = 1 +
GDALGetRasterCount(hSrcDS)
This should be equivalent to the -dstalpha option of gdalwarp. By the way, if
I were you, I would try to find the gdalwarp command line that fits my need, and
then study its code source to extract what is needed for your use case.
More information about the gdal-dev
mailing list