I am trying to write a simple script to convert an ESRI geodatabase to a geopackage using gdal/ogr. Here's the example I was using:
from osgeo import ogr
fgdb = r"C:\GIS\data\somefilegeodatabase.gdb"
outdb = r"C:\GIS\data\testdata\OK.gpkg" #Has to be created in advance
fileEncoding = "UTF-8"
driver = ogr.GetDriverByName("OpenFileGDB")
data = driver.Open(fgdb, 0)
#List all layers in the file geodatabase
feature_class_list = []
for i in data:
foo = i.GetName()
feature_class_list.append(foo)
#Write to geopackage
for fc in feature_class_list:
gdbLyr = QgsVectorLayer("{0}|layername={1}".format(fgdb, fc), fc, "ogr")
print('Writing: ', fc)
options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = "GPKG"
options.layerName = fc
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer
options.EditionCapability = 0 #CanAddNewLayer
QgsVectorFileWriter.writeAsVectorFormat(gdbLyr, outdb, options)
Everything works until I get to this line: gdbLyr = QgsVectorLayer("{0}|layername={1}".format(fgdb, fc), fc, "ogr")
. This throws an error: NameError: name 'QgsVectorLayer' is not defined
I've tried importing in QgsVectorLayer directly from osgeo, but that doesn't work. Has this been deprecated or replaced in osgeo
or am I importing it incorrectly?