[gdal-dev] Reprojecting orthoimages and transparent borders

Even Rouault even.rouault at spatialys.com
Fri Feb 26 10:39:47 PST 2016


Le jeudi 25 février 2016 14:46:15, Neumann, Andreas a écrit :
> Hi,
> 
> When reprojecting RGB orthoimages with gdalwarp from one projection
> system into another, there is often rotation involved and thus there
> will be black pixels around the borders. My target format is TIFF with
> JPEG compression.
> 
> Is there a way to tell gdalwarp to set these nodata pixels transparent?
> 
> I tried using -dstalpha but gdalwarp tells me this is incompatible with
> "-co PHOTOMETRIC=YCBCR", becauses this only supports 3 bands.
> 
> Thank you if you have any idea if there is some setting for RGB Geotiff
> files to set nodata pixels to transparent.

1) To get the smaller file size / best quality, you should consider doing a
gdal_translate after gdalwarp (and the gdalwarp using no compression or a lossless compression). See 
https://trac.osgeo.org/gdal/wiki/UserDocs/GdalWarp#GeoTIFFoutput-coCOMPRESSisbroken

2) There's no real convenient well supported way to have proper transparency and
JPEG compression. You could try setting nodata, but due to JPEG compression, you'll
have artifacts at the border between the area with valid pixels and the padding.
Another option would be to convert from RGBA to RGB+mask with
gdal_translate in_rgba.tif out_rgb_with_mask.tif -co compress=jpeg -co photometric=ycbcr -b 1 -b 2 -b 3 -mask 4 --config GDAL_TIFF_INTERNAL_MASK YES
so as to have JPEG compression for RGB and a DEFLATE compressed mask. But
masks such like that that are not alpha bands are not widely supported outside of
GDAL itself (MapServer supports that). This may be workarounded by using a VRT though.
See 
http://download.osgeo.org/gdal/workshop/foss4ge2015/workshop_gdal.html#__RefHeading__5975_1333016408


Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list