[QGIS-Developer] Add a layer using python console - let QGIS figure out which provider to use and what sublayers to load
Jean-Baptiste Peter
jbpeter at outlook.com
Sun Sep 15 04:59:40 PDT 2024
Hello,
I am trying to figure out if there is an easy way to add a layer using python API knowing only the file path of the source dataset. I would like to let QGIS figure out which provider to use and what sublayers to load if it is an archive. A bit like if I was drag dropping a file on the map canvas, but using python API.
I am able to add layers using the following code, but this means that I need to add a lot of custom logic to determine what provider to use, and what sublayer to load in case of archives:
from qgis.core import QgsVectorLayer
layer = QgsVectorLayer(file_path, layer_name)
QgsProject.instance().addMapLayer(layer)
Is there any way to do this with the python API? Thank you!
Best,
Jean-Baptiste PETER
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20240915/e30c72f5/attachment.htm>
More information about the QGIS-Developer
mailing list