Hi, I had the same issue. I had to loop over the output vector layer (child alg) to feed the sink (main alg). Maybe is not the simpliest/shortest/fastest, but it works. Something like that :
o = processing.run( 'qgis:pointsalonglines', params, context=context, feedback=feedback )['OUTPUT'] (sink, dest_id) = self.parameterAsSink( parameters, self.OUTPUT, context, o.fields, o.wkbType(), o.sourceCrs() ) for f in o.getFeatures() sink.addFeature(f) return {'OUTPUT':dest_id} 2018-06-29 9:35 GMT+02:00 Frank Broniewski <ha...@frankbroniewski.com>: > Hi Nyall, > > thanks a ton for your response. I am well know for making things tricky > for myself 😃 > Anyway, my testing-algorithm-script is still not working. It runs through, > but I do not get the expected result loaded into the layer tree. I suppose > it runs through - the output from the 'qgis:pointsalonglines' is a > QgsVectorLayer - but after finishing I get nuthink back. > > Here's my complete script: You'll need a temporary polygon layer in a > projected CRS (I use EPSG:31466) for it to work nicely. Copy & Paste it > into a new script window and run it. I simply don't find the reason why the > point result layer isn't loaded into my layer tree ... > > > from qgis.PyQt.QtCore import QCoreApplication > from qgis.core import (QgsApplication, > QgsProcessing, > QgsFeatureSink, > QgsProcessingAlgorithm, > QgsProcessingParameterFeatureSource, > QgsProcessingParameterNumber, > QgsProcessingParameterFeatureSink) > > import processing > > > class PolygonCenterline(QgsProcessingAlgorithm): > > INPUT = 'INPUT' > DISTANCE = 'DISTANCE' > OUTPUT = 'OUTPUT' > > def tr(self, text): > return QCoreApplication.translate('Processing', text) > > def createInstance(self): > return PolygonCenterline() > > def group(self): > return self.tr('Cartography') > > def groupId(self): > return 'cartography' > > def name(self): > return 'polygoncenterline' > > def displayName(self): > return self.tr('Calculate a polygon centerline') > > def initAlgorithm(self, config=None): > self.addParameter( > QgsProcessingParameterFeatureSource( > self.INPUT, > self.tr('Vector Polygon Layer'), > [QgsProcessing.TypeVectorPolygon] > ) > ) > > self.addParameter( > QgsProcessingParameterNumber( > self.DISTANCE, > self.tr('Point distance value'), > type=QgsProcessingParameterNumber.Double, > minValue=10.0 > ) > ) > > self.addParameter( > QgsProcessingParameterFeatureSink( > self.OUTPUT, > self.tr('Center line') > ) > ) > > 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} > > > > > -----Ursprüngliche Nachricht----- > Von: Nyall Dawson <nyall.daw...@gmail.com> > Gesendet: Freitag, 29. Juni 2018 01:04 > An: Frank Broniewski <ha...@frankbroniewski.com> > Cc: qgis-user <qgis-user@lists.osgeo.org> > Betreff: Re: [Qgis-user] QGIS 3 Processing question > > On Fri, 29 Jun 2018 at 07:14, Frank Broniewski <ha...@frankbroniewski.com> > wrote: > > > > def processAlgorithm(self, parameters, context, feedback): > > > You're making this tricky for yourself! Cut out everything in > processAlgorithm related to self.INPUT, and just pass the parameter value > direct to the child algorithm to handle: > > > params = { > > > > 'INPUT': parameters[self.INPUT], > > > > 'DISTANCE': pt_value, > > > > 'START_OFFSET': 0, > > > > 'END_OFFSET': 0, > > > > 'OUTPUT': 'memory:' > > > > } > > > Nyall > > _______________________________________________ > Qgis-user mailing list > Qgis-user@lists.osgeo.org > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user >
_______________________________________________ Qgis-user mailing list Qgis-user@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user