Skip to content

Commit

Permalink
Merge pull request #5155 from alexbruy/processing-saga
Browse files Browse the repository at this point in the history
[processing] port SAGA to new API
  • Loading branch information
alexbruy committed Nov 10, 2017
2 parents e7a1c04 + bd0b499 commit 019a4d2
Show file tree
Hide file tree
Showing 394 changed files with 3,291 additions and 3,133 deletions.
47 changes: 0 additions & 47 deletions python/plugins/processing/algs/replacer.py

This file was deleted.

386 changes: 214 additions & 172 deletions python/plugins/processing/algs/saga/SagaAlgorithm.py

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions python/plugins/processing/algs/saga/SagaAlgorithmBase.py
@@ -0,0 +1,51 @@
# -*- 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__()

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

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

def tr(self, string):
return QCoreApplication.translate("SAGAAlgorithm", string)
11 changes: 5 additions & 6 deletions python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
Expand Up @@ -16,7 +16,6 @@
* *
***************************************************************************
"""
from builtins import str

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -116,13 +115,13 @@ def name(self):
def id(self):
return 'saga'

def supportedOutputVectorLayerExtensions(self):
return ['shp']
def defaultVectorFileExtension(self, hasGeometry=True):
return 'shp'

def supportedOutputRasterLayerExtensions(self):
return ['sdat']
def defaultRasterFileExtension(self):
return 'sdat'

def getSupportedOutputTableLayerExtensions(self):
def supportedOutputTableExtensions(self):
return ['dbf']

def icon(self):
Expand Down
39 changes: 19 additions & 20 deletions python/plugins/processing/algs/saga/SplitRGBBands.py
Expand Up @@ -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'
Expand All @@ -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 = ""
Expand All @@ -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}
16 changes: 8 additions & 8 deletions python/plugins/processing/algs/saga/description/ANGMAP.txt
@@ -1,10 +1,10 @@
ANGMAP
ta_slope_stability
ParameterRaster|DEM|Elevation|False
ParameterRaster|C|Dip grid (degrees)|True
ParameterRaster|D|Dip direction grid (degrees)|True
ParameterNumber|fB|Global structure dip (degrees)|None|None| 45.000000
ParameterNumber|fC|Global structure dip direction (degrees)|None|None| 90.000000
OutputRaster|E|Angle
OutputRaster|F|CL dipdir
OutputRaster|G|CL dip
QgsProcessingParameterRasterLayer|DEM|Elevation|None|False
QgsProcessingParameterRasterLayer|C|Dip grid (degrees)|None|True
QgsProcessingParameterRasterLayer|D|Dip direction grid (degrees)|None|True
QgsProcessingParameterNumber|fB|Global structure dip (degrees)|QgsProcessingParameterNumber.Double|45.000000|False|None|None
QgsProcessingParameterNumber|fC|Global structure dip direction (degrees)|QgsProcessingParameterNumber.Double|90.000000|False|None|None
QgsProcessingParameterRasterDestination|E|Angle
QgsProcessingParameterRasterDestination|F|CL dipdir
QgsProcessingParameterRasterDestination|G|CL dip
@@ -1,8 +1,8 @@
Accumulated Cost (Anisotropic)
grid_analysis
ParameterRaster|COST|Cost Grid|False
ParameterRaster|DIRECTION|Direction of max cost|False
ParameterRaster|POINTS|Destination Points|False
ParameterNumber|K|k factor|None|None|1
ParameterNumber|THRESHOLD|Threshold for different route|None|None|0
OutputRaster|ACCCOST|Accumulated Cost
QgsProcessingParameterRasterLayer|COST|Cost Grid|None|False
QgsProcessingParameterRasterLayer|DIRECTION|Direction of max cost|None|False
QgsProcessingParameterRasterLayer|POINTS|Destination Points|None|False
QgsProcessingParameterNumber|K|k factor|QgsProcessingParameterNumber.Integer|1|False|None|None
QgsProcessingParameterNumber|THRESHOLD|Threshold for different route|QgsProcessingParameterNumber.Integer|0|False|None|None
QgsProcessingParameterRasterDestination|ACCCOST|Accumulated Cost
@@ -1,7 +1,7 @@
Accumulated Cost (Isotropic)
grid_analysis
ParameterRaster|COST|Cost Grid|False
ParameterRaster|POINTS|Destination Points|False
ParameterNumber|THRESHOLD|Threshold for different route|None|None|0.0
OutputRaster|ACCCOST|Accumulated Cost
OutputRaster|CLOSESTPT|Closest Point
QgsProcessingParameterRasterLayer|COST|Cost Grid|None|False
QgsProcessingParameterRasterLayer|POINTS|Destination Points|None|False
QgsProcessingParameterNumber|THRESHOLD|Threshold for different route|QgsProcessingParameterNumber.Double|0.0|False|None|None
QgsProcessingParameterRasterDestination|ACCCOST|Accumulated Cost
QgsProcessingParameterRasterDestination|CLOSESTPT|Closest Point
20 changes: 10 additions & 10 deletions python/plugins/processing/algs/saga/description/AccumulatedCost.txt
@@ -1,12 +1,12 @@
Accumulated Cost
grid_analysis
ParameterSelection|DEST_TYPE|Input Type of Destinations|[0] Point;[1] Grid| 0
ParameterVector|DEST_POINTS|Destinations|-1|False
ParameterRaster|DEST_GRID|Destinations|False
ParameterRaster|COST|Local Cost|False
ParameterRaster|DIR_MAXCOST|Direction of Maximum Cost|True
ParameterSelection|DIR_UNIT|Units of Direction|[0] radians;[1] degree| 0
ParameterNumber|DIR_K|K Factor|None|None| 2.000000
OutputRaster|ACCUMULATED|Accumulated Cost
OutputRaster|ALLOCATION|Allocation
ParameterNumber|THRESHOLD|Threshold for different route| 0.000000|None| 0.000000
QgsProcessingParameterEnum|DEST_TYPE|Input Type of Destinations|[0] Point;[1] Grid|False|0
QgsProcessingParameterFeatureSource|DEST_POINTS|Destinations|-1|None|False
QgsProcessingParameterRasterLayer|DEST_GRID|Destinations|None|False
QgsProcessingParameterRasterLayer|COST|Local Cost|None|False
QgsProcessingParameterRasterLayer|DIR_MAXCOST|Direction of Maximum Cost|None|True
QgsProcessingParameterEnum|DIR_UNIT|Units of Direction|[0] radians;[1] degree|False|0
QgsProcessingParameterNumber|DIR_K|K Factor|QgsProcessingParameterNumber.Double|2.000000|False|None|None
QgsProcessingParameterRasterDestination|ACCUMULATED|Accumulated Cost
QgsProcessingParameterRasterDestination|ALLOCATION|Allocation
QgsProcessingParameterNumber|THRESHOLD|Threshold for different route|QgsProcessingParameterNumber.Double|0.000000|False| 0.000000|None
@@ -1,12 +1,12 @@
Accumulation Functions
grid_analysis
ParameterRaster|SURFACE|Surface|False
ParameterRaster|INPUT|Input|False
ParameterRaster|STATE_IN|State t|True
ParameterRaster|CONTROL|Operation Control|True
ParameterRaster|CTRL_LINEAR|Linear Flow Control Grid|True
OutputRaster|FLUX|Flux
OutputRaster|STATE_OUT|State t + 1
ParameterSelection|OPERATION|Operation|[0] accuflux;[1] accucapacityflux / state;[2] accufractionflux / state;[3] accuthresholdflux / state;[4] accutriggerflux / state| 0
ParameterBoolean|LINEAR|Switch to Linear Flow|True
ParameterNumber|THRES_LINEAR|Threshold Linear Flow|None|None| 0.000000
QgsProcessingParameterRasterLayer|SURFACE|Surface|None|False
QgsProcessingParameterRasterLayer|INPUT|Input|None|False
QgsProcessingParameterRasterLayer|STATE_IN|State t|None|True
QgsProcessingParameterRasterLayer|CONTROL|Operation Control|None|True
QgsProcessingParameterRasterLayer|CTRL_LINEAR|Linear Flow Control Grid|None|True
QgsProcessingParameterRasterDestination|FLUX|Flux
QgsProcessingParameterRasterDestination|STATE_OUT|State t + 1
QgsProcessingParameterEnum|OPERATION|Operation|[0] accuflux;[1] accucapacityflux / state;[2] accufractionflux / state;[3] accuthresholdflux / state;[4] accutriggerflux / state|False|0
QgsProcessingParameterBoolean|LINEAR|Switch to Linear Flow|True
QgsProcessingParameterNumber|THRES_LINEAR|Threshold Linear Flow|QgsProcessingParameterNumber.Double|0.000000|False|None|None
@@ -1,4 +1,4 @@
Add Coordinates to points
shapes_points
ParameterVector|INPUT|Points|0|False
OutputVector|OUTPUT|Points with coordinates
QgsProcessingParameterFeatureSource|INPUT|Points|0|None|False
QgsProcessingParameterVectorDestination|OUTPUT|Points with coordinates
@@ -1,7 +1,7 @@
Add Grid Values to Points
shapes_grid
ParameterVector|SHAPES|Points|0|False
ParameterMultipleInput|GRIDS|Grids|3|False
ParameterSelection|INTERPOL|Interpolation|[0] Nearest Neighbor;[1] Bilinear Interpolation;[2] Inverse Distance Interpolation;[3] Bicubic Spline Interpolation;[4] B-Spline Interpolation
OutputVector|RESULT|Result
QgsProcessingParameterFeatureSource|SHAPES|Points|0|None|False
QgsProcessingParameterMultipleLayers|GRIDS|Grids|3|None|False
QgsProcessingParameterEnum|INTERPOL|Interpolation|[0] Nearest Neighbor;[1] Bilinear Interpolation;[2] Inverse Distance Interpolation;[3] Bicubic Spline Interpolation;[4] B-Spline Interpolation
QgsProcessingParameterVectorDestination|RESULT|Result
AllowUnmatching
@@ -1,7 +1,7 @@
Add Grid Values to Shapes
shapes_grid
ParameterVector|SHAPES|Shapes|-1|False
ParameterMultipleInput|GRIDS|Grids|3|False
ParameterSelection|INTERPOL|Interpolation|[0] Nearest Neighbor;[1] Bilinear Interpolation;[2] Inverse Distance Interpolation;[3] Bicubic Spline Interpolation;[4] B-Spline Interpolation
OutputVector|RESULT|Result
QgsProcessingParameterFeatureSource|SHAPES|Shapes|-1|None|False
QgsProcessingParameterMultipleLayers|GRIDS|Grids|3|None|False
QgsProcessingParameterEnum|INTERPOL|Interpolation|[0] Nearest Neighbor;[1] Bilinear Interpolation;[2] Inverse Distance Interpolation;[3] Bicubic Spline Interpolation;[4] B-Spline Interpolation
QgsProcessingParameterVectorDestination|RESULT|Result
AllowUnmatching
@@ -1,6 +1,6 @@
Add Indicator Fields for Categories
table_tools
ParameterTable|TABLE|Table|False
ParameterTable|FIELD|Categories|False
ParameterTable|OUT_TABLE|Output table with field(s) deleted|True
OutputVector|OUT_SHAPES|Output shapes with field(s) deleted
QgsProcessingParameterFeatureSource|TABLE|Table|5|None|False
QgsProcessingParameterFeatureSource|FIELD|Categories|5|None|False
QgsProcessingParameterFeatureSource|OUT_TABLE|Output table with field(s) deleted|5|None|True
QgsProcessingParameterVectorDestination|OUT_SHAPES|Output shapes with field(s) deleted
@@ -1,7 +1,7 @@
Add Point Attributes to Polygons
shapes_polygons
ParameterVector|INPUT|Polygons|2|False
ParameterVector|POINTS|Points|0|False
ParameterTableField|FIELDS|Attributes|POINTS|-1|False
ParameterBoolean|ADD_LOCATION_INFO|Add location info|False
OutputVector|OUTPUT|Result
QgsProcessingParameterFeatureSource|INPUT|Polygons|2|None|False
QgsProcessingParameterFeatureSource|POINTS|Points|0|None|False
QgsProcessingParameterField|FIELDS|Attributes|None|POINTS|-1|False|False
QgsProcessingParameterBoolean|ADD_LOCATION_INFO|Add locPation info|False
QgsProcessingParameterVectorDestination|OUTPUT|Result
@@ -1,6 +1,6 @@
Add Polygon Attributes to Points
shapes_points
ParameterVector|INPUT|Points|0|False
ParameterVector|POLYGONS|Polygons|2|False
ParameterTableField|FIELDS|Attribute|POLYGONS|-1|False
OutputVector|OUTPUT|Result
QgsProcessingParameterFeatureSource|INPUT|Points|0|None|False
QgsProcessingParameterFeatureSource|POLYGONS|Polygons|2|None|False
QgsProcessingParameterField|FIELDS|Attribute|None|POLYGONS|-1|False|False
QgsProcessingParameterVectorDestination|OUTPUT|Result
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/saga/description/Aggregate.txt
@@ -1,5 +1,5 @@
Aggregate
grid_tools
ParameterRaster|INPUT|Grid|False
ParameterNumber|SIZE|Aggregation Size|None|None|3
ParameterSelection|METHOD|Method|[0] Sum;[1] Min;[2] Max
QgsProcessingParameterRasterLayer|INPUT|Grid|None|False
QgsProcessingParameterNumber|SIZE|Aggregation Size|QgsProcessingParameterNumber.Integer|3|False|None|None
QgsProcessingParameterEnum|METHOD|Method|[0] Sum;[1] Min;[2] Max

0 comments on commit 019a4d2

Please sign in to comment.