<div dir="ltr"><div>You can output a QgsVectorLayer : <a href="https://qgis.org/api/classQgsProcessingOutputVectorLayer.html">https://qgis.org/api/classQgsProcessingOutputVectorLayer.html</a></div><div>The sink is not required and you would avoid a loop to insert all features.<br></div><div><br></div><div>I think you should also return sink ID or layer ID, not the object itself.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 24 août 2021 à 14:01, Richard Duivenvoorde <<a href="mailto:rdmailings@duif.net">rdmailings@duif.net</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 8/24/21 12:57 PM, Andrew Hughes wrote:<br>
> Hi All,<br>
> <br>
> I am trying to create a python script that takes a URL as input and creates/outputs an ArcGIS Feature Service Vector Layer (used for further processing downstream). However,  I believe I am doing something wrong with how I am trying to return the layer.<br>
> <br>
> The script in question can be found here:<br>
> <br>
> <a href="https://github.com/ahhughes/pyqgisorama/blob/main/CreateArcGISFeatureLayer.py#L132" rel="noreferrer" target="_blank">https://github.com/ahhughes/pyqgisorama/blob/main/CreateArcGISFeatureLayer.py#L132</a> <<a href="https://github.com/ahhughes/pyqgisorama/blob/main/CreateArcGISFeatureLayer.py#L132" rel="noreferrer" target="_blank">https://github.com/ahhughes/pyqgisorama/blob/main/CreateArcGISFeatureLayer.py#L132</a>><br>
<br>
Hi Andrew,<br>
<br>
I'm not so experienced either in writing algorithms, but if I am right, you are not supposed to return a layer, but you need to return a 'sink' as it is possible that it will be used as input for another algorithm.<br>
So I used:<br>
self.parameterAsSink<br>
<br>
Note there is also:<br>
self.parameterAsFileOutput<br>
<br>
Did some googling with 'pyqgis layer sink output' and came up with this (and the rest of your GIST):<br>
<br>
<br>
    def processAlgorithm(self, parameters, context, feedback):<br>
        """<br>
        Here is where the processing itself takes place.<br>
        """<br>
<br>
        url = parameters[self.INPUT].strip()<br>
<br>
        #out = self.parameterAsFileOutput(parameters, self.OUTPUT, context)<br>
<br>
        lyr = QgsVectorLayer("crs='EPSG:3857' url='"+url+"'", "RT",  "arcgisfeatureserver")<br>
<br>
        feedback.pushInfo("Layer has been created: "+str(lyr))<br>
        feedback.pushInfo("Is the layer valid?: "+str(lyr.isValid()))<br>
<br>
        (sink, dest_id) = self.parameterAsSink(<br>
            parameters,<br>
            self.OUTPUT,<br>
            context,<br>
            lyr.fields(),<br>
            lyr.wkbType(),<br>
            lyr.sourceCrs()<br>
        )<br>
<br>
        for f in lyr.getFeatures():<br>
            sink.addFeature(f)<br>
<br>
        return {self.OUTPUT: sink}<br>
<br>
<br>
Which at least for me loads some lines :-)<br>
<br>
I hope that others can maybe more context about the differences between parameterAsSink and parameterAsFileOutput.<br>
If not, this would be maybe more a question for the dev list?<br>
<br>
Regards,<br>
<br>
Richard Duivenvoorde<br>
<br>
_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
</blockquote></div>