0

I get error message when trying enter few layers to geopackage using PyQGIS 3.6.2.

This is my code:

from qgis.core import   QgsVectorFileWriter 
options = QgsVectorFileWriter.SaveVectorOptions()
options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer  
options.EditionCapability = QgsVectorFileWriter.CanAddNewLayer  
options.onlySelectedFeatures = True 
GpName = 'c:\\qgis_dat\\proj\\proj1' 

for layer in  iface.mapCanvas().layers() :  
    namee = layer.name()  # it can be 'roads' or 'buildings' ...
    options.layerName =  namee    
    _writer = QgsVectorFileWriter.writeAsVectorFormat(layer, GpName, options )
    print (_writer) 
    # print the error's message : 
    #    (2, 'Opening of data source in update mode failed (OGR error: )')  .
    # the geoPackage and layers are not created
  • 1
    @BERA, thanks. I already checked "namee" = "paved_road". it is ok, I understood it will be the name of the layer in geopackage. The error message I get when "print (_writer) " – Arie May 8 at 9:03
  • update your question then, and put the error in line print (_writer) – Fran Raga May 8 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.