On 1/20/2021 5:25 PM, Etienne Trimaille wrote:
Can you try that?

class Renamer(QgsProcessingLayerPostProcessorInterface):
    instance = None

    def postProcessLayer(self, layer, context, feedback):
        layer.setName('DiffLayer')

    @staticmethod
    def create() -> 'Renamer':
        Renamer.instance = Renamer()
        return Renamer.instance


In your processAlgorithm method() :


                context.layerToLoadOnCompletionDetails(
                    data[layer].id()
                ).setPostProcessor(
                    Renamer.create()
                )


That works. Thanks.
I made a small change because I didn't know  what data[layer] was referring to. Instead I used
        context.layerToLoadOnCompletionDetails(self.dest_id).setPostProcessor(Renamer.create())
where self.dest_id is the second value returned from the ParameterAsSink call.

Your solution leads me to conjecture there is either a temporal scoping issue with just using Renamer() in the call to setPostProcessor(), or else it has something to do with how Python passes parameters by object reference. Either way, by the time the postProcessorLayer is called, there's nothing there. This leads to a slightly different solution that is more flexible if there are multiple output layers:
class Renamer (QgsProcessingLayerPostProcessorInterface):
    def __init__(self, layer_name):
        self.name = layer_name
        super().__init__()
       
    def postProcessLayer(self, layer, context, feedback):
        layer.setName(self.name)
       
renamer = Renamer("DiffBuf")

<later in the processAlgorithm method>
context.layerToLoadOnCompletionDetails(self.dest_id).setPostProcessor(renamer)
_______________________________________________
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