[gdal-dev] COG and VRT behaviour

Even Rouault even.rouault at spatialys.com
Thu Oct 6 03:02:06 PDT 2022


Le 06/10/2022 à 07:55, thomas bonfort a écrit :
> There are only very specific cases where it would be valid to directly 
> copy overview tiles, namely if both image sizes are an exact power of 
> 2. I'll let Even contradict me if I'm wrong, but I highly doubt that 
> what you are trying to do is possible.

If your input files have the same overview levels and resolution, 
gdalbuildvrt should already build a VRT with the <OverviewList> element 
listing those overview levels

Demo with a file from GDAL autotest suite

$ gdal_translate autotest/gdrivers/data/small_world.tif left.tif -srcwin 
0 0 200 200 -outsize 1024 0 -of COG
$ gdal_translate autotest/gdrivers/data/small_world.tif right.tif 
-srcwin 200 0 200 200 -outsize 1024 0 -of COG
$ gdalbuildvrt out.vrt left.tif right.tif
$ grep Overview out.vrt
   <OverviewList resampling="nearest">2</OverviewList>
$ gdalinfo out.vrt | grep Overview
   Overviews: 1024x512

and that should be useable by the COG driver with -co 
OVERVIEWS=FORCE_USE_EXISTING

Note however that the overview exposed by the VRT is a virtual overview: 
so in the general case, there's no guarantee that the values of the 
pixel exactly match those of the source overview, depending on the 
spatial registration of each VRT source. If you have a nice mosaic of 
adjacent sources with power-of-2 dimensions, then yes, you're in the 
good situation.

But, if you were to produce a JPEG-compressed COG, don't expect 
*lossless* copy of overviews in the case of JPEG compression for target 
overviews: GDAL will get the decompressed values of the JPEG compressed 
overviews of the sources and would re-compress them. In the above 
mentioned perfect case, that could potentially be implemented (like 
"gdal_translate input.jpeg output.tif -co COMPRESS=JPEG" does 
currently), but it isn't and it would be a very specific non-trivial 
code to write.

Even


> regards,
> Thomas
>
> Le jeu. 6 oct. 2022, 05:58, Ian Reese <xycarto at gmail.com> a écrit :
>
>     Hi GDAL,
>
>     Let's say I have two GTiff files in COG format:
>
>     f1.tif
>     f2.tif
>
>     f1.tif and f2.tif are created like so:
>
>     gdal_translate input.tif f1.tif \
>
>     -of COG \
>
>     -co BLOCKSIZE=256 \
>
>     -co COMPRESS=JPEG \
>
>     I can easily create a vrt of these two COGs and get the expected
>     behaviour where the VRT honours the overviews of the f1 and f2 COGs.
>
>     gdalbuildvrt cog.vrt f1.tif f2.tif
>
>     This is my question, is it possible to create a COG Tif from this
>     VRT that copies over the overviews from each COG in the VRT?
>
>     For example something like:
>
>     gdal_translate cog.vrt cog.tif -of COG -co
>     OVERVIEWS=FORCE_USE_EXISTING
>
>     I suspect this may not be possible. My guess is that translate is
>     confused by which overviews to use when creating the single
>     cog.tif? Or that when I created f1.tif and f2.tif I missed a setting?
>
>     I have tried many combinations to get this to work, but I think it
>     might be time to ask the experts. Any insight to this would be
>     greatly appreciated.
>
>     Cheer,
>
>     Ianto
>
>     -- 
>     Ian C Reese
>     https://xycarto.com
>     _______________________________________________
>     gdal-dev mailing list
>     gdal-dev at lists.osgeo.org
>     https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev

-- 
http://www.spatialys.com
My software is free, but my time generally not.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20221006/68589257/attachment-0001.htm>


More information about the gdal-dev mailing list