22 const std::vector< QgsZonalStatistics::Statistic > STATS
38 QString QgsZonalStatisticsAlgorithm::name()
const 40 return QStringLiteral(
"zonalstatistics" );
43 QString QgsZonalStatisticsAlgorithm::displayName()
const 45 return QObject::tr(
"Zonal statistics" );
48 QStringList QgsZonalStatisticsAlgorithm::tags()
const 50 return QObject::tr(
"stats,statistics,zones,layer,sum,maximum,minimum,mean,count,standard,deviation," 51 "median,range,majority,minority,variety,variance,summary,raster" ).split(
',' );
54 QString QgsZonalStatisticsAlgorithm::group()
const 56 return QObject::tr(
"Raster analysis" );
59 QString QgsZonalStatisticsAlgorithm::groupId()
const 61 return QStringLiteral(
"rasteranalysis" );
64 QString QgsZonalStatisticsAlgorithm::shortHelpString()
const 66 return QObject::tr(
"This algorithm calculates statistics of a raster layer for each feature " 67 "of an overlapping polygon vector layer." );
70 QgsProcessingAlgorithm::Flags QgsZonalStatisticsAlgorithm::flags()
const 75 QgsZonalStatisticsAlgorithm *QgsZonalStatisticsAlgorithm::createInstance()
const 77 return new QgsZonalStatisticsAlgorithm();
80 void QgsZonalStatisticsAlgorithm::initAlgorithm(
const QVariantMap & )
82 QStringList statChoices;
83 statChoices.reserve( STATS.size() );
91 QObject::tr(
"Raster band" ), 1, QStringLiteral(
"INPUT_RASTER" ) ) );
94 addParameter(
new QgsProcessingParameterString( QStringLiteral(
"COLUMN_PREFIX" ), QObject::tr(
"Output column prefix" ), QStringLiteral(
"_" ) ) );
97 statChoices,
true, QVariantList() << 0 << 1 << 2 ) );
104 QgsRasterLayer *rasterLayer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT_RASTER" ), context );
108 mBand = parameterAsInt( parameters, QStringLiteral(
"RASTER_BAND" ), context );
109 if ( mBand < 1 || mBand > rasterLayer->
bandCount() )
110 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand )
114 mCrs = rasterLayer->
crs();
118 mPrefix = parameterAsString( parameters, QStringLiteral(
"COLUMN_PREFIX" ), context );
120 const QList< int > stats = parameterAsEnums( parameters, QStringLiteral(
"STATISTICS" ), context );
122 for (
int s : stats )
124 mStats |= STATS.at( s );
132 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"INPUT_VECTOR" ), context );
143 QgsZonalStatistics::Statistics( mStats )
149 outputs.insert( QStringLiteral(
"INPUT_VECTOR" ), layer->
id() );
Base class for providing feedback from a processing algorithm.
Statistic
Enumeration of flags that specify statistics to be calculated.
int bandCount() const
Returns the number of bands in this layer.
Represents a raster layer.
double rasterUnitsPerPixelX() const
Returns the number of raster units per each raster pixel in X axis.
QgsRasterInterface * clone() const override=0
Clone itself, create deep copy.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users...
double rasterUnitsPerPixelY() const
Returns the number of raster units per each raster pixel in Y axis.
A raster band parameter for Processing algorithms.
A vector layer output for processing algorithms.
Minority of pixel values.
Variety (count of distinct) pixel values.
Variance of pixel values.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
A raster layer parameter for processing algorithms.
static QString displayName(QgsZonalStatistics::Statistic statistic)
Returns the friendly display name for a statistic.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
An enum based parameter for processing algorithms, allowing for selection from predefined values...
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
Majority of pixel values.
Custom exception class for processing related exceptions.
A vector layer (with or without geometry) parameter for processing algorithms.
int calculateStatistics(QgsFeedback *feedback)
Starts the calculation.
Range of pixel values (max - min)
A class that calculates raster statistics (count, sum, mean) for a polygon or multipolygon layer and ...
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
A string parameter for processing algorithms.
QgsCoordinateReferenceSystem crs
Standard deviation of pixel values.