Monday, 11 May 2015

Getting the DB name of the spatialite table loaded inside QGIS using PyQGIS


I have a table loaded in QGIS from spatialite DB. When i see the layer properties it is dbname='/home/farook/Spatialite/Cities.sqlite' table="cities" sql=. Now i want the dbname alone (i.e) the entire path '/home/farook/Spatialite/Cities.sqlite' for whatever layer loaded inside QGIS dynamically using PyQGIS. Is there any options for the same?



Answer




These two code statements will provide the table path to the db name:


print iface.activeLayer().dataProvider().dataSourceUri().split('|')[0]

or


print lyr.dataProvider().dataSourceUri().split('|')[0]

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...