Skip to content

Commit 1cbbb8a

Browse files
committedAug 13, 2017
Port gdal aspect alg to new API
1 parent 2e7db48 commit 1cbbb8a

File tree

4 files changed

+119
-117
lines changed

4 files changed

+119
-117
lines changed
 

‎python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
from processing.core.ProcessingConfig import ProcessingConfig, Setting
3434
from .GdalUtils import GdalUtils
3535

36+
from .aspect import aspect
37+
from .warp import warp
3638
# from .nearblack import nearblack
3739
# from .information import information
38-
from .warp import warp
3940
# from .rgb2pct import rgb2pct
4041
# from .translate import translate
4142
# from .pct2rgb import pct2rgb
@@ -54,7 +55,7 @@
5455
# from .gdal2xyz import gdal2xyz
5556
# from .hillshade import hillshade
5657
# from .slope import slope
57-
# from .aspect import aspect
58+
5859
# from .tri import tri
5960
# from .tpi import tpi
6061
# from .roughness import roughness
@@ -70,12 +71,13 @@
7071
# from .gdal2tiles import gdal2tiles
7172
# from .AssignProjection import AssignProjection
7273
#
74+
from .ogr2ogrpointsonlines import Ogr2OgrPointsOnLines
75+
from .ogr2ogrtopostgis import Ogr2OgrToPostGis
76+
7377
# from .ogr2ogr import Ogr2Ogr
7478
# from .ogr2ogrclip import Ogr2OgrClip
7579
# from .ogr2ogrclipextent import Ogr2OgrClipExtent
76-
# from .ogr2ogrtopostgis import Ogr2OgrToPostGis
7780
# from .ogr2ogrtopostgislist import Ogr2OgrToPostGisList
78-
from .ogr2ogrpointsonlines import Ogr2OgrPointsOnLines
7981
# from .ogr2ogrbuffer import Ogr2OgrBuffer
8082
# from .ogr2ogrdissolve import Ogr2OgrDissolve
8183
# from .onesidebuffer import OneSideBuffer
@@ -141,6 +143,7 @@ def loadAlgorithms(self):
141143
self.algs = [
142144
# nearblack(),
143145
# information(),
146+
aspect(),
144147
warp(),
145148
# translate(),
146149
# rgb2pct(),
@@ -160,7 +163,6 @@ def loadAlgorithms(self):
160163
# gdal2xyz(),
161164
# hillshade(),
162165
# slope(),
163-
# aspect(),
164166
# tri(),
165167
# tpi(),
166168
# roughness(),
@@ -176,13 +178,13 @@ def loadAlgorithms(self):
176178
# gdal2tiles(),
177179
# AssignProjection(),
178180
# ----- OGR tools -----
181+
Ogr2OgrPointsOnLines(),
182+
Ogr2OgrToPostGis(),
179183
# OgrInfo(),
180184
# Ogr2Ogr(),
181185
# Ogr2OgrClip(),
182186
# Ogr2OgrClipExtent(),
183-
# Ogr2OgrToPostGis(),
184187
# Ogr2OgrToPostGisList(),
185-
Ogr2OgrPointsOnLines(),
186188
# Ogr2OgrBuffer(),
187189
# Ogr2OgrDissolve(),
188190
# OneSideBuffer(),

‎python/plugins/processing/algs/gdal/aspect.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
import os
3030

31+
from qgis.core import (QgsProcessingParameterRasterLayer,
32+
QgsProcessingParameterNumber,
33+
QgsProcessingParameterBoolean,
34+
QgsProcessingParameterRasterDestination)
3135
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
32-
from processing.core.parameters import ParameterRaster
33-
from processing.core.parameters import ParameterBoolean
34-
from processing.core.parameters import ParameterNumber
35-
from processing.core.outputs import OutputRaster
3636
from processing.algs.gdal.GdalUtils import GdalUtils
3737

3838
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
@@ -52,20 +52,20 @@ def __init__(self):
5252
super().__init__()
5353

5454
def initAlgorithm(self, config=None):
55-
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer')))
56-
self.addParameter(ParameterNumber(
57-
self.BAND, self.tr('Band number'), 1, 99, 1))
58-
self.addParameter(ParameterBoolean(
59-
self.COMPUTE_EDGES, self.tr('Compute edges'), False))
60-
self.addParameter(ParameterBoolean(self.ZEVENBERGEN,
61-
self.tr("Use Zevenbergen&Thorne formula (instead of the Horn's one)"),
62-
False))
63-
self.addParameter(ParameterBoolean(self.TRIG_ANGLE,
64-
self.tr('Return trigonometric angle (instead of azimuth)'), False))
65-
self.addParameter(ParameterBoolean(self.ZERO_FLAT,
66-
self.tr('Return 0 for flat (instead of -9999)'), False))
67-
68-
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Aspect')))
55+
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
56+
self.addParameter(QgsProcessingParameterNumber(
57+
self.BAND, self.tr('Band number'), minValue=1, maxValue=99, defaultValue=1))
58+
self.addParameter(QgsProcessingParameterBoolean(
59+
self.COMPUTE_EDGES, self.tr('Compute edges'), defaultValue=False))
60+
self.addParameter(QgsProcessingParameterBoolean(self.ZEVENBERGEN,
61+
self.tr("Use Zevenbergen&Thorne formula (instead of the Horn's one)"),
62+
defaultValue=False))
63+
self.addParameter(QgsProcessingParameterBoolean(self.TRIG_ANGLE,
64+
self.tr('Return trigonometric angle (instead of azimuth)'), defaultValue=False))
65+
self.addParameter(QgsProcessingParameterBoolean(self.ZERO_FLAT,
66+
self.tr('Return 0 for flat (instead of -9999)'), defaultValue=False))
67+
68+
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Aspect')))
6969

7070
def name(self):
7171
return 'aspect'
@@ -78,27 +78,29 @@ def group(self):
7878

7979
def getConsoleCommands(self, parameters, context, feedback):
8080
arguments = ['aspect']
81-
arguments.append(str(self.getParameterValue(self.INPUT)))
82-
output = str(self.getOutputValue(self.OUTPUT))
83-
arguments.append(output)
81+
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
82+
arguments.append(inLayer.source())
83+
84+
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
85+
arguments.append(out)
8486

8587
arguments.append('-of')
86-
arguments.append(GdalUtils.getFormatShortNameFromFilename(output))
88+
arguments.append(GdalUtils.getFormatShortNameFromFilename(out))
8789

8890
arguments.append('-b')
89-
arguments.append(str(self.getParameterValue(self.BAND)))
91+
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))
9092

91-
if self.getParameterValue(self.COMPUTE_EDGES):
93+
if self.parameterAsBool(parameters, self.COMPUTE_EDGES, context):
9294
arguments.append('-compute_edges')
9395

94-
if self.getParameterValue(self.ZEVENBERGEN):
96+
if self.parameterAsBool(parameters, self.ZEVENBERGEN, context):
9597
arguments.append('-alg')
9698
arguments.append('ZevenbergenThorne')
9799

98-
if self.getParameterValue(self.TRIG_ANGLE):
100+
if self.parameterAsBool(parameters, self.TRIG_ANGLE, context):
99101
arguments.append('-trigonometric')
100102

101-
if self.getParameterValue(self.ZERO_FLAT):
103+
if self.parameterAsBool(parameters, self.ZERO_FLAT, context):
102104
arguments.append('-zero_for_flat')
103105

104106
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]

‎python/plugins/processing/algs/gdal/warp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
QgsProcessingParameterBoolean,
3838
QgsProcessingParameterExtent,
3939
QgsProcessingParameterRasterDestination,
40-
QgsProcessingOutputRasterLayer,
4140
QgsProcessingUtils)
4241
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
4342
from processing.algs.gdal.GdalUtils import GdalUtils
@@ -113,7 +112,6 @@ def initAlgorithm(self, config=None):
113112
self.TYPE, defaultValue=5))
114113

115114
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Reprojected')))
116-
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT, self.tr('Reprojected')))
117115

118116
def name(self):
119117
return 'warpreproject'

‎python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -139,87 +139,87 @@ tests:
139139
# compare:
140140
# geometry:
141141
# precision: 7
142-
#
143-
# - algorithm: gdal:aspect
144-
# name: Aspect with standard parameters
145-
# params:
146-
# BAND: 1
147-
# COMPUTE_EDGES: false
148-
# INPUT:
149-
# name: dem.tif
150-
# type: raster
151-
# TRIG_ANGLE: false
152-
# ZERO_FLAT: false
153-
# ZEVENBERGEN: false
154-
# results:
155-
# OUTPUT:
156-
# hash: 8436df662a44a00762aa29768e5d6ecfaf2d42e9a4da02d8afc6e3f6
157-
# type: rasterhash
158-
#
159-
# - algorithm: gdal:aspect
160-
# name: Aspect without NULL (-9999) values (0 instead)
161-
# params:
162-
# BAND: 1
163-
# COMPUTE_EDGES: false
164-
# INPUT:
165-
# name: dem.tif
166-
# type: raster
167-
# TRIG_ANGLE: false
168-
# ZERO_FLAT: true
169-
# ZEVENBERGEN: false
170-
# results:
171-
# OUTPUT:
172-
# hash: 43cccb440c7febb0095103eee3509b740e9f1bf2b3ad3b8a4c25622e
173-
# type: rasterhash
174-
#
175-
# - algorithm: gdal:aspect
176-
# name: Aspect with trigonometric angle
177-
# params:
178-
# BAND: 1
179-
# COMPUTE_EDGES: false
180-
# INPUT:
181-
# name: dem.tif
182-
# type: raster
183-
# TRIG_ANGLE: true
184-
# ZERO_FLAT: false
185-
# ZEVENBERGEN: false
186-
# results:
187-
# OUTPUT:
188-
# hash: a95e8a09a613b551d3f33dfb4975c430f599dc55f761063ae9529124
189-
# type: rasterhash
190-
#
191-
# - algorithm: gdal:aspect
192-
# name: Aspect zevenbergen
193-
# params:
194-
# BAND: 1
195-
# COMPUTE_EDGES: false
196-
# INPUT:
197-
# name: dem.tif
198-
# type: raster
199-
# TRIG_ANGLE: false
200-
# ZERO_FLAT: false
201-
# ZEVENBERGEN: true
202-
# results:
203-
# OUTPUT:
204-
# hash: 2cd5868b21efbd286f4977795143c89df77ac8976f8bc2a2c4e310d8
205-
# type: rasterhash
206-
#
207-
# - algorithm: gdal:aspect
208-
# name: Aspect with edges
209-
# params:
210-
# BAND: 1
211-
# COMPUTE_EDGES: true
212-
# INPUT:
213-
# name: dem.tif
214-
# type: raster
215-
# TRIG_ANGLE: false
216-
# ZERO_FLAT: false
217-
# ZEVENBERGEN: false
218-
# results:
219-
# OUTPUT:
220-
# hash: d3a354c6e5f207779bb58f9bd23fd89a9f90a77d81aafc661d0ae077
221-
# type: rasterhash
222-
#
142+
143+
- algorithm: gdal:aspect
144+
name: Aspect with standard parameters
145+
params:
146+
BAND: 1
147+
COMPUTE_EDGES: false
148+
INPUT:
149+
name: dem.tif
150+
type: raster
151+
TRIG_ANGLE: false
152+
ZERO_FLAT: false
153+
ZEVENBERGEN: false
154+
results:
155+
OUTPUT:
156+
hash: 8436df662a44a00762aa29768e5d6ecfaf2d42e9a4da02d8afc6e3f6
157+
type: rasterhash
158+
159+
- algorithm: gdal:aspect
160+
name: Aspect without NULL (-9999) values (0 instead)
161+
params:
162+
BAND: 1
163+
COMPUTE_EDGES: false
164+
INPUT:
165+
name: dem.tif
166+
type: raster
167+
TRIG_ANGLE: false
168+
ZERO_FLAT: true
169+
ZEVENBERGEN: false
170+
results:
171+
OUTPUT:
172+
hash: 43cccb440c7febb0095103eee3509b740e9f1bf2b3ad3b8a4c25622e
173+
type: rasterhash
174+
175+
- algorithm: gdal:aspect
176+
name: Aspect with trigonometric angle
177+
params:
178+
BAND: 1
179+
COMPUTE_EDGES: false
180+
INPUT:
181+
name: dem.tif
182+
type: raster
183+
TRIG_ANGLE: true
184+
ZERO_FLAT: false
185+
ZEVENBERGEN: false
186+
results:
187+
OUTPUT:
188+
hash: a95e8a09a613b551d3f33dfb4975c430f599dc55f761063ae9529124
189+
type: rasterhash
190+
191+
- algorithm: gdal:aspect
192+
name: Aspect zevenbergen
193+
params:
194+
BAND: 1
195+
COMPUTE_EDGES: false
196+
INPUT:
197+
name: dem.tif
198+
type: raster
199+
TRIG_ANGLE: false
200+
ZERO_FLAT: false
201+
ZEVENBERGEN: true
202+
results:
203+
OUTPUT:
204+
hash: 2cd5868b21efbd286f4977795143c89df77ac8976f8bc2a2c4e310d8
205+
type: rasterhash
206+
207+
- algorithm: gdal:aspect
208+
name: Aspect with edges
209+
params:
210+
BAND: 1
211+
COMPUTE_EDGES: true
212+
INPUT:
213+
name: dem.tif
214+
type: raster
215+
TRIG_ANGLE: false
216+
ZERO_FLAT: false
217+
ZEVENBERGEN: false
218+
results:
219+
OUTPUT:
220+
hash: d3a354c6e5f207779bb58f9bd23fd89a9f90a77d81aafc661d0ae077
221+
type: rasterhash
222+
223223
# - algorithm: gdal:cliprasterbyextent
224224
# name: Clip raster by extent
225225
# params:

0 commit comments

Comments
 (0)
Please sign in to comment.