1

Programmatically I have added the vector layers to an existing Geo Package in QGIS 3.2 using python. Similarly, I would like to delete a layer from the existing Geo package using python code. But there is no example/help found in online.

Here is my code to add the selected layers to an existing Geo package:

    layer = self.iface.activeLayer() 
    layer.startEditing()
    gpkgPath='D:/AA/Layer/sample_gpkg'
    options = QgsVectorFileWriter.SaveVectorOptions()
    options.actionOnExistingFile =QgsVectorFileWriter.CreateOrOverwriteLayer   
    options.layerName = 'test'
    _writer=QgsVectorFileWriter.writeAsVectorFormat(layer,gpkgPath,options)

enter image description here

  • There is quite a lot to do when a table is totally and properly dropped from GeoPackage (drop spatial index, drop a bunch of triggers, remove outdated rows from metadata tables, and finally drop the table itself). If QGIS does not have a dedicated method for that (I don't know if it does) the easiest alternative is probably to let GDAL to drop the table with SQL DROP TABLE layer_name as documented in gdal.org/drv_geopackage.html. – user30184 Apr 24 at 18:43

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.