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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 16, 2021 at 8:18
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()
)
answered Dec 16, 2021 at 10:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.