Skip to content

Commit

Permalink
[processing] restore TPI algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Oct 11, 2017
1 parent b1ff4d7 commit c9ea889
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py
Expand Up @@ -44,6 +44,7 @@
from .polygonize import polygonize
from .rgb2pct import rgb2pct
from .translate import translate
from .tpi import tpi
from .tri import tri
from .warp import warp

Expand All @@ -59,7 +60,6 @@
# from .extractprojection import ExtractProjection
# from .gdal2xyz import gdal2xyz
# from .slope import slope
# from .tpi import tpi
# from .roughness import roughness
# from .GridInvDist import GridInvDist
# from .GridAverage import GridAverage
Expand Down Expand Up @@ -145,6 +145,7 @@ def loadAlgorithms(self):
polygonize(),
rgb2pct(),
translate(),
tpi(),
tri(),
warp(),
# merge(),
Expand All @@ -159,7 +160,6 @@ def loadAlgorithms(self):
# ExtractProjection(),
# gdal2xyz(),
# slope(),
# tpi(),
# roughness(),
# GridInvDist(),
# GridAverage(),
Expand Down
36 changes: 19 additions & 17 deletions python/plugins/processing/algs/gdal/tpi.py
Expand Up @@ -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]
Expand All @@ -46,36 +46,38 @@ class tpi(GdalAlgorithm):
COMPUTE_EDGES = 'COMPUTE_EDGES'
OUTPUT = 'OUTPUT'

def group(self):
return self.tr('Raster analysis')

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('Topographic Position Index')))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Terrain Ruggedness Index')))

def name(self):
return 'tpitopographicpositionindex'

def displayName(self):
return self.tr('TPI (Topographic Position Index)')

def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self, parameters, context, feedback):
arguments = ['TPI']
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)]
52 changes: 25 additions & 27 deletions python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml
@@ -1,5 +1,3 @@
# See ../README.md for a description of the file format

tests:
- algorithm: gdal:gdalinfo
name: gdalinfo
Expand Down Expand Up @@ -523,31 +521,31 @@ tests:
hash: fff4a08498e93494f3f2cf1a9074451e6fd68341849aedc9e2c45e6a
type: rasterhash

# - algorithm: gdal:tpitopographicpositionindex
# name: standard TPI
# params:
# BAND: 1
# COMPUTE_EDGES: false
# INPUT:
# name: dem.tif
# type: raster
# results:
# OUTPUT:
# hash: 4af1fe42d2a75c92eb9edcad9d77bd6cae958c0212de11e320fad689
# type: rasterhash
#
# - algorithm: gdal:tpitopographicpositionindex
# name: TPI with edges
# params:
# BAND: 1
# COMPUTE_EDGES: true
# INPUT:
# name: dem.tif
# type: raster
# results:
# OUTPUT:
# hash: f468bb08cbede2b606018a7a45a51cc221307a8421a11daefabeac12
# type: rasterhash
- algorithm: gdal:tpitopographicpositionindex
name: standard TPI
params:
BAND: 1
COMPUTE_EDGES: false
INPUT:
name: dem.tif
type: raster
results:
OUTPUT:
hash: 4af1fe42d2a75c92eb9edcad9d77bd6cae958c0212de11e320fad689
type: rasterhash

- algorithm: gdal:tpitopographicpositionindex
name: TPI with edges
params:
BAND: 1
COMPUTE_EDGES: true
INPUT:
name: dem.tif
type: raster
results:
OUTPUT:
hash: f468bb08cbede2b606018a7a45a51cc221307a8421a11daefabeac12
type: rasterhash

- algorithm: gdal:colorrelief
name: Standard Color Relief
Expand Down

0 comments on commit c9ea889

Please sign in to comment.