<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
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>
</body>
</html>