6

I've got a bunch of geotiffs' that I would like to combine into a single geopackage. Using QGIS, I've only managed to export one layer as a geopackage. I've tried merging the layers and created a virtual layer but then QGIS messes up the colors. The raster files are also arranged in a Arcgis Mosaic dataset (file geodatabase) if that is of any help.

Currently, I do the following (which probably isnt the fastest or most efficient way):

  1. Generate a .txt-file containing the filenames of all the geotiffs (dir /b /s *.tif > list.txt)
  2. Use gdal_merge to merge all the geotiffs from list.txt into one large geotiff (gdal_merge -pct --optfile list.txt -o new_huge_geotiff.tif)
  3. Use gdal_translate to convert my new, huge, geotiff into a geopackage (gdal_translate -of GPKG new_huge_geotiff.tif new_tiny_geopackage.gpkg)
  4. use gdaladdo to build pyramids in my new geopackage, which I guess also could be done in the previous step when creating the geopackage. I'm just such a newbie. (gdaladdo -r cubic -oo tile_format=JPEG new_tiny_geopackage.gpkg 2 4 6 8 16 32 64)

The process of merging all small geotiffs into one huge takes a lot of time - I wish I could just add them all to a geopackage at once. I've tried using --optfile and the generated txt-list but gdal_translate doesnt like that command.

  • Should there be one raster table for each image or would all the geotiffs go to one aggregated table? – user30184 Apr 3 '18 at 14:53
  • Pardon my ignorance, but I guess any of the two would work as long as all the images are combined into one geopackage. I've got a software that reads geopackage but doesnt read geotiff, thats the reason why I want to combine them. – Gustav Apr 3 '18 at 17:12
  • Mess with the colors may mean that you have paletted images which has different palettes. Are your images perhaps topographic maps or alike? – user30184 Apr 3 '18 at 17:33
  • Yeah, it's a topographical map. – Gustav Apr 3 '18 at 17:39
  • In that case it is easier to create a new table for each image, otherwise you must make the palettes fit or convert the images into non-paletted RGB images first. – user30184 Apr 3 '18 at 20:44
8

New raster tables must be added into existing GeoPackage as subdatasets as documented in the GDAL driver manual page http://www.gdal.org/drv_geopackage_raster.html. Have a look at the fifth example

Addition of a new subdataset to an existing GeoPackage, and choose a non default name for the raster table.

gdal_translate -of GPKG new.tif existing.gpkg -co APPEND_SUBDATASET=YES -co RASTER_TABLE=new_table

There is no user interface in QGIS for giving the extra parameters so you must edit the automatically generated gdal_translate command manually. For example if you have an existing GeoPackage "test.gpkg" and you want to add image "Img_Sample.tif" as a new raster table named as "Img_Sample_2" edit the command to look like this:

enter image description here

If you have lots of images to convert i would suggest to forget QGIS and graphical user interface and use gdal_translate directly from command line with a little script.

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.