QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsalgorithmhillshade.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmhillshade.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 "qgshillshadefilter.h"
21#include "qgsrasterfilewriter.h"
22
24
25QString QgsHillshadeAlgorithm::name() const
26{
27 return QStringLiteral( "hillshade" );
28}
29
30QString QgsHillshadeAlgorithm::displayName() const
31{
32 return QObject::tr( "Hillshade" );
33}
34
35QStringList QgsHillshadeAlgorithm::tags() const
36{
37 return QObject::tr( "dem,hillshade,terrain" ).split( ',' );
38}
39
40QString QgsHillshadeAlgorithm::group() const
41{
42 return QObject::tr( "Raster terrain analysis" );
43}
44
45QString QgsHillshadeAlgorithm::groupId() const
46{
47 return QStringLiteral( "rasterterrainanalysis" );
48}
49
50QString QgsHillshadeAlgorithm::shortHelpString() const
51{
52 return QObject::tr( "This algorithm calculates the hillshade of the Digital Terrain Model in input." )
53 + QStringLiteral( "\n\n" )
54 + QObject::tr( "The shading of the layer is calculated according to the sun position (azimuth and elevation)." );
55}
56
57QString QgsHillshadeAlgorithm::shortDescription() const
58{
59 return QObject::tr( "Calculates the hillshade of a Digital Terrain Model." );
60}
61
62QgsHillshadeAlgorithm *QgsHillshadeAlgorithm::createInstance() const
63{
64 return new QgsHillshadeAlgorithm();
65}
66
67void QgsHillshadeAlgorithm::initAlgorithm( const QVariantMap & )
68{
69 addParameter( new QgsProcessingParameterRasterLayer( QStringLiteral( "INPUT" ), QObject::tr( "Elevation layer" ) ) );
70 addParameter( new QgsProcessingParameterNumber( QStringLiteral( "Z_FACTOR" ), QObject::tr( "Z factor" ), Qgis::ProcessingNumberParameterType::Double, 1, false, 0 ) );
71 addParameter( new QgsProcessingParameterNumber( QStringLiteral( "AZIMUTH" ), QObject::tr( "Azimuth (horizontal angle)" ), Qgis::ProcessingNumberParameterType::Double, 300, false, 0, 360 ) );
72 addParameter( new QgsProcessingParameterNumber( QStringLiteral( "V_ANGLE" ), QObject::tr( "Vertical angle" ), Qgis::ProcessingNumberParameterType::Double, 40, false, 0, 90 ) );
73
74 addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Hillshade" ) ) );
75}
76
77QVariantMap QgsHillshadeAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
78{
79 QgsRasterLayer *inputLayer = parameterAsRasterLayer( parameters, QStringLiteral( "INPUT" ), context );
80
81 if ( !inputLayer )
82 throw QgsProcessingException( invalidRasterError( parameters, QStringLiteral( "INPUT" ) ) );
83
84 const double zFactor = parameterAsDouble( parameters, QStringLiteral( "Z_FACTOR" ), context );
85 const double azimuth = parameterAsDouble( parameters, QStringLiteral( "AZIMUTH" ), context );
86 const double vAngle = parameterAsDouble( parameters, QStringLiteral( "V_ANGLE" ), context );
87
88 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
89 const QFileInfo fi( outputFile );
90 const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
91
92 QgsHillshadeFilter hillshade( inputLayer->source(), outputFile, outputFormat, azimuth, vAngle );
93 hillshade.setZFactor( zFactor );
94 hillshade.processRaster( feedback );
95
96 QVariantMap outputs;
97 outputs.insert( QStringLiteral( "OUTPUT" ), outputFile );
98 return outputs;
99}
100
@ Double
Double/float values.
Definition qgis.h:3804
A hillshade filter.
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.