SetVectorStyle.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """
  2. ***************************************************************************
  3. SetVectorStyle.py
  4. ---------------------
  5. Date : August 2012
  6. Copyright : (C) 2012 by Victor Olaya
  7. Email : volayaf at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Victor Olaya'
  18. __date__ = 'August 2012'
  19. __copyright__ = '(C) 2012, Victor Olaya'
  20. from qgis.core import (QgsProcessingAlgorithm,
  21. QgsProcessingParameterFile,
  22. QgsProcessingParameterVectorLayer,
  23. QgsProcessingOutputVectorLayer)
  24. from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
  25. class SetVectorStyle(QgisAlgorithm):
  26. INPUT = 'INPUT'
  27. STYLE = 'STYLE'
  28. OUTPUT = 'OUTPUT'
  29. def group(self):
  30. return self.tr('Vector general')
  31. def groupId(self):
  32. return 'vectorgeneral'
  33. def __init__(self):
  34. super().__init__()
  35. def flags(self):
  36. return super().flags() | QgsProcessingAlgorithm.FlagNoThreading | QgsProcessingAlgorithm.FlagDeprecated | QgsProcessingAlgorithm.FlagNotAvailableInStandaloneTool
  37. def initAlgorithm(self, config=None):
  38. self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
  39. self.tr('Vector layer')))
  40. self.addParameter(QgsProcessingParameterFile(self.STYLE,
  41. self.tr('Style file'), extension='qml'))
  42. self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT,
  43. self.tr('Styled')))
  44. def name(self):
  45. return 'setstyleforvectorlayer'
  46. def displayName(self):
  47. return self.tr('Set style for vector layer')
  48. def processAlgorithm(self, parameters, context, feedback):
  49. layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
  50. style = self.parameterAsFile(parameters, self.STYLE, context)
  51. layer.loadNamedStyle(style)
  52. layer.triggerRepaint()
  53. return {self.INPUT: layer}