[QGIS-Developer] Processing Plugin - Can a feature sink add additional fields afterwords?

Nyall Dawson nyall.dawson at gmail.com
Sun Nov 4 15:04:59 PST 2018


On Sat, 3 Nov 2018 at 07:27, C Hamilton <adenaculture at gmail.com> wrote:
>
> In my KML Tools processing plugin algorithm I create a feature sink as follows:
>
> (self.sinkPt, self.dest_id_pt) = self.parameterAsSink(self.parameters,
>                 self.PrmPointOutputLayer, self.context, fields,
>                 QgsWkbTypes.Point, epsg4326)
>
> 'fields' is of type QgsFields which are my predefined field names.As I am parsing a KML file, I may find that there is extended field data. Is it possible to add additional fields to my QgsFeatureSink on the fly or do I need to do a first pass through the data to determine all of the possible fields?

It's not possible. It could potentially be added to the QgsFeatureSink
API, but you'd run into problems with some underlying datasources not
having supported for creating attributes anyway. (Not all
providers/file formats allow creation of new fields within existing
layers).

Nyall


More information about the QGIS-Developer mailing list