Sorry, an error in the code in the previous answer.
Correct code is (writer should be without indentation):
...
def create_blank_gpkg_layer(gpkg_path: str, layer_name: str, geometry: int,
crs: str, fields: QgsFields, append: bool = False
) -> bool:
# To add a layer to an existing GPKG file, pass 'append' as True
options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = "GPKG"
options.layerName = layer_name
if append:
options.actionOnExistingFile =
QgsVectorFileWriter.CreateOrOverwriteLayer
writer = QgsVectorFileWriter.create(
gpkg_path,
fields,
geometry,
QgsCoordinateReferenceSystem(crs),
QgsCoordinateTransformContext(),
options)
del writer
return True
...
Kind regards
Anne
_______________________________________________
QGIS-User mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user