[Qgis-user] QGIS 3 Processing question

Frank Broniewski hallo at frankbroniewski.com
Tue Jul 3 02:14:14 PDT 2018


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 <nyall.dawson at gmail.com> 
Gesendet: Dienstag, 3. Juli 2018 01:37
An: Frank Broniewski <hallo at frankbroniewski.com>
Cc: qgis-user <qgis-user at lists.osgeo.org>
Betreff: Re: [Qgis-user] QGIS 3 Processing question

On Fri, 29 Jun 2018 at 17:35, Frank Broniewski <hallo at frankbroniewski.com> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5488 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20180703/23cfdd54/attachment.bin>


More information about the Qgis-user mailing list