[QGIS-Developer] Create plain table (without geometry) in gpkg?
Julien Cabieces
julien.cabieces at oslandia.com
Wed Jun 24 08:28:40 PDT 2020
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.cabieces at 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.
More information about the QGIS-Developer
mailing list