mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Port gdal aspect alg to new API
This commit is contained in:
parent
2e7db48d20
commit
1cbbb8a0fb
@ -33,9 +33,10 @@ from qgis.core import (QgsApplication,
|
||||
from processing.core.ProcessingConfig import ProcessingConfig, Setting
|
||||
from .GdalUtils import GdalUtils
|
||||
|
||||
from .aspect import aspect
|
||||
from .warp import warp
|
||||
# from .nearblack import nearblack
|
||||
# from .information import information
|
||||
from .warp import warp
|
||||
# from .rgb2pct import rgb2pct
|
||||
# from .translate import translate
|
||||
# from .pct2rgb import pct2rgb
|
||||
@ -54,7 +55,7 @@ from .warp import warp
|
||||
# from .gdal2xyz import gdal2xyz
|
||||
# from .hillshade import hillshade
|
||||
# from .slope import slope
|
||||
# from .aspect import aspect
|
||||
|
||||
# from .tri import tri
|
||||
# from .tpi import tpi
|
||||
# from .roughness import roughness
|
||||
@ -70,12 +71,13 @@ from .warp import warp
|
||||
# from .gdal2tiles import gdal2tiles
|
||||
# from .AssignProjection import AssignProjection
|
||||
#
|
||||
from .ogr2ogrpointsonlines import Ogr2OgrPointsOnLines
|
||||
from .ogr2ogrtopostgis import Ogr2OgrToPostGis
|
||||
|
||||
# from .ogr2ogr import Ogr2Ogr
|
||||
# from .ogr2ogrclip import Ogr2OgrClip
|
||||
# from .ogr2ogrclipextent import Ogr2OgrClipExtent
|
||||
# from .ogr2ogrtopostgis import Ogr2OgrToPostGis
|
||||
# from .ogr2ogrtopostgislist import Ogr2OgrToPostGisList
|
||||
from .ogr2ogrpointsonlines import Ogr2OgrPointsOnLines
|
||||
# from .ogr2ogrbuffer import Ogr2OgrBuffer
|
||||
# from .ogr2ogrdissolve import Ogr2OgrDissolve
|
||||
# from .onesidebuffer import OneSideBuffer
|
||||
@ -141,6 +143,7 @@ class GdalAlgorithmProvider(QgsProcessingProvider):
|
||||
self.algs = [
|
||||
# nearblack(),
|
||||
# information(),
|
||||
aspect(),
|
||||
warp(),
|
||||
# translate(),
|
||||
# rgb2pct(),
|
||||
@ -160,7 +163,6 @@ class GdalAlgorithmProvider(QgsProcessingProvider):
|
||||
# gdal2xyz(),
|
||||
# hillshade(),
|
||||
# slope(),
|
||||
# aspect(),
|
||||
# tri(),
|
||||
# tpi(),
|
||||
# roughness(),
|
||||
@ -176,13 +178,13 @@ class GdalAlgorithmProvider(QgsProcessingProvider):
|
||||
# gdal2tiles(),
|
||||
# AssignProjection(),
|
||||
# ----- OGR tools -----
|
||||
Ogr2OgrPointsOnLines(),
|
||||
Ogr2OgrToPostGis(),
|
||||
# OgrInfo(),
|
||||
# Ogr2Ogr(),
|
||||
# Ogr2OgrClip(),
|
||||
# Ogr2OgrClipExtent(),
|
||||
# Ogr2OgrToPostGis(),
|
||||
# Ogr2OgrToPostGisList(),
|
||||
Ogr2OgrPointsOnLines(),
|
||||
# Ogr2OgrBuffer(),
|
||||
# Ogr2OgrDissolve(),
|
||||
# OneSideBuffer(),
|
||||
|
@ -28,11 +28,11 @@ __revision__ = '$Format:%H$'
|
||||
|
||||
import os
|
||||
|
||||
from qgis.core import (QgsProcessingParameterRasterLayer,
|
||||
QgsProcessingParameterNumber,
|
||||
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]
|
||||
@ -52,20 +52,20 @@ class aspect(GdalAlgorithm):
|
||||
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(ParameterBoolean(self.ZEVENBERGEN,
|
||||
self.tr("Use Zevenbergen&Thorne formula (instead of the Horn's one)"),
|
||||
False))
|
||||
self.addParameter(ParameterBoolean(self.TRIG_ANGLE,
|
||||
self.tr('Return trigonometric angle (instead of azimuth)'), False))
|
||||
self.addParameter(ParameterBoolean(self.ZERO_FLAT,
|
||||
self.tr('Return 0 for flat (instead of -9999)'), False))
|
||||
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(QgsProcessingParameterBoolean(
|
||||
self.COMPUTE_EDGES, self.tr('Compute edges'), defaultValue=False))
|
||||
self.addParameter(QgsProcessingParameterBoolean(self.ZEVENBERGEN,
|
||||
self.tr("Use Zevenbergen&Thorne formula (instead of the Horn's one)"),
|
||||
defaultValue=False))
|
||||
self.addParameter(QgsProcessingParameterBoolean(self.TRIG_ANGLE,
|
||||
self.tr('Return trigonometric angle (instead of azimuth)'), defaultValue=False))
|
||||
self.addParameter(QgsProcessingParameterBoolean(self.ZERO_FLAT,
|
||||
self.tr('Return 0 for flat (instead of -9999)'), defaultValue=False))
|
||||
|
||||
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Aspect')))
|
||||
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Aspect')))
|
||||
|
||||
def name(self):
|
||||
return 'aspect'
|
||||
@ -78,27 +78,29 @@ class aspect(GdalAlgorithm):
|
||||
|
||||
def getConsoleCommands(self, parameters, context, feedback):
|
||||
arguments = ['aspect']
|
||||
arguments.append(str(self.getParameterValue(self.INPUT)))
|
||||
output = str(self.getOutputValue(self.OUTPUT))
|
||||
arguments.append(output)
|
||||
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
|
||||
arguments.append(inLayer.source())
|
||||
|
||||
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
||||
arguments.append(out)
|
||||
|
||||
arguments.append('-of')
|
||||
arguments.append(GdalUtils.getFormatShortNameFromFilename(output))
|
||||
arguments.append(GdalUtils.getFormatShortNameFromFilename(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')
|
||||
|
||||
if self.getParameterValue(self.ZEVENBERGEN):
|
||||
if self.parameterAsBool(parameters, self.ZEVENBERGEN, context):
|
||||
arguments.append('-alg')
|
||||
arguments.append('ZevenbergenThorne')
|
||||
|
||||
if self.getParameterValue(self.TRIG_ANGLE):
|
||||
if self.parameterAsBool(parameters, self.TRIG_ANGLE, context):
|
||||
arguments.append('-trigonometric')
|
||||
|
||||
if self.getParameterValue(self.ZERO_FLAT):
|
||||
if self.parameterAsBool(parameters, self.ZERO_FLAT, context):
|
||||
arguments.append('-zero_for_flat')
|
||||
|
||||
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -37,7 +37,6 @@ from qgis.core import (QgsProcessingParameterRasterLayer,
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterExtent,
|
||||
QgsProcessingParameterRasterDestination,
|
||||
QgsProcessingOutputRasterLayer,
|
||||
QgsProcessingUtils)
|
||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
@ -113,7 +112,6 @@ class warp(GdalAlgorithm):
|
||||
self.TYPE, defaultValue=5))
|
||||
|
||||
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Reprojected')))
|
||||
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT, self.tr('Reprojected')))
|
||||
|
||||
def name(self):
|
||||
return 'warpreproject'
|
||||
|
@ -139,87 +139,87 @@ tests:
|
||||
# compare:
|
||||
# geometry:
|
||||
# precision: 7
|
||||
#
|
||||
# - algorithm: gdal:aspect
|
||||
# name: Aspect with standard parameters
|
||||
# params:
|
||||
# BAND: 1
|
||||
# COMPUTE_EDGES: false
|
||||
# INPUT:
|
||||
# name: dem.tif
|
||||
# type: raster
|
||||
# TRIG_ANGLE: false
|
||||
# ZERO_FLAT: false
|
||||
# ZEVENBERGEN: false
|
||||
# results:
|
||||
# OUTPUT:
|
||||
# hash: 8436df662a44a00762aa29768e5d6ecfaf2d42e9a4da02d8afc6e3f6
|
||||
# type: rasterhash
|
||||
#
|
||||
# - algorithm: gdal:aspect
|
||||
# name: Aspect without NULL (-9999) values (0 instead)
|
||||
# params:
|
||||
# BAND: 1
|
||||
# COMPUTE_EDGES: false
|
||||
# INPUT:
|
||||
# name: dem.tif
|
||||
# type: raster
|
||||
# TRIG_ANGLE: false
|
||||
# ZERO_FLAT: true
|
||||
# ZEVENBERGEN: false
|
||||
# results:
|
||||
# OUTPUT:
|
||||
# hash: 43cccb440c7febb0095103eee3509b740e9f1bf2b3ad3b8a4c25622e
|
||||
# type: rasterhash
|
||||
#
|
||||
# - algorithm: gdal:aspect
|
||||
# name: Aspect with trigonometric angle
|
||||
# params:
|
||||
# BAND: 1
|
||||
# COMPUTE_EDGES: false
|
||||
# INPUT:
|
||||
# name: dem.tif
|
||||
# type: raster
|
||||
# TRIG_ANGLE: true
|
||||
# ZERO_FLAT: false
|
||||
# ZEVENBERGEN: false
|
||||
# results:
|
||||
# OUTPUT:
|
||||
# hash: a95e8a09a613b551d3f33dfb4975c430f599dc55f761063ae9529124
|
||||
# type: rasterhash
|
||||
#
|
||||
# - algorithm: gdal:aspect
|
||||
# name: Aspect zevenbergen
|
||||
# params:
|
||||
# BAND: 1
|
||||
# COMPUTE_EDGES: false
|
||||
# INPUT:
|
||||
# name: dem.tif
|
||||
# type: raster
|
||||
# TRIG_ANGLE: false
|
||||
# ZERO_FLAT: false
|
||||
# ZEVENBERGEN: true
|
||||
# results:
|
||||
# OUTPUT:
|
||||
# hash: 2cd5868b21efbd286f4977795143c89df77ac8976f8bc2a2c4e310d8
|
||||
# type: rasterhash
|
||||
#
|
||||
# - algorithm: gdal:aspect
|
||||
# name: Aspect with edges
|
||||
# params:
|
||||
# BAND: 1
|
||||
# COMPUTE_EDGES: true
|
||||
# INPUT:
|
||||
# name: dem.tif
|
||||
# type: raster
|
||||
# TRIG_ANGLE: false
|
||||
# ZERO_FLAT: false
|
||||
# ZEVENBERGEN: false
|
||||
# results:
|
||||
# OUTPUT:
|
||||
# hash: d3a354c6e5f207779bb58f9bd23fd89a9f90a77d81aafc661d0ae077
|
||||
# type: rasterhash
|
||||
#
|
||||
|
||||
- algorithm: gdal:aspect
|
||||
name: Aspect with standard parameters
|
||||
params:
|
||||
BAND: 1
|
||||
COMPUTE_EDGES: false
|
||||
INPUT:
|
||||
name: dem.tif
|
||||
type: raster
|
||||
TRIG_ANGLE: false
|
||||
ZERO_FLAT: false
|
||||
ZEVENBERGEN: false
|
||||
results:
|
||||
OUTPUT:
|
||||
hash: 8436df662a44a00762aa29768e5d6ecfaf2d42e9a4da02d8afc6e3f6
|
||||
type: rasterhash
|
||||
|
||||
- algorithm: gdal:aspect
|
||||
name: Aspect without NULL (-9999) values (0 instead)
|
||||
params:
|
||||
BAND: 1
|
||||
COMPUTE_EDGES: false
|
||||
INPUT:
|
||||
name: dem.tif
|
||||
type: raster
|
||||
TRIG_ANGLE: false
|
||||
ZERO_FLAT: true
|
||||
ZEVENBERGEN: false
|
||||
results:
|
||||
OUTPUT:
|
||||
hash: 43cccb440c7febb0095103eee3509b740e9f1bf2b3ad3b8a4c25622e
|
||||
type: rasterhash
|
||||
|
||||
- algorithm: gdal:aspect
|
||||
name: Aspect with trigonometric angle
|
||||
params:
|
||||
BAND: 1
|
||||
COMPUTE_EDGES: false
|
||||
INPUT:
|
||||
name: dem.tif
|
||||
type: raster
|
||||
TRIG_ANGLE: true
|
||||
ZERO_FLAT: false
|
||||
ZEVENBERGEN: false
|
||||
results:
|
||||
OUTPUT:
|
||||
hash: a95e8a09a613b551d3f33dfb4975c430f599dc55f761063ae9529124
|
||||
type: rasterhash
|
||||
|
||||
- algorithm: gdal:aspect
|
||||
name: Aspect zevenbergen
|
||||
params:
|
||||
BAND: 1
|
||||
COMPUTE_EDGES: false
|
||||
INPUT:
|
||||
name: dem.tif
|
||||
type: raster
|
||||
TRIG_ANGLE: false
|
||||
ZERO_FLAT: false
|
||||
ZEVENBERGEN: true
|
||||
results:
|
||||
OUTPUT:
|
||||
hash: 2cd5868b21efbd286f4977795143c89df77ac8976f8bc2a2c4e310d8
|
||||
type: rasterhash
|
||||
|
||||
- algorithm: gdal:aspect
|
||||
name: Aspect with edges
|
||||
params:
|
||||
BAND: 1
|
||||
COMPUTE_EDGES: true
|
||||
INPUT:
|
||||
name: dem.tif
|
||||
type: raster
|
||||
TRIG_ANGLE: false
|
||||
ZERO_FLAT: false
|
||||
ZEVENBERGEN: false
|
||||
results:
|
||||
OUTPUT:
|
||||
hash: d3a354c6e5f207779bb58f9bd23fd89a9f90a77d81aafc661d0ae077
|
||||
type: rasterhash
|
||||
|
||||
# - algorithm: gdal:cliprasterbyextent
|
||||
# name: Clip raster by extent
|
||||
# params:
|
||||
|
Loading…
x
Reference in New Issue
Block a user