1

I know I can create a (QgsFeatureSink, string) tuple by calling

(sink, dest_id) = self.parameterAsSink(...)

However that requires me to pass an output layer as a parameter:

self.addParameter(
    QgsProcessingParameterFeatureSink(
        self.OUTPUT,
        self.tr('Some output layer'),
        QgsProcessing.TypeVectorPolygon
    )
)

But in a lot of cases, I really don't want this feature layer as an output. I might use it only for temporary processing. For instance I might generate a number of features and then rasterize them and only present the rasterized result to the user.

How can I create a similar sink from code that only resides in memory during the processing of the algorithm, and is not presented to the user?

1

1 Answer 1

2

As per Ben's suggestion, you can use createFeatureSink as a drop-in replacement. The only thing to be aware of, is to use memory: as destination URI. Something that seems to be missing from the official documentation

(sink, dest_id) = QgsProcessingUtils.createFeatureSink(
    'memory:',
    context,
    self.source.fields(),
    self.source.wkbType(),
    self.source.sourceCrs()
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.