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

_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to