[QGIS-Developer] PyQGIS : Creating a Geopackage layer without adding features

René-Luc Dhont rldhont at gmail.com
Thu May 23 00:55:44 PDT 2019


Hi Devs,

I have tested this and it works
from qgis.core import QgsVectorLayer, QgsVectorFileWriter
ml = QgsVectorLayer('Point?field=firstfield:int&field=secondfield:int', 
'test', 'memory')
filename = '/tmp/testing.gpkg'

options = QgsVectorFileWriter.SaveVectorOptions()
options.driverName = 'GPKG'
options.layerName = 'test'
write_result, error_message = 
QgsVectorFileWriter.writeAsVectorFormat(ml,filename,options)
write_result == QgsVectorFileWriter.NoError


René-Luc

Le 23/05/2019 à 09:27, René-Luc Dhont a écrit :
> Hi Dev,
>
> I would like to create a geopackage with multiple layers but without 
> features. I'd like to do the same thing as the 
> QgsNewGeoPackageLayerDialog do but without user interface in python.
>
> I have tested with QgsVectorFileWriter, but the file and layer are not 
> created if add feature is not used.
>
> Do I have to use Python OGR packaging to do so ?
>
> Regards,
> René-Luc



More information about the QGIS-Developer mailing list