2016-10-06 19:34:17 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
Aspect.py
|
|
|
|
---------------------
|
|
|
|
Date : October 2016
|
|
|
|
Copyright : (C) 2016 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Alexander Bruy'
|
|
|
|
__date__ = 'October 2016'
|
|
|
|
__copyright__ = '(C) 2016, Alexander Bruy'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2016-10-06 19:42:28 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
from qgis.PyQt.QtGui import QIcon
|
|
|
|
|
2016-10-06 19:34:17 +03:00
|
|
|
from qgis.analysis import QgsAspectFilter
|
2017-06-06 14:39:07 +10:00
|
|
|
from qgis.core import (QgsProcessingParameterRasterLayer,
|
|
|
|
QgsProcessingParameterNumber,
|
|
|
|
QgsProcessingParameterRasterOutput,
|
2017-06-23 14:34:38 +10:00
|
|
|
QgsProcessingOutputRasterLayer,
|
|
|
|
QgsFeatureSink)
|
2017-06-06 14:39:07 +10:00
|
|
|
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
|
2016-10-06 19:34:17 +03:00
|
|
|
from processing.core.parameters import ParameterRaster
|
|
|
|
from processing.core.parameters import ParameterNumber
|
|
|
|
from processing.core.outputs import OutputRaster
|
|
|
|
from processing.tools import raster
|
2017-06-06 14:39:07 +10:00
|
|
|
from processing.tools.dataobjects import exportRasterLayer
|
2016-10-06 19:34:17 +03:00
|
|
|
|
2016-10-06 19:42:28 +03:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
2016-10-06 19:34:17 +03:00
|
|
|
|
2017-05-19 11:27:16 +10:00
|
|
|
class Aspect(QgisAlgorithm):
|
2016-10-06 19:34:17 +03:00
|
|
|
|
2017-06-28 19:55:08 +10:00
|
|
|
INPUT = 'INPUT'
|
2016-10-06 19:34:17 +03:00
|
|
|
Z_FACTOR = 'Z_FACTOR'
|
2017-06-30 12:42:18 +10:00
|
|
|
OUTPUT = 'OUTPUT'
|
2016-10-06 19:34:17 +03:00
|
|
|
|
2017-03-29 10:42:42 +10:00
|
|
|
def icon(self):
|
2016-10-06 19:42:28 +03:00
|
|
|
return QIcon(os.path.join(pluginPath, 'images', 'dem.png'))
|
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Raster terrain analysis')
|
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2017-06-06 14:39:07 +10:00
|
|
|
|
2017-06-28 19:55:08 +10:00
|
|
|
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
|
2017-06-06 14:39:07 +10:00
|
|
|
self.tr('Elevation layer')))
|
|
|
|
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
|
|
|
|
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
|
|
|
|
1, False, 1, 999999.99))
|
2017-06-28 19:55:08 +10:00
|
|
|
self.addParameter(QgsProcessingParameterRasterOutput(self.OUTPUT, self.tr('Aspect')))
|
|
|
|
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT, self.tr('Aspect')))
|
|
|
|
|
|
|
|
self.inputFile = None
|
|
|
|
self.outputFile = None
|
|
|
|
self.outputFormat = None
|
|
|
|
self.zFactor = None
|
2016-10-06 19:34:17 +03:00
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def name(self):
|
|
|
|
return 'aspect'
|
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Aspect')
|
|
|
|
|
2017-06-28 19:55:08 +10:00
|
|
|
def prepareAlgorithm(self, parameters, context, feedback):
|
|
|
|
self.inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT, context))
|
|
|
|
self.zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
|
2017-06-06 14:39:07 +10:00
|
|
|
|
2017-06-28 19:55:08 +10:00
|
|
|
self.outputFile = self.parameterAsRasterOutputLayer(parameters, self.OUTPUT, context)
|
2016-10-06 19:34:17 +03:00
|
|
|
|
2017-06-28 19:55:08 +10:00
|
|
|
self.outputFormat = raster.formatShortNameFromFileName(self.outputFile)
|
|
|
|
return True
|
2016-10-06 19:34:17 +03:00
|
|
|
|
2017-06-28 19:55:08 +10:00
|
|
|
def processAlgorithm(self, context, feedback):
|
|
|
|
aspect = QgsAspectFilter(self.inputFile, self.outputFile, self.outputFormat)
|
|
|
|
aspect.setZFactor(self.zFactor)
|
|
|
|
return aspect.processRaster(feedback) == 0
|
2017-06-06 14:39:07 +10:00
|
|
|
|
2017-06-28 19:55:08 +10:00
|
|
|
def postProcessAlgorithm(self, context, feedback):
|
|
|
|
return {self.OUTPUT: self.outputFile}
|