2013-10-13 14:13:40 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
aspect.py
|
|
|
|
---------------------
|
|
|
|
Date : October 2013
|
|
|
|
Copyright : (C) 2013 by Alexander Bruy
|
|
|
|
Email : alexander dot bruy 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2016-09-21 18:24:26 +02:00
|
|
|
from builtins import str
|
2013-10-13 14:13:40 +03:00
|
|
|
|
|
|
|
__author__ = 'Alexander Bruy'
|
|
|
|
__date__ = 'October 2013'
|
|
|
|
__copyright__ = '(C) 2013, Alexander Bruy'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
import os
|
|
|
|
|
2017-08-31 15:16:44 +03:00
|
|
|
from qgis.core import (QgsRasterFileWriter,
|
|
|
|
QgsProcessingParameterRasterLayer,
|
2017-08-14 05:49:18 +10:00
|
|
|
QgsProcessingParameterBand,
|
2017-08-14 05:05:39 +10:00
|
|
|
QgsProcessingParameterBoolean,
|
|
|
|
QgsProcessingParameterRasterDestination)
|
2014-06-02 00:35:49 +02:00
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2014-04-17 01:41:25 +02:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
2013-10-13 14:13:40 +03:00
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
2013-10-13 14:13:40 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class aspect(GdalAlgorithm):
|
2013-10-13 14:13:40 +03:00
|
|
|
|
|
|
|
INPUT = 'INPUT'
|
|
|
|
BAND = 'BAND'
|
|
|
|
COMPUTE_EDGES = 'COMPUTE_EDGES'
|
|
|
|
ZEVENBERGEN = 'ZEVENBERGEN'
|
|
|
|
TRIG_ANGLE = 'TRIG_ANGLE'
|
|
|
|
ZERO_FLAT = 'ZERO_FLAT'
|
|
|
|
OUTPUT = 'OUTPUT'
|
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2017-06-27 17:20:57 +10:00
|
|
|
|
|
|
|
def initAlgorithm(self, config=None):
|
2017-08-14 05:05:39 +10:00
|
|
|
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
|
2017-08-14 05:49:18 +10:00
|
|
|
self.addParameter(QgsProcessingParameterBand(
|
|
|
|
self.BAND, self.tr('Band number'), parentLayerParameterName=self.INPUT))
|
2017-08-14 05:05:39 +10:00
|
|
|
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.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Aspect')))
|
2013-10-13 14:13:40 +03:00
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def name(self):
|
|
|
|
return 'aspect'
|
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Aspect')
|
|
|
|
|
|
|
|
def group(self):
|
|
|
|
return self.tr('Raster analysis')
|
|
|
|
|
2017-06-27 17:20:57 +10:00
|
|
|
def getConsoleCommands(self, parameters, context, feedback):
|
2013-10-13 14:13:40 +03:00
|
|
|
arguments = ['aspect']
|
2017-08-14 05:05:39 +10:00
|
|
|
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
|
|
|
|
arguments.append(inLayer.source())
|
|
|
|
|
|
|
|
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
|
|
|
arguments.append(out)
|
2014-09-26 07:46:10 +02:00
|
|
|
|
|
|
|
arguments.append('-of')
|
2017-08-31 15:16:44 +03:00
|
|
|
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
|
2013-10-13 14:13:40 +03:00
|
|
|
|
|
|
|
arguments.append('-b')
|
2017-08-14 05:05:39 +10:00
|
|
|
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))
|
2013-10-13 14:13:40 +03:00
|
|
|
|
2017-08-14 05:05:39 +10:00
|
|
|
if self.parameterAsBool(parameters, self.COMPUTE_EDGES, context):
|
2013-10-13 14:13:40 +03:00
|
|
|
arguments.append('-compute_edges')
|
|
|
|
|
2017-08-14 05:05:39 +10:00
|
|
|
if self.parameterAsBool(parameters, self.ZEVENBERGEN, context):
|
2013-10-13 14:13:40 +03:00
|
|
|
arguments.append('-alg')
|
|
|
|
arguments.append('ZevenbergenThorne')
|
|
|
|
|
2017-08-14 05:05:39 +10:00
|
|
|
if self.parameterAsBool(parameters, self.TRIG_ANGLE, context):
|
2013-10-13 14:13:40 +03:00
|
|
|
arguments.append('-trigonometric')
|
|
|
|
|
2017-08-14 05:05:39 +10:00
|
|
|
if self.parameterAsBool(parameters, self.ZERO_FLAT, context):
|
2013-10-13 14:13:40 +03:00
|
|
|
arguments.append('-zero_for_flat')
|
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|