0

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.

Francisco Puga
  • 4,618
  • 21
  • 40
  • Can you rename it with refactor fields? – BERA Jul 17 '23 at 14:02
  • I know that what should happen is to pass the layer creation option -lco FID=id for GDAL https://gdal.org/drivers/vector/gpkg.html. Unfortunately I do not know how to do it. – user30184 Jul 17 '23 at 14:45
  • Thanks both. I edited my question to explain how can be done i a two step process, and reframe the question a bit. – Francisco Puga Jul 18 '23 at 09:56

0 Answers0