Skip to main content
2 of 2
deleted 5 characters in body
Rob Irwin
  • 336
  • 4
  • 7

This code is very similar to what @BERA has posted. The difference is this python code runs in the interactive python console in QGIS (tested on version 3.16.3) to copy all vector layers from an ESRI file geodatabase to a GeoPackage. Interestingly, it also will copy vectors from within Feature Datasets contained in a geodatabase.

gdbPath = r"E:\ESRI_data.gdb"
gpkgPath = r"E:\My_GeoPackage.gpkg"
gdbLayer = QgsVectorLayer(gdbPath,"targ ESRI GeoDatabase","ogr")
subLayers = gdbLayer.dataProvider().subLayers()
for subLayer in subLayers:
    parts = subLayer.split('!!::!!')
    layerName = parts[1]
    geotype = parts[2]
    lpath = r"{}|layername={}".format(gdbPath,layerName)
    olayer = QgsVectorLayer(lpath, layerName, "ogr")
    # set options
    options = QgsVectorFileWriter.SaveVectorOptions()
    options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer
    options.layerName = layerName
    _writer = QgsVectorFileWriter.writeAsVectorFormat(olayer, gpkgPath, options)
    if _writer:
        print(layerName, _writer)
Rob Irwin
  • 336
  • 4
  • 7