QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsalgorithmtotalcurvature.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmtotalcurvature.cpp
3 ---------------------
4 begin : December 2025
5 copyright : (C) 2025 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"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
28
29QString QgsTotalCurvatureAlgorithm::name() const
30{
31 return u"totalcurvature"_s;
32}
33
34QString QgsTotalCurvatureAlgorithm::displayName() const
35{
36 return QObject::tr( "Total curvature" );
37}
38
39QStringList QgsTotalCurvatureAlgorithm::tags() const
40{
41 return QObject::tr( "dem,total curvature,terrain" ).split( ',' );
42}
43
44QString QgsTotalCurvatureAlgorithm::group() const
45{
46 return QObject::tr( "Raster terrain analysis" );
47}
48
49QString QgsTotalCurvatureAlgorithm::groupId() const
50{
51 return u"rasterterrainanalysis"_s;
52}
53
54QString QgsTotalCurvatureAlgorithm::shortHelpString() const
55{
56 return QObject::tr( "This algorithm calculates total curvature of the input raster as described by Wilson, Gallant (2000): terrain analysis." );
57}
58
59QString QgsTotalCurvatureAlgorithm::shortDescription() const
60{
61 return QObject::tr( "Calculates total curvature as described by Wilson, Gallant (2000): terrain analysis." );
62}
63
64QgsTotalCurvatureAlgorithm *QgsTotalCurvatureAlgorithm::createInstance() const
65{
66 return new QgsTotalCurvatureAlgorithm();
67}
68
69void QgsTotalCurvatureAlgorithm::initAlgorithm( const QVariantMap & )
70{
71 addParameter( new QgsProcessingParameterRasterLayer( u"INPUT"_s, QObject::tr( "Elevation layer" ) ) );
72
73 auto zFactorParam = std::make_unique<QgsProcessingParameterNumber>( u"Z_FACTOR"_s, QObject::tr( "Z factor" ), Qgis::ProcessingNumberParameterType::Double, 1.0, false, 0.0 );
74 zFactorParam->setHelp( QObject::tr( "Multiplication factor to convert vertical Z units to horizontal XY units." ) );
75 zFactorParam->setMetadata(
76 { QVariantMap( { { u"widget_wrapper"_s, QVariantMap( { { u"decimals"_s, 12 } } ) } } )
77 }
78 );
79 addParameter( zFactorParam.release() );
80
81 auto outputNodataParam = std::make_unique<QgsProcessingParameterNumber>( u"NODATA"_s, QObject::tr( "Output NoData value" ), Qgis::ProcessingNumberParameterType::Double, -9999.0 );
82 outputNodataParam->setFlags( outputNodataParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
83 addParameter( outputNodataParam.release() );
84
85 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( u"CREATION_OPTIONS"_s, QObject::tr( "Creation options" ), QVariant(), false, true );
86 creationOptsParam->setMetadata( QVariantMap( { { u"widget_wrapper"_s, QVariantMap( { { u"widget_type"_s, u"rasteroptions"_s } } ) } } ) );
87 creationOptsParam->setFlags( creationOptsParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
88 addParameter( creationOptsParam.release() );
89
90 addParameter( new QgsProcessingParameterRasterDestination( u"OUTPUT"_s, QObject::tr( "Total curvature" ) ) );
91}
92
93bool QgsTotalCurvatureAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
94{
95 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, u"INPUT"_s, context );
96 if ( !layer )
97 {
98 throw QgsProcessingException( invalidRasterError( parameters, u"INPUT"_s ) );
99 }
100
101 mLayerSource = layer->source();
102 return true;
103}
104
105QVariantMap QgsTotalCurvatureAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
106{
107 const double zFactor = parameterAsDouble( parameters, u"Z_FACTOR"_s, context );
108 const QString creationOptions = parameterAsString( parameters, u"CREATION_OPTIONS"_s, context ).trimmed();
109 const double outputNodata = parameterAsDouble( parameters, u"NODATA"_s, context );
110
111 const QString outputFile = parameterAsOutputLayer( parameters, u"OUTPUT"_s, context );
112 const QString outputFormat = parameterAsOutputRasterFormat( parameters, u"OUTPUT"_s, context );
113
114 QgsTotalCurvatureFilter curvature( mLayerSource, outputFile, outputFormat );
115 curvature.setZFactor( zFactor );
116 if ( !creationOptions.isEmpty() )
117 {
118 curvature.setCreationOptions( creationOptions.split( '|' ) );
119 }
120 curvature.setOutputNodataValue( outputNodata );
121 curvature.processRaster( feedback );
122
123 QVariantMap outputs;
124 outputs.insert( u"OUTPUT"_s, outputFile );
125 return outputs;
126}
127
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
Definition qgis.h:3834
@ Double
Double/float values.
Definition qgis.h:3875
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 total curvature as described by Wilson, Gallant (2000): terrain analysis.