[Qgis-user] Create new geopackage layer
Andrea Giudiceandrea
andreaerdna at libero.it
Thu Jul 28 09:32:47 PDT 2022
> *Arjun Dongre*adongre at west-inc.com
> <mailto:qgis-user%40lists.osgeo.org?Subject=Re%3A%20%5BQgis-user%5D%20Create%20new%20geopackage%20layer&In-Reply-To=%3CCADjDR2inBnjef%3Do_5868Ln5uXfqicW5HJCT3FBPUmYWpGO8tRA%40mail.gmail.com%3E>
> /Thu Jul 28 08:40:18 PDT 2022/
> ------------------------------------------------------------------------
> Should the driver name be "ogr" or
> "gpkg"? Is there any sort of commit statement that needs to happen after
> creation? Or is creation predicated upon adding features? The only example
> I can find is here:https://github.com/qgis/QGIS/issues/35021.
Hi Arjun,
the driver name is "GPKG". It should not be necessary to specify it,
since it defaults to "GPKG" anyway.
Could you please specify what QGIS version exactly are you using?
Have you tried with a simpler code in the Python console?
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
Please consider that the GeoPackage layer will be completely created
only after the "del writer" instruction.
Best regards.
Andrea Giudiceandrea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220728/152de1c7/attachment.htm>
More information about the Qgis-user
mailing list