25using namespace Qt::StringLiterals;
29QString QgsSlopeAlgorithm::name()
const
34QString QgsSlopeAlgorithm::displayName()
const
36 return QObject::tr(
"Slope" );
39QStringList QgsSlopeAlgorithm::tags()
const
41 return QObject::tr(
"dem,slope,terrain" ).split(
',' );
44QString QgsSlopeAlgorithm::group()
const
46 return QObject::tr(
"Raster terrain analysis" );
49QString QgsSlopeAlgorithm::groupId()
const
51 return u
"rasterterrainanalysis"_s;
54QString QgsSlopeAlgorithm::shortHelpString()
const
56 return QObject::tr(
"This algorithm calculates the angle of inclination "
57 "of the terrain from an input raster layer. The slope "
58 "is expressed in degrees." );
61QString QgsSlopeAlgorithm::shortDescription()
const
63 return QObject::tr(
"Calculates the angle of inclination of the terrain from an input raster layer." );
66QgsSlopeAlgorithm *QgsSlopeAlgorithm::createInstance()
const
68 return new QgsSlopeAlgorithm();
71void QgsSlopeAlgorithm::initAlgorithm(
const QVariantMap & )
76 zFactorParam->setHelp( QObject::tr(
"Multiplication factor to convert vertical Z units to horizontal XY units." ) );
77 zFactorParam->setMetadata(
78 { QVariantMap( { { u
"widget_wrapper"_s, QVariantMap( { { u
"decimals"_s, 12 } } ) } } )
81 addParameter( zFactorParam.release() );
85 addParameter( outputNodataParam.release() );
87 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( u
"CREATION_OPTIONS"_s, QObject::tr(
"Creation options" ), QVariant(),
false,
true );
88 creationOptsParam->setMetadata( QVariantMap( { { u
"widget_wrapper"_s, QVariantMap( { { u
"widget_type"_s, u
"rasteroptions"_s } } ) } } ) );
90 addParameter( creationOptsParam.release() );
97 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, u
"INPUT"_s, context );
103 mLayerSource = layer->
source();
109 const double zFactor = parameterAsDouble( parameters, u
"Z_FACTOR"_s, context );
110 const QString creationOptions = parameterAsString( parameters, u
"CREATION_OPTIONS"_s, context ).trimmed();
111 const double outputNodata = parameterAsDouble( parameters, u
"NODATA"_s, context );
113 const QString outputFile = parameterAsOutputLayer( parameters, u
"OUTPUT"_s, context );
114 const QString outputFormat = parameterAsOutputRasterFormat( parameters, u
"OUTPUT"_s, context );
117 if ( !creationOptions.isEmpty() )
119 slope.setCreationOptions( creationOptions.split(
'|' ) );
121 slope.setOutputNodataValue( outputNodata );
122 slope.setZFactor( zFactor );
123 slope.processRaster( feedback );
126 outputs.insert( u
"OUTPUT"_s, outputFile );
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Double
Double/float values.
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 slope values in a window of 3x3 cells based on first order derivatives in x- and y- direct...