25using namespace Qt::StringLiterals;
29QString QgsHillshadeAlgorithm::name()
const
31 return u
"hillshade"_s;
34QString QgsHillshadeAlgorithm::displayName()
const
36 return QObject::tr(
"Hillshade" );
39QStringList QgsHillshadeAlgorithm::tags()
const
41 return QObject::tr(
"dem,hillshade,terrain" ).split(
',' );
44QString QgsHillshadeAlgorithm::group()
const
46 return QObject::tr(
"Raster terrain analysis" );
49QString QgsHillshadeAlgorithm::groupId()
const
51 return u
"rasterterrainanalysis"_s;
54QString QgsHillshadeAlgorithm::shortHelpString()
const
56 return QObject::tr(
"This algorithm calculates the hillshade of the Digital Terrain Model in input." )
58 + QObject::tr(
"The shading of the layer is calculated according to the sun position (azimuth and elevation)." );
61QString QgsHillshadeAlgorithm::shortDescription()
const
63 return QObject::tr(
"Calculates the hillshade of a Digital Terrain Model." );
66QgsHillshadeAlgorithm *QgsHillshadeAlgorithm::createInstance()
const
68 return new QgsHillshadeAlgorithm();
71void QgsHillshadeAlgorithm::initAlgorithm(
const QVariantMap & )
76 zFactorParam->setHelp( QObject::tr(
"Multiplication factor to convert vertical Z units to horizontal XY units." ) );
77 zFactorParam->setMetadata( { QVariantMap( { { u
"widget_wrapper"_s, QVariantMap( { { u
"decimals"_s, 12 } } ) } } ) } );
78 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 double azimuth = parameterAsDouble( parameters, u
"AZIMUTH"_s, context );
111 const double vAngle = parameterAsDouble( parameters, u
"V_ANGLE"_s, context );
112 const QString creationOptions = parameterAsString( parameters, u
"CREATION_OPTIONS"_s, context ).trimmed();
113 const double outputNodata = parameterAsDouble( parameters, u
"NODATA"_s, context );
115 const QString outputFile = parameterAsOutputLayer( parameters, u
"OUTPUT"_s, context );
116 const QString outputFormat = parameterAsOutputRasterFormat( parameters, u
"OUTPUT"_s, context );
118 QgsHillshadeFilter hillshade( mLayerSource, outputFile, outputFormat, azimuth, vAngle );
119 hillshade.setZFactor( zFactor );
120 if ( !creationOptions.isEmpty() )
122 hillshade.setCreationOptions( creationOptions.split(
'|' ) );
124 hillshade.setOutputNodataValue( outputNodata );
125 hillshade.processRaster( feedback );
128 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 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.
Represents a raster layer.