[Qgis-user] Create new geopackage layer
Andrea Giudiceandrea
andreaerdna at libero.it
Thu Jul 28 11:20:59 PDT 2022
Il 28/07/2022 18:32, Andrea Giudiceandrea ha scritto:
> filepath = "[complete file path and file name and extension (.gpkg)]
> lyrname = "test_layer"
> fields=QgsFields()
> fields.append(QgsField("test_field", QVariant.Double))
> opts = QgsVectorFileWriter.SaveVectorOptions()
> writer = QgsVectorFileWriter.create(filepath, fields,
> QgsWkbTypes.Point, QgsCoordinateReferenceSystem("EPSG:4326"),
> QgsCoordinateTransformContext(), opts)
> del writer
...I forgot to add the layer name to the options...
filepath = "[complete file path and file name and extension (.gpkg)]
lyrname = "test_layer"
fields=QgsFields()
fields.append(QgsField("test_field", QVariant.Double))
opts = QgsVectorFileWriter.SaveVectorOptions()
opts.layerName = lyrname
writer = QgsVectorFileWriter.create(filepath, fields, QgsWkbTypes.Point,
QgsCoordinateReferenceSystem("EPSG:4326"),
QgsCoordinateTransformContext(), opts)
del writer
More information about the Qgis-user
mailing list