7

I can access ESRI .GDB data using OSGeo's OGR. The following code gives feature class names embedded in .GDB...

from osgeo import ogr

driver = ogr.GetDriverByName("FileGDB")
data = driver.Open(r"D:\pycharm_development\turkiye_db.gdb", 0)

feature_class_list = []

for i in data:
    foo = i.GetName()
    feature_class_list.append(foo)
    feature_class_list.sort()

print feature_class_list

But I cannot access ESRI .GDB data in PyQGIS environment, unfortunately. PyQGIS works properly in my PC and .SHP files can be loaded successfully...

Is QgsVectorLayer() approach true or should QgsDataSourceURI() class be used to handle that?

P.S. I installed from OSGeo4W 64-bit installer. I'm using PyCharm IDE.

  • Please edit your question to include how/from where you installed both gdal/ogr, and QGIS. – user2856 Dec 21 '14 at 11:27
  • Please post the solution as a separate answer and remove the SOLVED from the question title for consistency with the site format. – ako Dec 22 '14 at 19:25
4

QgsVectorLayer() approach is true. Here is the code which can read field names of a specific feature class in ESRI .GDB:

from qgis.core import *

QgsApplication.setPrefixPath("D:/OSGeo4W64/apps/qgis", True)
QgsApplication.initQgis() 

layer = QgsVectorLayer("D:/pycharm/turkiye_db.gdb|layername=tr_il", "provinces", "ogr")

fields = layer.pendingFields()

for i in range(fields.count()):
    field = fields[i]
    print "Name:%s" % (field.name())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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