3

My script has a single point input layer that will be processed with some logic to extract just some points.

I'd like to pass these extracted points as input of another algorithm (simple buffer) within the same scripts.

I define the final output as QgsProcessingParameterFeatureSink:

self.addParameter(QgsProcessingParameterFeatureSink(
    self.OUTPUT,
    "Extracted points",
    QgsProcessing.TypeVectorPoint
    )
)

....

   (sink, dest_id) = self.parameterAsSink(
        parameters,
        self.OUTPUT,
        context,
        source.fields(),
        source.wkbType(),
        source.sourceCrs()
    )

running some logic to extract some points:

features = source.getFeatures()
for current, feat in enumerate(features):
    if feat.geometry().asPoint() == maximum:
        sink.addFeature(feat, QgsFeatureSink.FastInsert)

then I'm trying to call the buffer algorithm:

   buffer = processing.run(
        "native:buffer", {
            'INPUT': sink,
            'DISTANCE': distance,
            'SEGMENTS': 5,
            'END_CAP_STYLE': 0,
            'JOIN_STYLE': 0,
            'MITER_LIMIT': 2,
            'DISSOLVE': False,
            'OUTPUT': 'memory:'
        }
    )

but it does not accept the input:

Incorrect parameter value for INPUT
1
  • Is the sink layer a QgsVectorLayer object?
    – artwork21
    Apr 25, 2018 at 16:29

1 Answer 1

3

There's two things you need to fix:

  • Pass dest_id, not the sink as the parameter value, i.e.

param = { 'INPUT': dest_id, 'DISTANCE': distance, 'SEGMENTS':5, 'END_CAP_STYLE':0, 'JOIN_STYLE':0, 'MITER_LIMIT':2, 'DISSOLVE':False, 'OUTPUT':'memory:' }

  • Pass the context and feedback objects to processing.run, so that the child algorithm can access project layers and other objects from the wider context, and can pass feedback messages from the child algorithm (and handle cancelation and progress reports):

buffer = processing.run("native:buffer", param, context=context, feedback=feedback)

4
  • thanks for the answer! But even with dest_id I have the same error. I don't know if the complete script can help: gist.github.com/ghtmtt/54b3253836c3b7aaff910006de091a91
    – matteo
    Apr 25, 2018 at 8:31
  • Try adding a del sink line before running the buffer
    – ndawson
    Apr 25, 2018 at 18:53
  • Updated with correct answer
    – ndawson
    Apr 27, 2018 at 3:43
  • many many thanks @ndawson.. that was exactly what I was missing!
    – matteo
    Apr 27, 2018 at 6:49

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.