[gdal-dev] Warp to GeoTIFF with Transparency?
Nik Sands
nixanz at nixanz.com
Wed Sep 19 15:43:59 PDT 2012
Thank you very kindly, Even. It works perfectly now. I can't recall exactly what I'd tried previously when adding the additional band, but I think I must have neglected to include the
psWarpOptions->nDstAlphaBand = GDALGetRasterCount(hSrcDS) + 1;
I thought I'd tried that before, but it certainly fixed it this time.
So again... thanks very much for your assistance. It's very much appreciated.
Cheers,
Nik.
On 19/09/2012, at 7:12 AM, Even Rouault <even.rouault at mines-paris.org> wrote:
> 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