I have a standalone pyqgis script that uses processing algorithms. The final output is a GPKG layer, and I want to define the name of the FID field (that by default is fid).
The relevant code is something like this:
import processing
processing.run("native:buffer", {
"INPUT": "/data/input.gpkg|layername=input",
"OUTPUT": "/data/output.gpkg",
"DISTANCE": 10,
})
This generates an output.gpkg with a primary key called fid, but I want to use another name.
Using two steps, following the advice of this answer I can get the desired output:
import processing
from qgis.core import QgsProcessing
outputs = {}
outputs["buffer"] = processing.run(
"native:buffer",
{
"INPUT": "/data/input.gpkg|layername=input",
"OUTPUT": QgsProcessing.TEMPORARY_OUTPUT,,
"DISTANCE": 10,
},
)
outputs["savefeatures"] = processing.run(
"native:savefeatures",
{
"INPUT": outputs["buffer"]["OUTPUT"],
"OUTPUT": "/data/output.gpkg",
"LAYER_OPTIONS": "FID=id;",
},
)
But, it will be nice if there is a way to do it in just one step, something like:
`"OUTPUT": "/data/output.gpkg?FID=id"`
that does not work.
-lco FID=idfor GDAL https://gdal.org/drivers/vector/gpkg.html. Unfortunately I do not know how to do it. – user30184 Jul 17 '23 at 14:45