Skip to main content
5 of 6
edited tags
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

Adding layer to GeoPackage

While running the following code

canvas = qgis.utils.iface.mapCanvas()
layer = canvas.currentLayer()
print(layer.name())
options = QgsVectorFileWriter.SaveVectorOptions()
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer

#options.layerName = "_".join(layer.name().split(' '))
writer = QgsVectorFileWriter.writeAsVectorFormat(layer, "C:/Users/ilyasse2.0/Documents/SQRLAND/hh.gpkg", options)
print(writer)

I got this error:

(2, 'Opening of data source in update mode failed (OGR error: )')

The layer is created by with

layer = QgsVectorLayer("Point", 'layerName', "memory")

I tried to use this solution: Adding layer to GeoPackage using PyQGIS but it is not working for me.