Re: Writing raster to GeoPackage layer


Sean Gillies
 

Hi,

Can you tell us how you installed rasterio? If you installed one of the binary wheels from PyPI (which I built), you may be out of luck. I haven't paid any attention to making sure that they have support for geopackage rasters. I hope someone else can report whether they do or do not.

Also note that when you open an existing dataset in r+ mode, all of the keyword arguments you provide will be ignored, so the properties dict you've made in your code is unnecessary.


On Thu, Jun 20, 2019 at 12:48 PM Ryan <code@...> wrote:
I'm trying to add a raster layer to an existing GPKG with rasterio:

properties = {
        'driver':'GPKG',
        'width':array.shape[1],
        'height':array.shape[0],
        'count':1,
        'crs':crs,
        'transform':transform,
        'dtype':np.float32,
        'nodata':-9999,
        'layer':'rasterlayer'}
with rasterio.open('testing.gpkg', 'r+', **properties) as dst_dataset:
    dst_dataset.write(array)

However I get the following error:

Traceback (most recent call last):
  File "rasterio/_base.pyx", line 76, in rasterio._base.get_dataset_driver
  File "rasterio/_err.pyx", line 205, in rasterio._err.exc_wrap_pointer
rasterio._err.CPLE_OpenFailedError: 'testing.gpkg' not recognized as a supported file format.

I can do this with "gdal_translate" so I at least know the GPKG and rasters are all properly formatted:

gdal_translate -of GPKG raster.tiff testing.gpkg -co APPEND_SUBDATASET=YES -co RASTER_TABLE=rasterlayer


Side Question: Is there a way to format code in groups.io? I can't seem to find anything on the edit toolbar :-/



--
Sean Gillies

Join main@rasterio.groups.io to automatically receive all group messages.