|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + SelectByLocation.py |
| 6 | + --------------------- |
| 7 | + Date : August 2012 |
| 8 | + Copyright : (C) 2012 by Victor Olaya |
| 9 | + Email : volayaf at gmail dot com |
| 10 | +*************************************************************************** |
| 11 | +* * |
| 12 | +* This program is free software; you can redistribute it and/or modify * |
| 13 | +* it under the terms of the GNU General Public License as published by * |
| 14 | +* the Free Software Foundation; either version 2 of the License, or * |
| 15 | +* (at your option) any later version. * |
| 16 | +* * |
| 17 | +*************************************************************************** |
| 18 | +""" |
| 19 | + |
| 20 | +__author__ = 'Victor Olaya' |
| 21 | +__date__ = 'August 2012' |
| 22 | +__copyright__ = '(C) 2012, Victor Olaya' |
| 23 | + |
| 24 | +# This will get replaced with a git SHA1 when you do a git archive |
| 25 | + |
| 26 | +__revision__ = '$Format:%H$' |
| 27 | + |
| 28 | +from PyQt4.QtCore import * |
| 29 | +from PyQt4.QtXml import * |
| 30 | +from qgis.core import * |
| 31 | +from processing.core.GeoAlgorithm import GeoAlgorithm |
| 32 | +from processing.parameters.ParameterFile import ParameterFile |
| 33 | +from processing.parameters.ParameterRaster import ParameterRaster |
| 34 | +from processing.outputs.OutputRaster import OutputRaster |
| 35 | +from processing.tools import dataobjects |
| 36 | +from qgis.utils import iface |
| 37 | + |
| 38 | +class SetRasterStyle(GeoAlgorithm): |
| 39 | + |
| 40 | + INPUT = 'INPUT' |
| 41 | + STYLE = 'STYLE' |
| 42 | + OUTPUT = 'OUTPUT' |
| 43 | + |
| 44 | + |
| 45 | + def defineCharacteristics(self): |
| 46 | + self.allowOnlyOpenedLayers = True |
| 47 | + self.name = 'Set style for raster layer' |
| 48 | + self.group = 'Raster general tools' |
| 49 | + self.addParameter(ParameterRaster(self.INPUT, 'Vector layer')) |
| 50 | + self.addParameter(ParameterFile(self.STYLE, |
| 51 | + 'Style file', False, False, 'qml')) |
| 52 | + self.addOutput(OutputRaster(self.OUTPUT, 'Styled layer', True)) |
| 53 | + |
| 54 | + def processAlgorithm(self, progress): |
| 55 | + filename = self.getParameterValue(self.INPUT) |
| 56 | + layer = dataobjects.getObjectFromUri(filename) |
| 57 | + |
| 58 | + style = self.getParameterValue(self.STYLE) |
| 59 | + with open(style) as f: |
| 60 | + xml = "".join(f.readlines()) |
| 61 | + d = QDomDocument(); |
| 62 | + d.setContent(xml); |
| 63 | + n = d.firstChild(); |
| 64 | + layer.readSymbology(n, '') |
| 65 | + self.setOutputValue(self.OUTPUT, filename) |
| 66 | + iface.mapCanvas().refresh() |
| 67 | + iface.legendInterface().refreshLayerSymbology(layer) |
0 commit comments