Skip to content

Commit 6c44073

Browse files
committedJul 31, 2020
[Processing] Fix GDAL Assign Projection: update QgsRasterLayer crs
Even if the projection is assign, the QgsRasterLayer and the QgsRasterDataProvider was not updated. The fix reloads the QgsRasterDataProvider's data and updates the QgsRasterLayer's crs. Fixed #37920
1 parent e19f27d commit 6c44073

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed
 

‎python/plugins/processing/algs/gdal/AssignProjection.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
from qgis.core import (QgsProcessingException,
2929
QgsProcessingParameterRasterLayer,
3030
QgsProcessingParameterCrs,
31-
QgsProcessingOutputRasterLayer)
31+
QgsProcessingOutputRasterLayer,
32+
QgsProcessingContext)
3233
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
3334
from processing.algs.gdal.GdalUtils import GdalUtils
3435

@@ -97,3 +98,37 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
9798
self.setOutputValue(self.OUTPUT, fileName)
9899

99100
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

Comments
 (0)
Please sign in to comment.