[gdal-dev] CreateCopy() does not copy overviews of dataset?

Even Rouault even.rouault at spatialys.com
Thu May 16 05:56:44 PDT 2019


On jeudi 16 mai 2019 00:18:47 CDT Matsamentet wrote:
> Hi all!
> 
> I'm trying to do the following using Python: Take a GeoTIFF file as input,
> and build an in-memory GeoPackage. Then build overviews on the GeoPackage,
> and finally writing it out to disk.
> 
> Before the last step, I have confirmed that the dataset contains overviews
> by using GetOverviewCount() on one of its bands. I then use CreateCopy() to
> write the dataset to file, but the file which is written does not contain
> any overviews. Is this the intended behaviour of CreateCopy() ? If so, is
> there another way to go about this?

CreateCopy() generally don't copy overviews present in the source dataset (the 
only exception is the GTiff driver if you use the COPY_SRC_OVERVIEWS=YES 
creation option).

Your use case is just file copying.
Something along the following lines (untested) should work:

gpkg = None # to properly flush data and close the dataset
f = gdal.VSIFOpenL(outputvsimem, 'rb')
data = gdal.VSIFReadL(1, gdal.VSIStatL(outputvsimem).size, f)
gdal.VSIFCloseL(f)
with open(outputfile, 'wb') as f:
	f.write(data)
gdal.Unlink(outputvsimem)

Even

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


More information about the gdal-dev mailing list