Skip to content

Commit

Permalink
[Processing] Fix GDAL Assign Projection: update QgsRasterLayer crs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rldhont committed Jul 31, 2020
1 parent e19f27d commit 6c44073
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 @@ -97,3 +98,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 6c44073

Please sign in to comment.