Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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

(cherry picked from commit 6c44073)
  • Loading branch information
rldhont authored and nyalldawson committed Aug 15, 2020
1 parent 9975cf0 commit acecc1f
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion python/plugins/processing/algs/gdal/AssignProjection.py
Expand Up @@ -28,7 +28,8 @@
from qgis.core import (QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterCrs,
QgsProcessingOutputRasterLayer)
QgsProcessingOutputRasterLayer,
QgsProcessingContext)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils

Expand Down Expand Up @@ -98,3 +99,37 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
self.setOutputValue(self.OUTPUT, fileName)

return commands

def postProcessAlgorithm(self, context, feedback):
# get output value
fileName = self.output_values.get(self.OUTPUT)
if not fileName:
return {}

# search in context project's layers
if context.project():

for l in context.project().mapLayers().values():

# check the source
if l.source() != fileName:
continue

# reload provider's data
l.dataProvider().reloadData()
l.setCrs(l.dataProvider().crs())
l.triggerRepaint()

# search in context temporary layer store
for l in context.temporaryLayerStore().mapLayers().values():

# check the source
if l.source() != fileName:
continue

# reload provider's data
l.dataProvider().reloadData()
l.setCrs(l.dataProvider().crs())
context.temporaryLayerStore().addMapLayer(l)

return {}

0 comments on commit acecc1f

Please sign in to comment.