QGIS – Difference Between PostProcessorInterface and postProcessAlgorithm in QGIS

pyqgisqgisqgis-processing

QgsProcessingLayerPostProcessorInterface.postProcessLayer()

vs

QgsProcessingAlgorithm.postProcessAlgorithm()

They both seem to post-process a layer like style it or change its display name. What are the differences and which is the recommended method?

Best Answer

So after reading through multiple docs and answers. This is my understanding:

QgsProcessingAlgorithm.postProcessAlgorithm() You can do anything here related to canvas or not, literally almost anything. This runs first after the processAlgorithm in QgsProcessingAlgorithm. This is the part of QgsProcessingAlgorithm class.

QgsProcessingLayerPostProcessorInterface.postProcessLayer() On the other hand this is not part of the QgsProcessingAlgorithm class and is run after QgsProcessingAlgorithm is completely finished. It does not do anything apart from attaching its postProcessLayer function to the layer on which it was added. (the function is not executed here)

When QGIS natively outputs layers after the algorithm is finished, it will apply the postProcessLayer function as the last step.