Skip to content
Permalink
Browse files

Start bringing back saga algs - split RGB bands

  • Loading branch information
nyalldawson authored and alexbruy committed Aug 14, 2017
1 parent d00efde commit 571a5ca5f8735b7e9b7501f51dbcaf4301f7a5cf

This file was deleted.

@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
SagaAlgorithmBase.py
---------------------
Date : August 2017
Copyright : (C) 2017 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Nyall Dawson'
__date__ = 'August 2017'
__copyright__ = '(C) 2017, Nyall Dawson'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os

from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsProcessingAlgorithm


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


class SagaAlgorithmBase(QgsProcessingAlgorithm):

def __init__(self):
super().__init__()
self.output_values = {}

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'saga.png'))

def createInstance(self, config={}):
return self.__class__()

def tr(self, string, context=''):
if context == '':
context = self.__class__.__name__
return QCoreApplication.translate(context, string)
@@ -26,37 +26,32 @@
__revision__ = '$Format:%H$'

import os
from qgis.PyQt.QtGui import QIcon
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.outputs import OutputRaster
from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterRasterDestination)
from processing.tools.system import getTempFilename
from . import SagaUtils
from .SagaAlgorithmBase import SagaAlgorithmBase

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


class SplitRGBBands(GeoAlgorithm):
class SplitRGBBands(SagaAlgorithmBase):

INPUT = 'INPUT'
R = 'R'
G = 'G'
B = 'B'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'saga.png'))

def __init__(self):
super().__init__()
self.addParameter(ParameterRaster(SplitRGBBands.INPUT,
self.tr('Input layer'), False))
self.addOutput(OutputRaster(SplitRGBBands.R,
self.tr('Output R band layer')))
self.addOutput(OutputRaster(SplitRGBBands.G,
self.tr('Output G band layer')))
self.addOutput(OutputRaster(SplitRGBBands.B,
self.tr('Output B band layer')))

def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))

self.addParameter(QgsProcessingParameterRasterDestination(self.R, self.tr('Output R band layer')))
self.addParameter(QgsProcessingParameterRasterDestination(self.G, self.tr('Output G band layer')))
self.addParameter(QgsProcessingParameterRasterDestination(self.B, self.tr('Output B band layer')))

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

def processAlgorithm(self, parameters, context, feedback):
# TODO: check correct num of bands
input = self.getParameterValue(SplitRGBBands.INPUT)
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
input = inLayer.source()
temp = getTempFilename(None).replace('.', '')
basename = os.path.basename(temp)
validChars = \
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
safeBasename = ''.join(c for c in basename if c in validChars)
temp = os.path.join(os.path.dirname(temp), safeBasename)

r = self.getOutputValue(SplitRGBBands.R)
g = self.getOutputValue(SplitRGBBands.G)
b = self.getOutputValue(SplitRGBBands.B)
r = self.parameterAsOutputLayer(parameters, self.R, context)
g = self.parameterAsOutputLayer(parameters, self.G, context)
b = self.parameterAsOutputLayer(parameters, self.B, context)

commands = []
version = SagaUtils.getInstalledVersion(True)
trailing = ""
@@ -95,3 +92,5 @@ def processAlgorithm(self, parameters, context, feedback):

SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
SagaUtils.executeSaga(feedback)

return {self.R: r, self.G: g, self.B: b}
@@ -56,7 +56,7 @@
from processing.algs.qgis.QGISAlgorithmProvider import QGISAlgorithmProvider # NOQA
from processing.algs.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider
from processing.algs.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider # NOQA
#from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # NOQA
from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # NOQA
from processing.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider # NOQA
#from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider # NOQA

0 comments on commit 571a5ca

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