It works fine for me too, thanks Alessandro! > This works fine for me: > > md = QgsProviderRegistry.instance().providerMetadata('ogr') > conn = md.createConnection('/tmp/test_no_geometry.gpkg', {}) > conn.createVectorTable('', 'my_table', QgsFields(), > QgsWkbTypes.NoGeometry, QgsCoordinateReferenceSystem(), True, {}) > layer = QgsVectorLayer('/tmp/test_no_geometry.gpkg', 'pg', 'ogr') > layer.isValid() --> True > layer.geometryType() --> 4 == NullGeometry > > > On Wed, Jun 24, 2020 at 5:28 PM Julien Cabieces > <julien.cabie...@oslandia.com> wrote: >> >> >> Thanks Alessandro and Even for your replies, >> >> I try your suggestions but I still get the error. I opened an issue >> https://github.com/qgis/QGIS/issues/37386 >> >> Kind regards, >> Julien >> >> >> > On Wed, Jun 24, 2020 at 2:57 PM Julien Cabieces >> > <julien.cabie...@oslandia.com> wrote: >> >> >> >> >> >> Hi alls, >> >> >> >> 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? >> > >> > Hi Julien, >> > >> > I believe you need to add at least one feature to trigger the layer >> > creation (through QgsVectorFileWriter/GDAL). >> > >> > You may try QgsAbstractDatabaseProviderConnection::createVectorTable >> > or QgsProviderRegistry::createEmptyLayer (they both use the same >> > provider's code).. >> > >> > Hope it helps. >>
_______________________________________________ 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