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 (in place)" );
 
   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. The results will be written in place." );
 
   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 );
 
  121   mStats = QgsZonalStatistics::Statistics();
 
  122   for ( 
int s : stats )
 
  124     mStats |= STATS.at( s );
 
  132   QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral( 
"INPUT_VECTOR" ), context );
 
  143                          QgsZonalStatistics::Statistics( mStats )
 
  146   zs.calculateStatistics( feedback );
 
  149   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.