Julien, > I was looking to create an empty GPKG layer and try the solution Even > provide, but it creates an invalid file. > > fields=QgsFields() > fields.append(QgsField("note", QVariant.Double)) > QgsVectorFileWriter.create("/tmp/test.gpkg", fields, > QgsWkbTypes.MultiLineString, QgsProject.instance().crs(), > QgsCoordinateTransformContext(), QgsVectorFileWriter.SaveVectorOptions()) > > I try also: > lyr = "mylayer" > QgsVectorFileWriter.create("/tmp/again.gpkg", fields, > QgsWkbTypes.MultiLineString, QgsProject.instance().crs(), > QgsCoordinateTransformContext(), QgsVectorFileWriter.SaveVectorOptions(), > QgsFeatureSink.SinkFlags(), None, lyr) > > It looks like there is no layer in the produced GPKG. Is it an issue, or am > I misunderstanding the use of QgsVectorFileWriter?
The issue is likely QgsVectorFileWriter.SaveVectorOptions() with no driverName set. There's no extension based guessing. Probably that the SaveVectorOptions inner class could have a "GPKG" default value for driverName, as it is the default driver name in other methods of qgsvectorfilewriter.h There are some usage examples of QgsVectorFileWriter in https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgsvectorfilewriter.py (not of create() though) Even -- Spatialys - Geospatial professional services http://www.spatialys.com
_______________________________________________ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer