I have many raster tiles (in tif format, SR WGS84) and, since all together are very heavy, I want to unify them in a geopackage.

I've tried to do that in QGIS, performing the following steps:

  1. converting all the raster in PNG format,
  2. creating a geopackage from the Browser panel (Create Database > No geometry)
  3. simply dragging them into the geopackage created ---> Import succesful

but: the original rasters have a single band, while once added to the geopackage they have 4 bands.

Is there a way to create a Geopackage that contains all my raster tiles (about 850 tiles) maintaining only the 1 original band?

  • Could you share some test data?
    – user30184
    Jan 10 '20 at 20:59
  • As per the Tour there should be only one question asked per question.
    – PolyGeo
    Jan 11 '20 at 1:10
  • 1
    @PolyGeo I've edited the question being more focused, could you re-open it, please?
    – chiarar
    Jan 13 '20 at 8:49

Create with your 850 raster tiles a VRT ("Raster" -> "Other" -> "Build Virtual Raster"). Remove the tick from the checkbox "Place each input file into a seperate band". You can leave the other options as they are. Drag & Drop the VRT within QGIS into the Geopackage you prepared - Done

(or rightclick on the VRT, "export as" -> Geopackage )

  • The issue wasn't solved: once created the virtual raster, it has got one single band with original values. But after I export it as geopackage, it contains 4 bands, of which one contains a NoData value, while the other three contain the same value, that I think is an interpolation of neighbouring cells.
    – chiarar
    Feb 10 '20 at 5:51
  • What is the data type of your source data? 8 bit, 16 bit, 32 bit? Feb 10 '20 at 8:23
  • 1
    It is eight-bit unsigned integer. I don't understand why the output raster in the geopackage has different cells values from the input.
    – chiarar
    Feb 10 '20 at 12:46

This is quite easy with gdalwarp (2.4 and newer):

gdalwarp -of GPKG inputfolder\*.tif output.gpkg
gdaladdo -r cubic output.gpkg

If your source data is single band 8 bit grayscale, then the tiles in the GeoPackage will be likewise.

However, the GDAL GeoPackage driver will by default expose a GeoPackage dataset as four bands RGBA. This means that even though your gpkg file contains single band tiles, it will appear to have four bands when opening it in (for instance) gdalinfo or QGIS. To be absolutely sure, you can

  1. Open the GeoPackage in DB browser for SQLite
  2. Open the tile table (named after the file)
  3. Sort by zoom_level
  4. Pick a row from the highest zoom level, save tile_data cell as a jpg.
  5. Inspect the jpg in a GIS or drawing application

The tiles around the edges of the dataset will be 4 band PNG, but all other tiles should be single band 8 bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.