[gdal-dev] gdal_translate: extracting mask band and its overviews

Even Rouault even.rouault at spatialys.com
Thu Aug 31 10:17:51 PDT 2017


On jeudi 31 août 2017 18:55:54 CEST Emanuele Tajariol wrote:
> Hi,
> 
> I'm trying and extract the single mask band out of a geotiff file using
> gdal_translate.
> The tiff file also contains overviews of mask band, and I'd like to extract
> them as well (In the end of the mail there's a fragment of the input file's
> gdalinfo.)
> 
> The command I'm using is:
> 
> gdal_translate -b mask \
>    --config GDAL_TIFF_INTERNAL_MASK YES \
>    -co COPY_SRC_OVERVIEWS=yes \
>    -co TILED=yes  \
>    -co COMPRESS=DEFLATE   \
>    intput_file.tif output_mask.tif
> 
> Anyway the output file does not contain any overview at all.

Emanuele,

COPY_SRC_OVERVIEWS=YES will only work if you do a "bare" gdal_translate, ie if you use 
only source, target, output format and potentially creation options. Here the -b mask causes 
an intermediate VRT to be created, which no longer exposes the source overviews to the 
output GTiff driver (although this VRT dataset can still use the overviews of the source when 
doing downsampling operations. See below)

However, assuming overview dimensions following a power of 2 suite, you could do:

gdal_translate in.tif temp.tif -b mask
gdal_translate in.tif temp.tif.ovr -b mask -outsize 50% 50% (should extract the overview of 
the mask without actually resampling from full resolution)
gdal_translate in.tif temp.tif.ovr.ovr -b mask -outsize 25% 25%
gdal_translate temp.tif out.tif -co COPY_SRC_OVERVIEWS=yes

or even:

gdal_translate in.tif temp.vrt -b mask -of VRT
gdal_translate in.tif temp.vrt.ovr -b mask -outsize 50% 50% -of VRT
gdal_translate in.tif temp.vrt.ovr.ovr -b mask -outsize 25% 25% -of VRT
gdal_translate temp.vrt out.tif -co COPY_SRC_OVERVIEWS=yes


If you build GDAL from source, there's also the "dumpoverviews" utility that is built and that 
dumps overviews, mask bands and mask band overviews in separate TIFF file.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170831/9d3e47a3/attachment-0001.html>


More information about the gdal-dev mailing list