Skip to content

Commit 571a5ca

Browse files
nyalldawsonalexbruy
authored andcommitted
Start bringing back saga algs - split RGB bands
1 parent d00efde commit 571a5ca

File tree

4 files changed

+74
-68
lines changed

4 files changed

+74
-68
lines changed

python/plugins/processing/algs/replacer.py

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
SagaAlgorithmBase.py
6+
---------------------
7+
Date : August 2017
8+
Copyright : (C) 2017 by Nyall Dawson
9+
Email : nyall dot dawson 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__ = 'Nyall Dawson'
21+
__date__ = 'August 2017'
22+
__copyright__ = '(C) 2017, Nyall Dawson'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
30+
from qgis.PyQt.QtCore import QCoreApplication
31+
from qgis.PyQt.QtGui import QIcon
32+
from qgis.core import QgsProcessingAlgorithm
33+
34+
35+
pluginPath = os.path.normpath(os.path.join(
36+
os.path.split(os.path.dirname(__file__))[0], os.pardir))
37+
38+
39+
class SagaAlgorithmBase(QgsProcessingAlgorithm):
40+
41+
def __init__(self):
42+
super().__init__()
43+
self.output_values = {}
44+
45+
def icon(self):
46+
return QIcon(os.path.join(pluginPath, 'images', 'saga.png'))
47+
48+
def createInstance(self, config={}):
49+
return self.__class__()
50+
51+
def tr(self, string, context=''):
52+
if context == '':
53+
context = self.__class__.__name__
54+
return QCoreApplication.translate(context, string)

python/plugins/processing/algs/saga/SplitRGBBands.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,32 @@
2626
__revision__ = '$Format:%H$'
2727

2828
import os
29-
from qgis.PyQt.QtGui import QIcon
30-
from processing.core.GeoAlgorithm import GeoAlgorithm
31-
from processing.core.parameters import ParameterRaster
32-
from processing.core.outputs import OutputRaster
29+
from qgis.core import (QgsProcessingParameterRasterLayer,
30+
QgsProcessingParameterRasterDestination)
3331
from processing.tools.system import getTempFilename
3432
from . import SagaUtils
33+
from .SagaAlgorithmBase import SagaAlgorithmBase
3534

3635
pluginPath = os.path.normpath(os.path.join(
3736
os.path.split(os.path.dirname(__file__))[0], os.pardir))
3837

3938

40-
class SplitRGBBands(GeoAlgorithm):
39+
class SplitRGBBands(SagaAlgorithmBase):
4140

4241
INPUT = 'INPUT'
4342
R = 'R'
4443
G = 'G'
4544
B = 'B'
4645

47-
def icon(self):
48-
return QIcon(os.path.join(pluginPath, 'images', 'saga.png'))
49-
5046
def __init__(self):
5147
super().__init__()
52-
self.addParameter(ParameterRaster(SplitRGBBands.INPUT,
53-
self.tr('Input layer'), False))
54-
self.addOutput(OutputRaster(SplitRGBBands.R,
55-
self.tr('Output R band layer')))
56-
self.addOutput(OutputRaster(SplitRGBBands.G,
57-
self.tr('Output G band layer')))
58-
self.addOutput(OutputRaster(SplitRGBBands.B,
59-
self.tr('Output B band layer')))
48+
49+
def initAlgorithm(self, config=None):
50+
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
51+
52+
self.addParameter(QgsProcessingParameterRasterDestination(self.R, self.tr('Output R band layer')))
53+
self.addParameter(QgsProcessingParameterRasterDestination(self.G, self.tr('Output G band layer')))
54+
self.addParameter(QgsProcessingParameterRasterDestination(self.B, self.tr('Output B band layer')))
6055

6156
def name(self):
6257
return 'splitrgbbands'
@@ -69,17 +64,19 @@ def group(self):
6964

7065
def processAlgorithm(self, parameters, context, feedback):
7166
# TODO: check correct num of bands
72-
input = self.getParameterValue(SplitRGBBands.INPUT)
67+
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
68+
input = inLayer.source()
7369
temp = getTempFilename(None).replace('.', '')
7470
basename = os.path.basename(temp)
7571
validChars = \
7672
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
7773
safeBasename = ''.join(c for c in basename if c in validChars)
7874
temp = os.path.join(os.path.dirname(temp), safeBasename)
7975

80-
r = self.getOutputValue(SplitRGBBands.R)
81-
g = self.getOutputValue(SplitRGBBands.G)
82-
b = self.getOutputValue(SplitRGBBands.B)
76+
r = self.parameterAsOutputLayer(parameters, self.R, context)
77+
g = self.parameterAsOutputLayer(parameters, self.G, context)
78+
b = self.parameterAsOutputLayer(parameters, self.B, context)
79+
8380
commands = []
8481
version = SagaUtils.getInstalledVersion(True)
8582
trailing = ""
@@ -95,3 +92,5 @@ def processAlgorithm(self, parameters, context, feedback):
9592

9693
SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
9794
SagaUtils.executeSaga(feedback)
95+
96+
return {self.R: r, self.G: g, self.B: b}

python/plugins/processing/core/Processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
5757
from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider
5858
from processing.algs.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider # NOQA
59-
#from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # NOQA
59+
from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # NOQA
6060
from processing.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider # NOQA
6161
#from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider # NOQA
6262

0 commit comments

Comments
 (0)