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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Matsamentet
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?


This is my code:

---

srcfile = 'input.tif'
outputvsimem = '/vsimem/output.gpkg'

warpoptions = gdal.WarpOptions(format='GPKG',
warpOptions='SKIP_NOSOURCE=YES', \
                                           dstAlpha=False, multithread=True)
gpkg = gdal.Warp(outputvsimem, srcfile, options=warpoptions)

overviews = [2,4,8,16,32,64,128]
gpkg.BuildOverviews('AVERAGE',overviews)

gpkgdriver = gdal.GetDriverByName('GPKG')
outputdataset = gpkgdriver.CreateCopy(outputfile, gpkg, strict=0)

outputdataset = None
gpkg = None
gdal.Unlink(outputvsimem)



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: CreateCopy() does not copy overviews of dataset?

Even Rouault-2
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
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev