<div dir="ltr"><div>Can you try that?</div><div><br></div><div><pre class="gmail-code gmail-highlight" lang="python"><span id="gmail-LC20" class="gmail-line" lang="python"><span class="gmail-k">class</span> <font face="monospace">Renamer</font><span class="gmail-p">(</span><span class="gmail-n">QgsProcessingLayerPostProcessorInterface</span><span class="gmail-p">):</span></span>
<span id="gmail-LC21" class="gmail-line" lang="python">    <span class="gmail-n">instance</span> <span class="gmail-o">=</span> <span class="gmail-bp">None</span></span>
<span id="gmail-LC22" class="gmail-line" lang="python"></span>
<span id="gmail-LC23" class="gmail-line" lang="python">    <span class="gmail-k">def</span> <span class="gmail-nf">postProcessLayer</span><span class="gmail-p">(</span><span class="gmail-bp">self</span><span class="gmail-p">,</span> <span class="gmail-n">layer</span><span class="gmail-p">,</span> <span class="gmail-n">context</span><span class="gmail-p">,</span> <span class="gmail-n">feedback</span><span class="gmail-p">):</span></span>
<font face="monospace">        layer.setName('DiffLayer')</font>
<span id="gmail-LC28" class="gmail-line" lang="python"></span>
<span id="gmail-LC29" class="gmail-line" lang="python">    <span class="gmail-o">@</span><span class="gmail-nb">staticmethod</span></span>
<span id="gmail-LC30" class="gmail-line" lang="python">    <span class="gmail-k">def</span> <span class="gmail-nf">create</span><span class="gmail-p">()</span> <span class="gmail-o">-></span> <span class="gmail-s">'<font face="monospace">Renamer</font>'</span><span class="gmail-p">:</span></span>
<span id="gmail-LC31" class="gmail-line" lang="python">        <font face="monospace">Renamer</font><span class="gmail-p">.</span><span class="gmail-n">instance</span> <span class="gmail-o">=</span> <font face="monospace">Renamer</font><span class="gmail-p">()</span></span>
<span id="gmail-LC32" class="gmail-line" lang="python">        <span class="gmail-k">return</span> <font face="monospace">Renamer</font><span class="gmail-p">.</span><span class="gmail-n">instance<br><br><br></span></span></pre><pre class="gmail-code gmail-highlight" lang="python"><span style="font-family:arial,sans-serif">In your processAlgorithm method() :</span><span id="gmail-LC32" class="gmail-line" lang="python"><span class="gmail-n"><br><br><br><span id="gmail-LC142" class="gmail-line" lang="python">                <span class="gmail-n">context</span><span class="gmail-p">.</span><span class="gmail-n">layerToLoadOnCompletionDetails</span><span class="gmail-p">(</span></span>
<span id="gmail-LC143" class="gmail-line" lang="python">                    <span class="gmail-n">data</span><span class="gmail-p">[</span><span class="gmail-n">layer</span><span class="gmail-p">].</span><span class="gmail-nb">id</span><span class="gmail-p">()</span></span>
<span id="gmail-LC144" class="gmail-line" lang="python">                <span class="gmail-p">).</span><span class="gmail-n">setPostProcessor</span><span class="gmail-p">(</span></span>
<span id="gmail-LC145" class="gmail-line" lang="python">                    <font face="monospace">Renamer</font><span class="gmail-p"></span><span class="gmail-p">.</span><span class="gmail-n">create</span><span class="gmail-p">()</span></span>
<span id="gmail-LC146" class="gmail-line" lang="python">                <span class="gmail-p">)</span></span>
</span></span>
<br><br></pre></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le jeu. 21 janv. 2021 à 03:14, <<a href="mailto:qgis-user@stripfamily.net">qgis-user@stripfamily.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">
  

    
  
  <div>
    I thought QgsProcessingLayerPostProcessorInterface might be a
    solution to my earlier question about renaming the output layer of
    Processing script. <br>
    I derive a class and overload postProcessLayer:<br>
    <br>
    <blockquote><font face="monospace">class Renamer
        (QgsProcessingLayerPostProcessorInterface):<br>
            def postProcessLayer(self, layer, context, feedback):<br>
                layer.setName('DiffLayer')<br>
                print('Renaming layer in post-processor')</font><br>
      <br>
    </blockquote>
    Near the end of my processAlgorithm implementation I add:<br>
    <blockquote><font face="monospace">details =
        context.LayerDetails(dest_id,context.project())<br>
        details.setPostProcessor(Renamer())</font><br>
    </blockquote>
    where dest_id is the value returned by parameterAsSink<br>
    <br>
    The postProcessLayer method does not appear to run (no output is
    produced by the print statement) and the layer is added, but the
    name is unchanged.<br>
    I'm not sure if I'm setting up the post process wrong, or not
    fetching the right LayerDetails object.<br>
    <br>
    Any pointer to how this should be used or an example of its use
    would be appreciated. <br>
    <br>
    Thanks<br>
    David<br>
    <br>
    PS - I also tried the postProcessAlgorithm of the
    QgsProcessingAlgorithm class, but the layer hasn't been added yet
    when the method is called. I wonder if I'll have the same problem
    with the layer post processor?<br>
    PPS I tried postProcess, but it doesn't appear to get called as far
    as I can tell. Not sure why.<br>
    <br>
    <blockquote><font face="monospace">    def postProcess(self,
        context, feedback):<br>
                print('Number of layers = ' +
        str(len(QgsProject.instance().mapLayers())))<br>
                print("PostProcess completed")<br>
                feedback.pushInfo(1)  # This line should generate an
        error since pushInfo expects a string, but no error is thrown<br>
                return {self.OUTPUT: self.dest_id}</font><br>
    </blockquote>
  </div>

_______________________________________________<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>