22const std::vector< QgsZonalStatistics::Statistic > STATS
38QString QgsZonalStatisticsAlgorithm::name()
const
40 return QStringLiteral(
"zonalstatistics" );
43QString QgsZonalStatisticsAlgorithm::displayName()
const
45 return QObject::tr(
"Zonal statistics (in place)" );
48QStringList 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(
',' );
54QString QgsZonalStatisticsAlgorithm::group()
const
56 return QObject::tr(
"Raster analysis" );
59QString QgsZonalStatisticsAlgorithm::groupId()
const
61 return QStringLiteral(
"rasteranalysis" );
64QString QgsZonalStatisticsAlgorithm::shortDescription()
const
66 return QObject::tr(
"Calculates statistics for a raster layer's values for each feature of an overlapping polygon vector layer." );
69QString QgsZonalStatisticsAlgorithm::shortHelpString()
const
71 return QObject::tr(
"This algorithm calculates statistics of a raster layer for each feature "
72 "of an overlapping polygon vector layer. The results will be written in place." );
75QgsProcessingAlgorithm::Flags QgsZonalStatisticsAlgorithm::flags()
const
80QgsZonalStatisticsAlgorithm *QgsZonalStatisticsAlgorithm::createInstance()
const
82 return new QgsZonalStatisticsAlgorithm();
85void QgsZonalStatisticsAlgorithm::initAlgorithm(
const QVariantMap & )
87 QStringList statChoices;
88 statChoices.reserve( STATS.size() );
96 QObject::tr(
"Raster band" ), 1, QStringLiteral(
"INPUT_RASTER" ) ) );
99 addParameter(
new QgsProcessingParameterString( QStringLiteral(
"COLUMN_PREFIX" ), QObject::tr(
"Output column prefix" ), QStringLiteral(
"_" ) ) );
102 statChoices,
true, QVariantList() << 0 << 1 << 2 ) );
109 QgsRasterLayer *rasterLayer = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT_RASTER" ), context );
113 mBand = parameterAsInt( parameters, QStringLiteral(
"RASTER_BAND" ), context );
114 if ( mBand < 1 || mBand > rasterLayer->
bandCount() )
115 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand )
119 mCrs = rasterLayer->
crs();
123 mPrefix = parameterAsString( parameters, QStringLiteral(
"COLUMN_PREFIX" ), context );
125 const QList< int > stats = parameterAsEnums( parameters, QStringLiteral(
"STATISTICS" ), context );
126 mStats = QgsZonalStatistics::Statistics();
127 for (
const int s : stats )
129 mStats |= STATS.at( s );
137 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"INPUT_VECTOR" ), context );
148 QgsZonalStatistics::Statistics( mStats )
151 zs.calculateStatistics( feedback );
154 outputs.insert( QStringLiteral(
"INPUT_VECTOR" ), layer->
id() );
QgsCoordinateReferenceSystem crs
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
@ FlagNoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
@ FlagDeprecated
Algorithm is deprecated.
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.
@ TypeVectorPolygon
Vector polygon layers.
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 ...
Statistic
Enumeration of flags that specify statistics to be calculated.
@ Minority
Minority of pixel values.
@ Variety
Variety (count of distinct) pixel values.
@ Variance
Variance of pixel values.
@ Mean
Mean of pixel values.
@ Majority
Majority of pixel values.
@ Range
Range of pixel values (max - min)
@ Min
Min of pixel values.
@ Sum
Sum of pixel values.
@ StDev
Standard deviation of pixel values.
@ Max
Max of pixel values.
@ Median
Median of pixel values.
static QString displayName(QgsZonalStatistics::Statistic statistic)
Returns the friendly display name for a statistic.