Skip to main content
1 of 6

adding layer to geopackage

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 get this error :

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

this layer is created by :
layer = QgsVectorLayer("Point", 'layerName', "memory")