Skip to content
Permalink
Browse files

Port gdal tri alg to new API

  • Loading branch information
nyalldawson committed Aug 13, 2017
1 parent ab2886d commit 1cbbbc4b8316bdd951c8b8b7856040e50cb269d3
@@ -35,6 +35,7 @@

from .AssignProjection import AssignProjection
from .aspect import aspect
from .tri import tri
from .warp import warp
# from .nearblack import nearblack
# from .information import information
@@ -56,8 +57,6 @@
# from .gdal2xyz import gdal2xyz
# from .hillshade import hillshade
# from .slope import slope

# from .tri import tri
# from .tpi import tpi
# from .roughness import roughness
# from .ColorRelief import ColorRelief
@@ -145,6 +144,7 @@ def loadAlgorithms(self):
# information(),
AssignProjection(),
aspect(),
tri(),
warp(),
# translate(),
# rgb2pct(),
@@ -164,7 +164,7 @@ def loadAlgorithms(self):
# gdal2xyz(),
# hillshade(),
# slope(),
# tri(),
#
# tpi(),
# roughness(),
# ColorRelief(),
@@ -29,7 +29,7 @@
import os

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterBand,
QgsProcessingParameterBoolean,
QgsProcessingParameterRasterDestination)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@@ -53,8 +53,8 @@ def __init__(self):

def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
self.addParameter(QgsProcessingParameterNumber(
self.BAND, self.tr('Band number'), minValue=1, maxValue=99, defaultValue=1))
self.addParameter(QgsProcessingParameterBand(
self.BAND, self.tr('Band number'), parentLayerParameterName=self.INPUT))
self.addParameter(QgsProcessingParameterBoolean(
self.COMPUTE_EDGES, self.tr('Compute edges'), defaultValue=False))
self.addParameter(QgsProcessingParameterBoolean(self.ZEVENBERGEN,
@@ -29,11 +29,11 @@

import os

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterBoolean,
QgsProcessingParameterRasterDestination)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputRaster
from processing.algs.gdal.GdalUtils import GdalUtils

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
@@ -50,13 +50,13 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer')))
self.addParameter(ParameterNumber(self.BAND,
self.tr('Band number'), 1, 99, 1))
self.addParameter(ParameterBoolean(self.COMPUTE_EDGES,
self.tr('Compute edges'), False))
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
self.addParameter(QgsProcessingParameterBand(self.BAND,
self.tr('Band number'), parentLayerParameterName=self.INPUT))
self.addParameter(QgsProcessingParameterBoolean(self.COMPUTE_EDGES,
self.tr('Compute edges'), defaultValue=False))

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Terrain Ruggedness Index')))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Terrain Ruggedness Index')))

def name(self):
return 'triterrainruggednessindex'
@@ -69,13 +69,15 @@ def group(self):

def getConsoleCommands(self, parameters, context, feedback):
arguments = ['TRI']
arguments.append(str(self.getParameterValue(self.INPUT)))
arguments.append(str(self.getOutputValue(self.OUTPUT)))
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
arguments.append(inLayer.source())
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
arguments.append(out)

arguments.append('-b')
arguments.append(str(self.getParameterValue(self.BAND)))
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))

if self.getParameterValue(self.COMPUTE_EDGES):
if self.parameterAsBool(parameters, self.COMPUTE_EDGES, context):
arguments.append('-compute_edges')

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -482,33 +482,33 @@ tests:
# OUTPUT:
# hash: aba5167b8a2e97a93b22d406e0363f91c151fd353c0fc56ce24ac5fc
# type: rasterhash
#
# - algorithm: gdal:triterrainruggednessindex
# name: standard TRI
# params:
# BAND: 1
# COMPUTE_EDGES: false
# INPUT:
# name: dem.tif
# type: raster
# results:
# OUTPUT:
# hash: c888764a08fae72a129dfff4947149c3185532373d33d4537ecf409c
# type: rasterhash
#
# - algorithm: gdal:triterrainruggednessindex
# name: TRI with edges
# params:
# BAND: 1
# COMPUTE_EDGES: true
# INPUT:
# name: dem.tif
# type: raster
# results:
# OUTPUT:
# hash: 07376c74de869323125ceacbb5e34438655ff73f63d4b3ff3e268f7f
# type: rasterhash
#

- algorithm: gdal:triterrainruggednessindex
name: standard TRI
params:
BAND: 1
COMPUTE_EDGES: false
INPUT:
name: dem.tif
type: raster
results:
OUTPUT:
hash: c888764a08fae72a129dfff4947149c3185532373d33d4537ecf409c
type: rasterhash

- algorithm: gdal:triterrainruggednessindex
name: TRI with edges
params:
BAND: 1
COMPUTE_EDGES: true
INPUT:
name: dem.tif
type: raster
results:
OUTPUT:
hash: 07376c74de869323125ceacbb5e34438655ff73f63d4b3ff3e268f7f
type: rasterhash

# - algorithm: gdal:nearblack
# name: standard near black
# params:

0 comments on commit 1cbbbc4

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