Feature request #16539

option to skip layer table panel if adding a geopackage to the project using the api

Added by Paul van Genuchten over 3 years ago. Updated over 3 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Data Provider
Pull Request or Patch supplied:No Resolution:
Easy fix?:No Copied to github as #:24445

Description

Currently if you use the api from a python plugin to add a geopackage to the project (as used in https://github.com/pka/qgpkg) a popup is displayed giving the option to select tables to add to the project. This is undesirable, since the plugin at that point already knows which layers it wants to add.

I suggest to extend the geopackage api to expose in the addVectorLayer method an optional parameter "tables" that, if filled, will override the popup and add the selected tables directly.

https://github.com/qgis/QGIS/blob/af236c4ef8303f4ff95f9f0733d25e08659318eb/python/plugins/db_manager/db_plugins/gpkg/plugin.py

QGIS uses ogr to open a geopackage
the plugin is passing the file to GDAL/OGR, who is doing all the work
This is how a file can be opened
.addVectorLayer(gpkg_path, "", "ogr")
it calls a generic vector provider, and passes the OGR driver
for most cases, when you call this function, you get back one layer
But in the case of geopackage you get multiple layers; this is the issue

History

#1 Updated by Alexander Bruy over 3 years ago

  • Tracker changed from Bug report to Feature request

#2 Updated by Paul van Genuchten over 3 years ago

  • Status changed from Open to Closed

hint from @pkalberer
Apparantly this is possible:
.addVectorLayer(gpkg_path + "|layername=" + layername, title, "ogr")
so to add the layername concatenated with |

Also available in: Atom PDF