Skip to content
Permalink
Browse files

Restore Set style for vector layer alg

  • Loading branch information
nyalldawson committed Aug 18, 2017
1 parent be48f17 commit cfbc00990b2ad8ce0ad1db37e2b13439b6d0a3e6
@@ -128,6 +128,7 @@
from .ServiceAreaFromLayer import ServiceAreaFromLayer
from .ServiceAreaFromPoint import ServiceAreaFromPoint
from .SetMValue import SetMValue
from .SetVectorStyle import SetVectorStyle
from .SetZValue import SetZValue
from .ShortestPathLayerToPoint import ShortestPathLayerToPoint
from .ShortestPathPointToLayer import ShortestPathPointToLayer
@@ -161,7 +162,6 @@
# from .GeometryConvert import GeometryConvert
# from .FieldsCalculator import FieldsCalculator
# from .FieldPyculator import FieldsPyculator
# from .SetVectorStyle import SetVectorStyle
# from .SetRasterStyle import SetRasterStyle
# from .SelectByAttributeSum import SelectByAttributeSum
# from .Datasources2Vrt import Datasources2Vrt
@@ -192,7 +192,7 @@ def getAlgs(self):
# SpatialJoin(),
# GeometryConvert(), FieldsCalculator(),
# FieldsPyculator(),
# SetVectorStyle(), SetRasterStyle(),
# SetRasterStyle(),
# FieldsMapper(), SelectByAttributeSum(), Datasources2Vrt(),
# DefineProjection(),
# RectanglesOvalsDiamondsVariable(),
@@ -289,6 +289,7 @@ def getAlgs(self):
ServiceAreaFromLayer(),
ServiceAreaFromPoint(),
SetMValue(),
SetVectorStyle(),
SetZValue(),
ShortestPathLayerToPoint(),
ShortestPathPointToLayer(),
@@ -25,14 +25,10 @@

__revision__ = '$Format:%H$'

import os
from qgis.core import (QgsApplication,
QgsProcessingUtils)
from qgis.core import (QgsProcessingParameterFile,
QgsProcessingParameterVectorLayer,
QgsProcessingOutputVectorLayer)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.core.parameters import ParameterFile
from processing.tools import dataobjects


class SetVectorStyle(QgisAlgorithm):
@@ -48,11 +44,12 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterVector(self.INPUT,
self.tr('Vector layer')))
self.addParameter(ParameterFile(self.STYLE,
self.tr('Style file'), False, False, 'qml'))
self.addOutput(OutputVector(self.OUTPUT, self.tr('Styled'), True))
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
self.tr('Vector layer')))
self.addParameter(QgsProcessingParameterFile(self.STYLE,
self.tr('Style file'), extension='qml'))
self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT,
self.tr('Styled')))

def name(self):
return 'setstyleforvectorlayer'
@@ -61,13 +58,8 @@ def displayName(self):
return self.tr('Set style for vector layer')

def processAlgorithm(self, parameters, context, feedback):
filename = self.getParameterValue(self.INPUT)

style = self.getParameterValue(self.STYLE)
layer = QgsProcessingUtils.mapLayerFromString(filename, context, False)
if layer is None:
dataobjects.load(filename, os.path.basename(filename), style=style)
else:
layer.loadNamedStyle(style)
context.addLayerToLoadOnCompletion(layer.id())
layer.triggerRepaint()
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
style = self.parameterAsFile(parameters, self.STYLE, context)
layer.loadNamedStyle(style)
layer.triggerRepaint()
return {self.INPUT: layer}

0 comments on commit cfbc009

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