26using namespace Qt::StringLiterals;
30QString QgsRuggednessAlgorithm::name()
const
32 return u
"ruggednessindex"_s;
35QString QgsRuggednessAlgorithm::displayName()
const
37 return QObject::tr(
"Ruggedness index" );
40QStringList QgsRuggednessAlgorithm::tags()
const
42 return QObject::tr(
"dem,ruggedness,index,terrain" ).split(
',' );
45QString QgsRuggednessAlgorithm::group()
const
47 return QObject::tr(
"Raster terrain analysis" );
50QString QgsRuggednessAlgorithm::groupId()
const
52 return u
"rasterterrainanalysis"_s;
55QString QgsRuggednessAlgorithm::shortHelpString()
const
58 "This algorithm calculates the quantitative measurement of terrain "
59 "heterogeneity described by Riley et al. (1999)."
63 "It is calculated for every location, by summarizing the change "
64 "in elevation within the 3x3 pixel grid. Each pixel contains the "
65 "difference in elevation from a center cell and the 8 cells surrounding it."
69QString QgsRuggednessAlgorithm::shortDescription()
const
71 return QObject::tr(
"Calculates the quantitative measurement of terrain heterogeneity described by Riley et al. (1999)." );
74QList<QgsAcademicReference> QgsRuggednessAlgorithm::academicReferences()
const
77 createJournalArticle( { u
"Riley, S."_s, u
"Degloria, S."_s, u
"Elliot, S. D."_s }, 1999, u
"A Terrain Ruggedness Index that Quantifies Topographic Heterogeneity"_s, u
"International Journal of Science"_s, u
"5"_s, QString(), u
"23-27"_s );
78 return { rileyReference };
81QgsRuggednessAlgorithm *QgsRuggednessAlgorithm::createInstance()
const
83 return new QgsRuggednessAlgorithm();
86void QgsRuggednessAlgorithm::initAlgorithm(
const QVariantMap & )
91 zFactorParam->setHelp( QObject::tr(
"Multiplication factor to convert vertical Z units to horizontal XY units." ) );
92 zFactorParam->setMetadata( { QVariantMap( { { u
"widget_wrapper"_s, QVariantMap( { { u
"decimals"_s, 12 } } ) } } ) } );
93 addParameter( zFactorParam.release() );
97 addParameter( outputNodataParam.release() );
99 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( u
"CREATION_OPTIONS"_s, QObject::tr(
"Creation options" ), QVariant(),
false,
true );
100 creationOptsParam->setMetadata( QVariantMap( { { u
"widget_wrapper"_s, QVariantMap( { { u
"widget_type"_s, u
"rasteroptions"_s } } ) } } ) );
102 addParameter( creationOptsParam.release() );
109 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, u
"INPUT"_s, context );
115 mLayerSource = layer->
source();
121 const double zFactor = parameterAsDouble( parameters, u
"Z_FACTOR"_s, context );
122 const QString creationOptions = parameterAsString( parameters, u
"CREATION_OPTIONS"_s, context ).trimmed();
123 const double outputNodata = parameterAsDouble( parameters, u
"NODATA"_s, context );
125 const QString outputFile = parameterAsOutputLayer( parameters, u
"OUTPUT"_s, context );
126 const QString outputFormat = parameterAsOutputRasterFormat( parameters, u
"OUTPUT"_s, context );
129 ruggedness.setZFactor( zFactor );
130 if ( !creationOptions.isEmpty() )
132 ruggedness.setCreationOptions( creationOptions.split(
'|' ) );
134 ruggedness.setOutputNodataValue( outputNodata );
135 ruggedness.processRaster( feedback );
138 outputs.insert( u
"OUTPUT"_s, outputFile );
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Double
Double/float values.
Encapsulates an academic reference and formats it according to style guidelines.
static QgsAcademicReference createJournalArticle(const QStringList &authors, int year, const QString &title, const QString &journal, const QString &volume=QString(), const QString &issue=QString(), const QString &pages=QString())
Creates a journal article reference.
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 raster layer destination parameter, for specifying the destination path for a raster layer created ...
A raster layer parameter for processing algorithms.
Represents a raster layer.
Calculates the ruggedness index based on a 3x3 moving window.