QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsalgorithmruggedness.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmruggedness.cpp
3 ---------------------
4 begin : November 2019
5 copyright : (C) 2019 by Alexander Bruy
6 email : alexander dot bruy at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include "qgsrasterfilewriter.h"
21#include "qgsruggednessfilter.h"
22
24
25QString QgsRuggednessAlgorithm::name() const
26{
27 return QStringLiteral( "ruggednessindex" );
28}
29
30QString QgsRuggednessAlgorithm::displayName() const
31{
32 return QObject::tr( "Ruggedness index" );
33}
34
35QStringList QgsRuggednessAlgorithm::tags() const
36{
37 return QObject::tr( "dem,ruggedness,index,terrain" ).split( ',' );
38}
39
40QString QgsRuggednessAlgorithm::group() const
41{
42 return QObject::tr( "Raster terrain analysis" );
43}
44
45QString QgsRuggednessAlgorithm::groupId() const
46{
47 return QStringLiteral( "rasterterrainanalysis" );
48}
49
50QString QgsRuggednessAlgorithm::shortHelpString() const
51{
52 return QObject::tr( "This algorithm calculates the quantitative measurement of terrain "
53 "heterogeneity described by Riley et al. (1999)." )
54 + QStringLiteral( "\n\n" )
55 + QObject::tr( "It is calculated for every location, by summarizing the change "
56 "in elevation within the 3x3 pixel grid. Each pixel contains the "
57 "difference in elevation from a center cell and the 8 cells surrounding it." );
58}
59
60QString QgsRuggednessAlgorithm::shortDescription() const
61{
62 return QObject::tr( "Calculates the quantitative measurement of terrain heterogeneity described by Riley et al. (1999)." );
63}
64
65QgsRuggednessAlgorithm *QgsRuggednessAlgorithm::createInstance() const
66{
67 return new QgsRuggednessAlgorithm();
68}
69
70void QgsRuggednessAlgorithm::initAlgorithm( const QVariantMap & )
71{
72 addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "INPUT" ), QObject::tr( "Elevation layer" ) ) );
73 addParameter( new QgsProcessingParameterNumber( QStringLiteral( "Z_FACTOR" ), QObject::tr( "Z factor" ), Qgis::ProcessingNumberParameterType::Double, 1, false, 0 ) );
74
75 addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Ruggedness" ) ) );
76}
77
78QVariantMap QgsRuggednessAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
79{
80 QgsRasterLayer *inputLayer = parameterAsRasterLayer( parameters, QStringLiteral( "INPUT" ), context );
81
82 if ( !inputLayer )
83 throw QgsProcessingException( invalidRasterError( parameters, QStringLiteral( "INPUT" ) ) );
84
85 const double zFactor = parameterAsDouble( parameters, QStringLiteral( "Z_FACTOR" ), context );
86
87 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
88 const QFileInfo fi( outputFile );
89 const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
90
91 QgsRuggednessFilter ruggedness( inputLayer->source(), outputFile, outputFormat );
92 ruggedness.setZFactor( zFactor );
93 ruggedness.processRaster( feedback );
94
95 QVariantMap outputs;
96 outputs.insert( QStringLiteral( "OUTPUT" ), outputFile );
97 return outputs;
98}
99
@ Double
Double/float values.
Definition qgis.h:3804
QString source() const
Returns the source for the layer.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A numeric parameter for processing algorithms.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
A raster layer parameter for processing algorithms.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
Represents a raster layer.
Calculates the ruggedness index based on a 3x3 moving window.