Skip to content
Permalink
Browse files

Merge pull request #6081 from radosuav/fix_style_algs

[Processing] Fix "Set style for raster/vector layer" algorithms.
  • Loading branch information
m-kuhn committed Jun 19, 2018
2 parents 6d3199f + 77a28dd commit f4e49ddd30379516acceeff3b3259573c7e86c62
@@ -27,8 +27,6 @@

import os

from qgis.PyQt.QtXml import QDomDocument

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterFile
from processing.core.parameters import ParameterRaster
@@ -54,19 +52,14 @@ def defineCharacteristics(self):

def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)
layer = dataobjects.getObjectFromUri(filename)

style = self.getParameterValue(self.STYLE)

dataobjects.resetLoadedLayers()
layer = dataobjects.getObjectFromUri(filename, False)
if layer is None:
dataobjects.load(filename, os.path.basename(filename), style=style)
self.getOutputFromName(self.OUTPUT).open = False
dataobjects.load(filename, os.path.basename(filename), style=style, isRaster=True)
else:
with open(style) as f:
xml = "".join(f.readlines())
d = QDomDocument()
d.setContent(xml)
n = d.firstChild()
layer.readSymbology(n, '')
self.setOutputValue(self.OUTPUT, filename)
iface.mapCanvas().refresh()
layer.loadNamedStyle(style)
layer.triggerRepaint()
iface.legendInterface().refreshLayerSymbology(layer)
self.setOutputValue(self.OUTPUT, filename)
@@ -52,14 +52,14 @@ def defineCharacteristics(self):

def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)

style = self.getParameterValue(self.STYLE)

dataobjects.resetLoadedLayers()
layer = dataobjects.getObjectFromUri(filename, False)
if layer is None:
dataobjects.load(filename, os.path.basename(filename), style=style)
self.getOutputFromName(self.OUTPUT).open = False
else:
layer.loadNamedStyle(style)
iface.mapCanvas().refresh()
iface.legendInterface().refreshLayerSymbology(layer)
layer.triggerRepaint()
iface.legendInterface().refreshLayerSymbology(layer)
self.setOutputValue(self.OUTPUT, filename)

0 comments on commit f4e49dd

Please sign in to comment.
You can’t perform that action at this time.