25QString QgsZonalStatisticsAlgorithm::name()
const
27 return QStringLiteral(
"zonalstatistics" );
30QString QgsZonalStatisticsAlgorithm::displayName()
const
32 return QObject::tr(
"Zonal statistics (in place)" );
35QStringList QgsZonalStatisticsAlgorithm::tags()
const
37 return QObject::tr(
"stats,statistics,zones,layer,sum,maximum,minimum,mean,count,standard,deviation,"
38 "median,range,majority,minority,variety,variance,summary,raster" )
42QString QgsZonalStatisticsAlgorithm::group()
const
44 return QObject::tr(
"Raster analysis" );
47QString QgsZonalStatisticsAlgorithm::groupId()
const
49 return QStringLiteral(
"rasteranalysis" );
52QString QgsZonalStatisticsAlgorithm::shortDescription()
const
54 return QObject::tr(
"Calculates statistics for a raster layer's values for each feature of an overlapping polygon vector layer." );
57QString QgsZonalStatisticsAlgorithm::shortHelpString()
const
59 return QObject::tr(
"This algorithm calculates statistics of a raster layer for each feature "
60 "of an overlapping polygon vector layer. The results will be written in place." );
68QgsZonalStatisticsAlgorithm *QgsZonalStatisticsAlgorithm::createInstance()
const
70 return new QgsZonalStatisticsAlgorithm();
73void QgsZonalStatisticsAlgorithm::initAlgorithm(
const QVariantMap & )
75 QStringList statChoices;
76 statChoices.reserve( STATS.size() );
83 addParameter(
new QgsProcessingParameterBand( QStringLiteral(
"RASTER_BAND" ), QObject::tr(
"Raster band" ), 1, QStringLiteral(
"INPUT_RASTER" ) ) );
85 addParameter(
new QgsProcessingParameterString( QStringLiteral(
"COLUMN_PREFIX" ), QObject::tr(
"Output column prefix" ), QStringLiteral(
"_" ) ) );
87 addParameter(
new QgsProcessingParameterEnum( QStringLiteral(
"STATISTICS" ), QObject::tr(
"Statistics to calculate" ), statChoices,
true, QVariantList() << 0 << 1 << 2 ) );
94 QgsRasterLayer *rasterLayer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT_RASTER" ), context );
98 mBand = parameterAsInt( parameters, QStringLiteral(
"RASTER_BAND" ), context );
99 if ( mBand < 1 || mBand > rasterLayer->
bandCount() )
100 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand ).arg( rasterLayer->
bandCount() ) );
103 mCrs = rasterLayer->
crs();
107 mPrefix = parameterAsString( parameters, QStringLiteral(
"COLUMN_PREFIX" ), context );
109 const QList<int> stats = parameterAsEnums( parameters, QStringLiteral(
"STATISTICS" ), context );
111 for (
const int s : stats )
113 mStats |= STATS.at( s );
121 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"INPUT_VECTOR" ), context );
127 zs.calculateStatistics( feedback );
130 outputs.insert( QStringLiteral(
"INPUT_VECTOR" ), layer->
id() );
@ VectorPolygon
Vector polygon layers.
ZonalStatistic
Statistics to be calculated during a zonal statistics operation.
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
QFlags< ZonalStatistic > ZonalStatistics
Statistics to be calculated during a zonal statistics operation.
@ Deprecated
Algorithm is deprecated.
@ NoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
QgsCoordinateReferenceSystem crs
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
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 vector layer output for processing algorithms.
A raster band parameter for Processing algorithms.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
A raster layer parameter for processing algorithms.
A string parameter for processing algorithms.
A vector layer (with or without geometry) parameter for processing algorithms.
QgsRasterDataProvider * clone() const override=0
Clone itself, create deep copy.
Represents a raster layer.
int bandCount() const
Returns the number of bands in this layer.
double rasterUnitsPerPixelX() const
Returns the number of raster units per each raster pixel in X axis.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis.
Represents a vector layer which manages a vector based data sets.
A class that calculates raster statistics (count, sum, mean) for a polygon or multipolygon layer and ...
static QString displayName(Qgis::ZonalStatistic statistic)
Returns the friendly display name for a statistic.