QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsalgorithmaspect.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmaspect.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
18#include "qgsalgorithmaspect.h"
19
20#include "qgsaspectfilter.h"
21#include "qgsrasterfilewriter.h"
22
24
25QString QgsAspectAlgorithm::name() const
26{
27 return QStringLiteral( "aspect" );
28}
29
30QString QgsAspectAlgorithm::displayName() const
31{
32 return QObject::tr( "Aspect" );
33}
34
35QStringList QgsAspectAlgorithm::tags() const
36{
37 return QObject::tr( "dem,aspect,terrain,slope" ).split( ',' );
38}
39
40QString QgsAspectAlgorithm::group() const
41{
42 return QObject::tr( "Raster terrain analysis" );
43}
44
45QString QgsAspectAlgorithm::groupId() const
46{
47 return QStringLiteral( "rasterterrainanalysis" );
48}
49
50QString QgsAspectAlgorithm::shortHelpString() const
51{
52 return QObject::tr( "This algorithm calculates the aspect of the Digital Terrain Model in input." )
53 + QStringLiteral( "\n\n" )
54 + QObject::tr( "The final aspect raster layer contains values from 0 to 360 that express "
55 "the slope direction: starting from North (0°) and continuing clockwise." );
56}
57
58QString QgsAspectAlgorithm::shortDescription() const
59{
60 return QObject::tr( "Generates a raster layer representing the slope direction from a Digital Terrain Model." );
61}
62
63QgsAspectAlgorithm *QgsAspectAlgorithm::createInstance() const
64{
65 return new QgsAspectAlgorithm();
66}
67
68void QgsAspectAlgorithm::initAlgorithm( const QVariantMap & )
69{
70 addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "INPUT" ), QObject::tr( "Elevation layer" ) ) );
71 addParameter( new QgsProcessingParameterNumber( QStringLiteral( "Z_FACTOR" ), QObject::tr( "Z factor" ), Qgis::ProcessingNumberParameterType::Double, 1, false, 0 ) );
72
73 addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Aspect" ) ) );
74}
75
76QVariantMap QgsAspectAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
77{
78 QgsRasterLayer *inputLayer = parameterAsRasterLayer( parameters, QStringLiteral( "INPUT" ), context );
79
80 if ( !inputLayer )
81 throw QgsProcessingException( invalidRasterError( parameters, QStringLiteral( "INPUT" ) ) );
82
83 const double zFactor = parameterAsDouble( parameters, QStringLiteral( "Z_FACTOR" ), context );
84
85 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
86 const QFileInfo fi( outputFile );
87 const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
88
89 QgsAspectFilter aspect( inputLayer->source(), outputFile, outputFormat );
90 aspect.setZFactor( zFactor );
91 aspect.processRaster( feedback );
92
93 QVariantMap outputs;
94 outputs.insert( QStringLiteral( "OUTPUT" ), outputFile );
95 return outputs;
96}
97
@ Double
Double/float values.
Definition qgis.h:3804
Calculates aspect values in a window of 3x3 cells based on first order derivatives in x- and y- direc...
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.