QGIS API Documentation 3.41.0-Master (3c143d501a8)
|
A class that calculates raster statistics (count, sum, mean) for a polygon or multipolygon layer and appends the results as attributes. More...
#include <qgszonalstatistics.h>
Public Member Functions | |
QgsZonalStatistics (QgsVectorLayer *polygonLayer, QgsRasterInterface *rasterInterface, const QgsCoordinateReferenceSystem &rasterCrs, double rasterUnitsPerPixelX, double rasterUnitsPerPixelY, const QString &attributePrefix=QString(), int rasterBand=1, Qgis::ZonalStatistics stats=Qgis::ZonalStatistic::Default) | |
Constructor for QgsZonalStatistics, using a QgsRasterInterface. | |
QgsZonalStatistics (QgsVectorLayer *polygonLayer, QgsRasterLayer *rasterLayer, const QString &attributePrefix=QString(), int rasterBand=1, Qgis::ZonalStatistics stats=Qgis::ZonalStatistic::Default) | |
Convenience constructor for QgsZonalStatistics, using an input raster layer. | |
Qgis::ZonalStatisticResult | calculateStatistics (QgsFeedback *feedback) |
Runs the calculation. | |
Static Public Member Functions | |
static QMap< Qgis::ZonalStatistic, QVariant > | calculateStatistics (QgsRasterInterface *rasterInterface, const QgsGeometry &geometry, double cellSizeX, double cellSizeY, int rasterBand, Qgis::ZonalStatistics statistics) |
Calculates the specified statistics for the pixels of rasterBand in rasterInterface (a raster layer dataProvider() ) within polygon geometry. | |
static QString | displayName (Qgis::ZonalStatistic statistic) |
Returns the friendly display name for a statistic. | |
static QString | shortName (Qgis::ZonalStatistic statistic) |
Returns a short, friendly display name for a statistic, suitable for use in a field name. | |
A class that calculates raster statistics (count, sum, mean) for a polygon or multipolygon layer and appends the results as attributes.
Definition at line 46 of file qgszonalstatistics.h.
QgsZonalStatistics::QgsZonalStatistics | ( | QgsVectorLayer * | polygonLayer, |
QgsRasterLayer * | rasterLayer, | ||
const QString & | attributePrefix = QString() , |
||
int | rasterBand = 1 , |
||
Qgis::ZonalStatistics | stats = Qgis::ZonalStatistic::Default |
||
) |
Convenience constructor for QgsZonalStatistics, using an input raster layer.
The raster layer must exist for the lifetime of the zonal statistics calculation.
Definition at line 31 of file qgszonalstatistics.cpp.
QgsZonalStatistics::QgsZonalStatistics | ( | QgsVectorLayer * | polygonLayer, |
QgsRasterInterface * | rasterInterface, | ||
const QgsCoordinateReferenceSystem & | rasterCrs, | ||
double | rasterUnitsPerPixelX, | ||
double | rasterUnitsPerPixelY, | ||
const QString & | attributePrefix = QString() , |
||
int | rasterBand = 1 , |
||
Qgis::ZonalStatistics | stats = Qgis::ZonalStatistic::Default |
||
) |
Constructor for QgsZonalStatistics, using a QgsRasterInterface.
The polygonLayer gives the vector layer containing the (multi)polygon features corresponding to the different zones. This layer will be modified, adding extra attributes for each of the zonal statistics calculated.
Pixel values for each zone are taken from the raster rasterInterface. The constructor must also be given various properties relating to the input raster, such as the raster CRS (rasterCrs), and the size (X and Y) in map units for each raster pixel. The source raster band is specified via rasterBand, where a value of 1 corresponds to the first band.
If the CRS of the polygonLayer and rasterCrs differ, the calculation will automatically reproject the zones to ensure valid results are calculated.
The attributePrefix argument specifies an optional prefix to use when creating the new fields for each calculated statistic.
Finally, the calculated statistics can be set via the stats argument. A new field will be added to polygonLayer for each statistic calculated.
Definition at line 43 of file qgszonalstatistics.cpp.
Qgis::ZonalStatisticResult QgsZonalStatistics::calculateStatistics | ( | QgsFeedback * | feedback | ) |
Runs the calculation.
Definition at line 56 of file qgszonalstatistics.cpp.
|
static |
Calculates the specified statistics for the pixels of rasterBand in rasterInterface (a raster layer dataProvider() ) within polygon geometry.
Returns a map of statistic to result value.
Definition at line 311 of file qgszonalstatistics.cpp.
|
static |
Returns the friendly display name for a statistic.
Definition at line 220 of file qgszonalstatistics.cpp.
|
static |
Returns a short, friendly display name for a statistic, suitable for use in a field name.
Definition at line 259 of file qgszonalstatistics.cpp.