[Qgis-developer] open vector data using specific GDAL driver

Even Rouault even.rouault at spatialys.com
Sat Oct 29 03:39:50 PDT 2016


Le samedi 29 octobre 2016 12:30:38, Martin Landa a écrit :
> Hi all,
> 
> I wonder whether it's possible to specify GDAL driver when creating
> QgsVectorLayer instance. The constructor allows passing uri, layer
> name and provider. Is there any way how to specify GDAL driver which
> will be used for opening datasource (let's say that we are working
> with datasource which can be open by two different GDAL drivers).
> 
> composedURI = str(dbPath) + "|layername=" + dbTable
> layer = QgsVectorLayer(composedURI, layerName, 'ogr')
> 
> Something like:
> 
> sqliteDriver = ogr.GetDriverByName('SQLite')
> sqliteDataSource = sqliteDriver.Open(str(dbPath))

No, this is currently not possible this way

You could potentially achieve what you want by calling 

blacklisted_driver = gdal.GetDriverByName('driver_you_dont_want')
blacklisted_driver.Deregister()
layer = QgsVectorLayer(composedURI, layerName, 'ogr')
do all the stuff you need with the layer
blacklisted_driver.Register()

> 
> Thanks, Martin

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the Qgis-developer mailing list