<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<blockquote type="cite"><b style="color: rgb(0, 0, 0); font-family:
"Times New Roman"; font-size: medium; font-style:
normal; font-variant-ligatures: normal; font-variant-caps:
normal; letter-spacing: normal; orphans: 2; text-align: start;
text-indent: 0px; text-transform: none; white-space: normal;
widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration-thickness: initial; text-decoration-style:
initial; text-decoration-color: initial;">Arjun Dongre</b><span
style="color: rgb(0, 0, 0); font-family: "Times New
Roman"; font-size: medium; font-style: normal;
font-variant-ligatures: normal; font-variant-caps: normal;
font-weight: 400; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
255); text-decoration-thickness: initial; text-decoration-style:
initial; text-decoration-color: initial; display: inline
!important; float: none;"><span> </span></span><a
href="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"
title="[Qgis-user] Create new geopackage layer"
style="font-family: "Times New Roman"; font-size:
medium; font-style: normal; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;">adongre at
west-inc.com</a><br style="color: rgb(0, 0, 0); font-family:
"Times New Roman"; font-size: medium; font-style:
normal; font-variant-ligatures: normal; font-variant-caps:
normal; font-weight: 400; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial;">
<i style="color: rgb(0, 0, 0); font-family: "Times New
Roman"; font-size: medium; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration-thickness: initial; text-decoration-style:
initial; text-decoration-color: initial;">Thu Jul 28 08:40:18
PDT 2022</i><span style="color: rgb(0, 0, 0); font-family:
"Times New Roman"; font-size: medium; font-style:
normal; font-variant-ligatures: normal; font-variant-caps:
normal; font-weight: 400; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; background-color: rgb(255, 255,
255); text-decoration-thickness: initial; text-decoration-style:
initial; text-decoration-color: initial; display: inline
!important; float: none;"></span>
<hr style="color: rgb(0, 0, 0); font-family: "Times New
Roman"; font-size: medium; font-style: normal;
font-variant-ligatures: normal; font-variant-caps: normal;
font-weight: 400; letter-spacing: normal; orphans: 2;
text-align: start; text-indent: 0px; text-transform: none;
white-space: normal; widows: 2; word-spacing: 0px;
-webkit-text-stroke-width: 0px; text-decoration-thickness:
initial; text-decoration-style: initial; text-decoration-color:
initial;">
<pre style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">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: <a href="https://github.com/qgis/QGIS/issues/35021." class="moz-txt-link-freetext">https://github.com/qgis/QGIS/issues/35021.</a>
</pre>
</blockquote>
<br>
Hi Arjun,<br>
the driver name is "GPKG". It should not be necessary to specify it,
since it defaults to "GPKG" anyway.<br>
<br>
Could you please specify what QGIS version exactly are you using?<br>
<br>
Have you tried with a simpler code in the Python console?<br>
<br>
filepath = "[complete file path and file name and extension (.gpkg)]<br>
lyrname = "test_layer"<br>
fields=QgsFields()<br>
fields.append(QgsField("test_field", QVariant.Double))<br>
opts = QgsVectorFileWriter.SaveVectorOptions()<br>
writer = QgsVectorFileWriter.create(filepath, fields,
QgsWkbTypes.Point, QgsCoordinateReferenceSystem("EPSG:4326"),
QgsCoordinateTransformContext(), opts)<br>
del writer<br>
<br>
Please consider that the GeoPackage layer will be completely created
only after the "del writer" instruction.<br>
<br>
Best regards.<br>
<br>
Andrea Giudiceandrea<br>
</body>
</html>