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(
78 { QVariantMap( { { u
"widget_wrapper"_s, QVariantMap( { { u
"decimals"_s, 12 } } ) } } )
81 addParameter( zFactorParam.release() );
88 addParameter( outputNodataParam.release() );
90 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( u
"CREATION_OPTIONS"_s, QObject::tr(
"Creation options" ), QVariant(),
false,
true );
91 creationOptsParam->setMetadata( QVariantMap( { { u
"widget_wrapper"_s, QVariantMap( { { u
"widget_type"_s, u
"rasteroptions"_s } } ) } } ) );
93 addParameter( creationOptsParam.release() );
100 QgsRasterLayer *layer = parameterAsRasterLayer( parameters, u
"INPUT"_s, context );
106 mLayerSource = layer->
source();
112 const double zFactor = parameterAsDouble( parameters, u
"Z_FACTOR"_s, context );
113 const double azimuth = parameterAsDouble( parameters, u
"AZIMUTH"_s, context );
114 const double vAngle = parameterAsDouble( parameters, u
"V_ANGLE"_s, context );
115 const QString creationOptions = parameterAsString( parameters, u
"CREATION_OPTIONS"_s, context ).trimmed();
116 const double outputNodata = parameterAsDouble( parameters, u
"NODATA"_s, context );
118 const QString outputFile = parameterAsOutputLayer( parameters, u
"OUTPUT"_s, context );
119 const QString outputFormat = parameterAsOutputRasterFormat( parameters, u
"OUTPUT"_s, context );
121 QgsHillshadeFilter hillshade( mLayerSource, outputFile, outputFormat, azimuth, vAngle );
122 hillshade.setZFactor( zFactor );
123 if ( !creationOptions.isEmpty() )
125 hillshade.setCreationOptions( creationOptions.split(
'|' ) );
127 hillshade.setOutputNodataValue( outputNodata );
128 hillshade.processRaster( feedback );
131 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.