Skip to content

Commit

Permalink
[processing] Modified styling algs to work with layer that are not op…
Browse files Browse the repository at this point in the history
…en in qgis
  • Loading branch information
volaya committed Jun 20, 2014
1 parent e8d4732 commit 3c7f5c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
25 changes: 15 additions & 10 deletions python/plugins/processing/algs/qgis/SetRasterStyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

__revision__ = '$Format:%H$'

import os
from PyQt4.QtCore import *
from PyQt4.QtXml import *
from qgis.core import *
Expand All @@ -46,7 +47,7 @@ def defineCharacteristics(self):
self.allowOnlyOpenedLayers = True
self.name = 'Set style for raster layer'
self.group = 'Raster general tools'
self.addParameter(ParameterRaster(self.INPUT, 'Vector layer'))
self.addParameter(ParameterRaster(self.INPUT, 'Raster layer'))
self.addParameter(ParameterFile(self.STYLE,
'Style file', False, False, 'qml'))
self.addOutput(OutputRaster(self.OUTPUT, 'Styled layer', True))
Expand All @@ -56,12 +57,16 @@ def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(filename)

style = self.getParameterValue(self.STYLE)
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()
iface.legendInterface().refreshLayerSymbology(layer)
if layer is None:
dataobjects.load(filename, os.path.basename(filename), style=style)
self.getOutputFromName(self.OUTPUT).open = False
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()
iface.legendInterface().refreshLayerSymbology(layer)
18 changes: 11 additions & 7 deletions python/plugins/processing/algs/qgis/SetVectorStyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

__revision__ = '$Format:%H$'

import os
from PyQt4.QtCore import *
from qgis.core import *
from processing.core.GeoAlgorithm import GeoAlgorithm
Expand All @@ -42,7 +43,7 @@ class SetVectorStyle(GeoAlgorithm):


def defineCharacteristics(self):
self.allowOnlyOpenedLayers = True
#self.allowOnlyOpenedLayers = True
self.name = 'Set style for vector layer'
self.group = 'Vector general tools'
self.addParameter(ParameterVector(self.INPUT, 'Vector layer',
Expand All @@ -51,13 +52,16 @@ def defineCharacteristics(self):
'Style file', False, False, 'qml'))
self.addOutput(OutputVector(self.OUTPUT, 'Styled layer', True))

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

style = self.getParameterValue(self.STYLE)
layer.loadNamedStyle(style)

self.setOutputValue(self.OUTPUT, filename)
iface.mapCanvas().refresh()
iface.legendInterface().refreshLayerSymbology(layer)
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)

0 comments on commit 3c7f5c9

Please sign in to comment.