Rudi, Nyall,

I tried both your tips on how to solve this puzzle, but both didn't work 
unfortunately. Nyall's tip with the temporary layer store just runs through 
nicely, but nothing gets added to the layer pane after the script finished. 
Rudi's tip changes mostly the vector layer type from memory to a physical 
layer, but does not work as well. I even tried to return the result from the 
processing alg directly with no success: 

return processing.run(
            'qgis:pointsalonglines', 
            params, context=context, feedback=feedback
        )

=> {'OUTPUT': <PyQt5.QtCore.QObject object at 0x000002024290CC18>}

Jean-Baptiste's tip on copying the features over to a new feature sink does 
work though.
I can however use the output from qgis:pointsalonglines without any problem in 
a second processing algorithm without needing to copy the features over to 
another feature sink.

It seems that there's some logic going on that prevents returning other 
processing results. Maybe it has to do with the ownership that's mentioned a 
few times in the docs [1]?



[1] 
https://qgis.org/pyqgis/master/core/Processing/QgsProcessingAlgorithm.html?highlight=parameterassink#qgis.core.QgsProcessingAlgorithm.addParameter



-----Ursprüngliche Nachricht-----
Von: Nyall Dawson <[email protected]> 
Gesendet: Dienstag, 3. Juli 2018 01:37
An: Frank Broniewski <[email protected]>
Cc: qgis-user <[email protected]>
Betreff: Re: [Qgis-user] QGIS 3 Processing question

On Fri, 29 Jun 2018 at 17:35, Frank Broniewski <[email protected]> 
wrote:

>     def processAlgorithm(self, parameters, context, feedback):
>         # qgis:pointsalonglines
>         params = {
>             'INPUT': parameters[self.INPUT],
>             'DISTANCE': parameters[self.DISTANCE],
>             'START_OFFSET': 0,
>             'END_OFFSET': 0,
>             'OUTPUT': 'memory:'
>         }
>         points = processing.run(
>             'qgis:pointsalonglines',
>             params, context=context, feedback=feedback
>         )['OUTPUT']
>
>         return {self.OUTPUT: points}
>

Try:

     def processAlgorithm(self, parameters, context, feedback):
         # qgis:pointsalonglines
         params = {
             'INPUT': parameters[self.INPUT],
             'DISTANCE': parameters[self.DISTANCE],
             'START_OFFSET': 0,
             'END_OFFSET': 0,
             'OUTPUT': 'memory:'
         }
         points = processing.run(
             'qgis:pointsalonglines',
             params, context=context, feedback=feedback
         )['OUTPUT']

        # store result layer in context - this prevents it being deleted and 
cleaned up
        # when processAlgorithm finishes
        context.temporaryLayerStore().addMapLayer(points)

         # return the layer ID in the results dictionary - processing will 
automatically retrieve the corresponding
         # layer from the context when required
         return {self.OUTPUT: points.id()}


Nyall

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to