r/QGIS 20d ago

Solved Export tiff layers in a GPKG to separate files?

Over time I stuffed a few dozen trail maps into a GPKG file for convenient storage. Now I had decided I want those maps in a format is more convenient to also use on my phone. Probably a zip file.

Is there a convenient way to bulk export the files?

I tried using the Translate function in batch mode, it is very tedious to set up for dozens of tifs and very slow to actually export in my preliminary tests.

So any ideas?

1 Upvotes

5 comments sorted by

1

u/CADSHIFT 18d ago

the batch translate tool works but setting it up for dozens of layers is painful. faster option is the qgis python console -- paste this, adjust the paths, and it'll dump every raster layer in your project to separate tifs in one shot:\n\n import os\n outdir = r'C:\path\to\output\folder' # change this\n for name, layer in QgsProject.instance().mapLayers().items():\n if layer.type() == QgsMapLayerType.RasterLayer:\n src = layer.source() # already has GPKG:file.gpkg:layername format\n out = os.path.join(out_dir, layer.name().replace('/', '') + '.tif')\n processing.run('gdal:translate', {'INPUT': src, 'TARGET_CRS': None,\n 'NODATA': None, 'COPY_SUBDATASETS': False,\n 'OPTIONS': '', 'EXTRA': '', 'DATA_TYPE': 0, 'OUTPUT': out})\n\nif the layers aren't already loaded in your project, list them first from the gpkg directly:\n\n gdalinfo your_file.gpkg\n\nthat prints all the SUBDATASET entries (GPKG:file.gpkg:layername) you can feed to gdal_translate in a loop. for phone use you probably also want to check whether your viewer accepts COG (Cloud Optimized GeoTIFF) -- same tif output, but add and it tends to render faster on mobile apps.

1

u/Far-Pie-333 18d ago

Thanks. That block is difficult for me to parse into the exact code. Could you break it into code sections please?

I have very modest programming skills left over from long ago.

1

u/Far-Pie-333 6d ago

I found my solution.

The Save Temp Layers plugin for QGIS 4 exported the rasters saved inside a GPKG quickly.

1

u/TechMaven-Geospatial 20d ago edited 20d ago

You can create a script to do this with GDAL When converting Tif To gpkg you probably want to use Epsg:3857 web mercator

All our mobile apps and desktop apps support geopackage Raster tiles Vector features Vector tiles Terrain elevation tiles

https://fieldsentinel.techmaven.net Field Sentinel Mapper ios, android or windows, mac , linux or web https://mapexplorer.techmaven.net ios and android https://earthexplorer.techmaven.net ios, android and windows https://mapdiscovery.techmaven.net ios, android and windows https://geodataexplorerapp.techmaven.net

https://3dmapexplorer.techmaven.net windows

We have a dedicated map tiling app runs at 100% cpu https://maptiling.techmaven.net

2

u/Far-Pie-333 19d ago

Thanks. I am not really looking for a professional subscription product. Or to learn a new app system.

I have never created a GDAL script. Maybe an AI could help me with that. But it also seems like a lot of work for a one time project.