I thought QgsProcessingLayerPostProcessorInterface might be a solution to my earlier question about renaming the output layer of Processing script.
I derive a class and overload postProcessLayer:

class Renamer (QgsProcessingLayerPostProcessorInterface):
    def postProcessLayer(self, layer, context, feedback):
        layer.setName('DiffLayer')
        print('Renaming layer in post-processor')


Near the end of my processAlgorithm implementation I add:
details = context.LayerDetails(dest_id,context.project())
details.setPostProcessor(Renamer())

where dest_id is the value returned by parameterAsSink

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.
I'm not sure if I'm setting up the post process wrong, or not fetching the right LayerDetails object.

Any pointer to how this should be used or an example of its use would be appreciated.

Thanks
David

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?
PPS I tried postProcess, but it doesn't appear to get called as far as I can tell. Not sure why.

    def postProcess(self, context, feedback):
        print('Number of layers = ' + str(len(QgsProject.instance().mapLayers())))
        print("PostProcess completed")
        feedback.pushInfo(1)  # This line should generate an error since pushInfo expects a string, but no error is thrown
        return {self.OUTPUT: self.dest_id}

_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to