|
28 | 28 | from qgis.core import (QgsProcessingException,
|
29 | 29 | QgsProcessingParameterRasterLayer,
|
30 | 30 | QgsProcessingParameterCrs,
|
31 |
| - QgsProcessingOutputRasterLayer) |
| 31 | + QgsProcessingOutputRasterLayer, |
| 32 | + QgsProcessingContext) |
32 | 33 | from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
33 | 34 | from processing.algs.gdal.GdalUtils import GdalUtils
|
34 | 35 |
|
@@ -97,3 +98,37 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
97 | 98 | self.setOutputValue(self.OUTPUT, fileName)
|
98 | 99 |
|
99 | 100 | return commands
|
| 101 | + |
| 102 | + def postProcessAlgorithm(self, context, feedback): |
| 103 | + # get output value |
| 104 | + fileName = self.output_values.get(self.OUTPUT) |
| 105 | + if not fileName: |
| 106 | + return {} |
| 107 | + |
| 108 | + # search in context project's layers |
| 109 | + if context.project(): |
| 110 | + |
| 111 | + for l in context.project().mapLayers().values(): |
| 112 | + |
| 113 | + # check the source |
| 114 | + if l.source() != fileName: |
| 115 | + continue |
| 116 | + |
| 117 | + # reload provider's data |
| 118 | + l.dataProvider().reloadData() |
| 119 | + l.setCrs(l.dataProvider().crs()) |
| 120 | + l.triggerRepaint() |
| 121 | + |
| 122 | + # search in context temporary layer store |
| 123 | + for l in context.temporaryLayerStore().mapLayers().values(): |
| 124 | + |
| 125 | + # check the source |
| 126 | + if l.source() != fileName: |
| 127 | + continue |
| 128 | + |
| 129 | + # reload provider's data |
| 130 | + l.dataProvider().reloadData() |
| 131 | + l.setCrs(l.dataProvider().crs()) |
| 132 | + context.temporaryLayerStore().addMapLayer(l) |
| 133 | + |
| 134 | + return {} |
0 commit comments