26using namespace Qt::StringLiterals;
30QString QgsZonalStatisticsAlgorithm::name()
const
32 return u
"zonalstatistics"_s;
35QString QgsZonalStatisticsAlgorithm::displayName()
const
37 return QObject::tr(
"Zonal statistics (in place)" );
40QStringList QgsZonalStatisticsAlgorithm::tags()
const
42 return QObject::tr(
"stats,statistics,zones,layer,sum,maximum,minimum,mean,count,standard,deviation,"
43 "median,range,majority,minority,variety,variance,summary,raster" )
47QString QgsZonalStatisticsAlgorithm::group()
const
49 return QObject::tr(
"Raster analysis" );
52QString QgsZonalStatisticsAlgorithm::groupId()
const
54 return u
"rasteranalysis"_s;
57QString QgsZonalStatisticsAlgorithm::shortDescription()
const
59 return QObject::tr(
"Calculates statistics for a raster layer's values for each feature of an overlapping polygon vector layer." );
62QString QgsZonalStatisticsAlgorithm::shortHelpString()
const
64 return QObject::tr(
"This algorithm calculates statistics of a raster layer for each feature "
65 "of an overlapping polygon vector layer. The results will be written in place." );
73QgsZonalStatisticsAlgorithm *QgsZonalStatisticsAlgorithm::createInstance()
const
75 return new QgsZonalStatisticsAlgorithm();
78void QgsZonalStatisticsAlgorithm::initAlgorithm(
const QVariantMap & )
80 QStringList statChoices;
81 statChoices.reserve( STATS.size() );
92 addParameter(
new QgsProcessingParameterEnum( u
"STATISTICS"_s, QObject::tr(
"Statistics to calculate" ), statChoices,
true, QVariantList() << 0 << 1 << 2 ) );
99 QgsRasterLayer *rasterLayer = parameterAsRasterLayer( parameters, u
"INPUT_RASTER"_s, context );
103 mBand = parameterAsInt( parameters, u
"RASTER_BAND"_s, context );
104 if ( mBand < 1 || mBand > rasterLayer->
bandCount() )
105 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand ).arg( rasterLayer->
bandCount() ) );
108 mCrs = rasterLayer->
crs();
112 mPrefix = parameterAsString( parameters, u
"COLUMN_PREFIX"_s, context );
114 const QList<int> stats = parameterAsEnums( parameters, u
"STATISTICS"_s, context );
116 for (
const int s : stats )
118 mStats |= STATS.at( s );
126 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, u
"INPUT_VECTOR"_s, context );
132 zs.calculateStatistics( feedback );
135 outputs.insert( u
"INPUT_VECTOR"_s, 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 dataset.
Calculates raster statistics (count, sum, mean) for a polygon or multipolygon layer and appends the r...
static QString displayName(Qgis::ZonalStatistic statistic)
Returns the friendly display name for a statistic.