I'm looking for an alternative to import multiple raster files into a GeoPackage other than dragging and dropping via QGIS Browser (sometimes takes to long or returns error).

Following this post I'm using gdal_translate with additional parameters to create a model for exporting a .tif file to an existing GeoPackage without deleting existing tables.

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

However, I have problems naming the table based on the input file name when I try to use the batch process as I can't set up a variable for this on command line.

Is there a better alternative using QGIS? Or maybe another way to manage GeoPackage files.

  • there is a QGIS processing algorithm "package" which can be used also as batch process
    – eurojam
    Commented Aug 6, 2021 at 6:19
  • @eurojam I think it supports only vector files since I get an error when trying to use raster files.
    – geofausto
    Commented Aug 6, 2021 at 15:41

1 Answer 1


Use the option: 'OPTIONS':'APPEND_SUBDATASET=YES|RASTER_TABLE=raster123', change the raster_table name with each iteration:

import os

newgpkg = '/home/bera/Desktop/all_rasters.gpkg' #Will be created if it doesnt exist
rasterfolder = r'/home/bera/Desktop/GIS/Data/testdata/' #All tif rasters in this folder and all subfolders will be converted

for root, folder, files in os.walk(rasterfolder):
    for file in files:
        if file.endswith('.tif'): #For each tif file in rasterfolder
            print('Processing {0}'.format(file))
            fullname = os.path.join(root, file)
            newname = file.replace('.tif', '_trans') #Adjust this line to change how the output rasters are named
            processing.run("gdal:translate", {'INPUT':fullname,'TARGET_CRS':None,'NODATA':None,

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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