Skip to content
Permalink
Browse files

[Processing] Fix "Set style for raster/vector layer" algorithms.

  • Loading branch information
radosuav committed Jan 16, 2018
1 parent 4b1d98b commit 77a28ddd3c91ef887fe3595a55efc5c690b86da6
@@ -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 77a28dd

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