2013-10-13 14:36:10 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
roughness.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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Alexander Bruy'
|
|
|
|
__date__ = 'October 2013'
|
|
|
|
__copyright__ = '(C) 2013, Alexander Bruy'
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
import os
|
|
|
|
|
2017-08-31 15:03:33 +03:00
|
|
|
from qgis.core import (QgsRasterFileWriter,
|
2018-05-06 10:29:01 +10:00
|
|
|
QgsProcessingException,
|
2017-09-06 16:59:48 +03:00
|
|
|
QgsProcessingParameterDefinition,
|
2017-08-31 15:03:33 +03:00
|
|
|
QgsProcessingParameterRasterLayer,
|
|
|
|
QgsProcessingParameterBand,
|
2017-09-06 16:59:48 +03:00
|
|
|
QgsProcessingParameterString,
|
2017-08-31 15:03:33 +03: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:36:10 +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:36:10 +03:00
|
|
|
|
2014-06-02 00:35:49 +02:00
|
|
|
class roughness(GdalAlgorithm):
|
2013-10-13 14:36:10 +03:00
|
|
|
|
|
|
|
INPUT = 'INPUT'
|
|
|
|
BAND = 'BAND'
|
|
|
|
COMPUTE_EDGES = 'COMPUTE_EDGES'
|
2017-09-06 16:59:48 +03:00
|
|
|
OPTIONS = 'OPTIONS'
|
2013-10-13 14:36:10 +03:00
|
|
|
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-31 15:03:33 +03:00
|
|
|
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
|
2017-09-06 16:59:48 +03:00
|
|
|
self.addParameter(QgsProcessingParameterBand(self.BAND,
|
|
|
|
self.tr('Band number'),
|
2018-12-30 09:18:23 +02:00
|
|
|
1,
|
2017-09-06 16:59:48 +03:00
|
|
|
parentLayerParameterName=self.INPUT))
|
|
|
|
self.addParameter(QgsProcessingParameterBoolean(self.COMPUTE_EDGES,
|
|
|
|
self.tr('Compute edges'),
|
|
|
|
defaultValue=False))
|
|
|
|
|
|
|
|
options_param = QgsProcessingParameterString(self.OPTIONS,
|
2018-08-02 12:03:45 +03:00
|
|
|
self.tr('Additional creation options'),
|
2017-09-06 16:59:48 +03:00
|
|
|
defaultValue='',
|
|
|
|
optional=True)
|
|
|
|
options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
|
|
|
options_param.setMetadata({
|
|
|
|
'widget_wrapper': {
|
|
|
|
'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
|
|
|
|
self.addParameter(options_param)
|
2013-10-13 14:36:10 +03:00
|
|
|
|
2017-08-31 15:03:33 +03:00
|
|
|
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Roughness')))
|
2013-10-13 14:36:10 +03:00
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def name(self):
|
|
|
|
return 'roughness'
|
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Roughness')
|
|
|
|
|
2017-08-31 15:03:33 +03:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Raster analysis')
|
|
|
|
|
2017-12-14 12:05:40 +02:00
|
|
|
def groupId(self):
|
|
|
|
return 'rasteranalysis'
|
|
|
|
|
2018-05-05 19:18:41 +10:00
|
|
|
def commandName(self):
|
|
|
|
return 'gdaldem'
|
|
|
|
|
2017-12-08 13:51:30 +10:00
|
|
|
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
2013-10-13 14:36:10 +03:00
|
|
|
arguments = ['roughness']
|
2017-08-31 15:03:33 +03:00
|
|
|
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
|
2018-05-06 10:29:01 +10:00
|
|
|
if inLayer is None:
|
|
|
|
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))
|
|
|
|
|
2017-08-31 15:03:33 +03:00
|
|
|
arguments.append(inLayer.source())
|
|
|
|
|
|
|
|
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
2019-02-05 12:48:43 +10:00
|
|
|
self.setOutputValue(self.OUTPUT, out)
|
2017-08-31 15:03:33 +03:00
|
|
|
arguments.append(out)
|
2014-09-26 07:46:10 +02:00
|
|
|
|
|
|
|
arguments.append('-of')
|
2017-08-31 15:03:33 +03:00
|
|
|
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
|
2013-10-13 14:36:10 +03:00
|
|
|
|
|
|
|
arguments.append('-b')
|
2017-08-31 15:03:33 +03:00
|
|
|
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))
|
2013-10-13 14:36:10 +03:00
|
|
|
|
2019-04-16 08:30:00 +02:00
|
|
|
if self.parameterAsBoolean(parameters, self.COMPUTE_EDGES, context):
|
2013-10-13 14:36:10 +03:00
|
|
|
arguments.append('-compute_edges')
|
|
|
|
|
2017-09-06 16:59:48 +03:00
|
|
|
options = self.parameterAsString(parameters, self.OPTIONS, context)
|
|
|
|
if options:
|
|
|
|
arguments.append('-co')
|
|
|
|
arguments.append(options)
|
|
|
|
|
2018-05-05 19:18:41 +10:00
|
|
|
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|