1

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?

1 Answer 1

3

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]
2
  • I tried but its prints dbname='/home/farook/Spatialite/Cities.sqlite' table="cities" (geometry) sql= instead of dbname='/home/farook/Spatialite/Cities.sqlite'
    – User123
    Apr 13, 2016 at 5:20
  • For your case you may have to split at the empty space character between Cities.sqlite' and table instead of the pipe character e.g. .split(' ')[0]
    – artwork21
    Apr 13, 2016 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.