Skip to main content
deleted 5 characters in body
Source Link
Rob Irwin
  • 336
  • 4
  • 7

This is approachcode is very similar to what @BERA has posted. The difference is this python code runs in the interactive python console in QGIS (testtested 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)

This is approach is very similar to what @BERA has posted. The difference is this python code runs in the interactive python console in QGIS (test 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)

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)
Source Link
Rob Irwin
  • 336
  • 4
  • 7

This is approach is very similar to what @BERA has posted. The difference is this python code runs in the interactive python console in QGIS (test 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)