[gdal-dev] Working with GeoPackage using python API

Ben Avrahami avrahami.ben at gmail.com
Wed Sep 5 00:45:32 PDT 2018


Hello, I'm trying to use GDAL python API to work with geopackage files, and
I ran into some trouble

First off, when creating a geopackage raster, the created raster is always
4-bands. After running this code:

import ogr, osr, gdal
import numpy as np

dst_path = 'out.gpkg'
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
options = ()
driver = gdal.GetDriverByName('GPKG')
dst_ds = driver.Create(dst_path, 19, 10, 1, options=options)
dst_ds.SetGeoTransform((30, 0.01, 0.0, 30, 0.0, -0.01))
dst_ds.SetProjection(srs.ExportToWkt())
band = dst_ds.GetRasterBand(1)
array = np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1],
[1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1],
[1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1],
[1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1],
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
band.WriteArray(array)
band.FlushCache()
assert dst_ds.RasterCount == 1
del dst_ds


I get a 4-band raster (weirdly enough, with all RGB bands set to the
set value, and the ALPHA set 255)


Second, the API has no mention as to how to work with the geopackage
to save/load multiple raster layers and vector layers simultaneously.

All my attempts at creating a geopackage file with both a raster layer
and a vector layer have failed, either with the vector layer not
appearing or standard errors.


Any help at all would be appreciated, thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20180905/21298c43/attachment.html>


More information about the gdal-dev mailing list