18#ifndef QGSZONALSTATISTICS_H
19#define QGSZONALSTATISTICS_H
25#include "qgis_analysis.h"
92 double rasterUnitsPerPixelX,
93 double rasterUnitsPerPixelY,
94 const QString &attributePrefix = QString(),
144 static QMap<int, QVariant> calculateStatisticsInt(
156 FeatureStats(
bool storeValues =
false,
bool storeValueCounts =
false )
157 : mStoreValues( storeValues )
158 , mStoreValueCounts( storeValueCounts )
165 max = std::numeric_limits<double>::lowest();
166 min = std::numeric_limits<double>::max();
171 void addValue(
double value,
const QgsPointXY &point,
double weight = 1.0 )
173 if ( !std::isnan( value ) )
177 sum += value * weight;
200 if ( mStoreValueCounts )
203 values.append( value );
207 double max = std::numeric_limits<double>::lowest();
208 double min = std::numeric_limits<double>::max();
213 bool operator()(
double lhs,
double rhs )
const {
return ( std::isnan( lhs ) && !std::isnan( rhs ) ) || lhs < rhs; }
215 std::map<double, int64_t, CompareNaNAware> valueCount;
216 QList<double> values;
219 bool mStoreValues =
false;
220 bool mStoreValueCounts =
false;
223 QString getUniqueFieldName(
const QString &fieldName,
const QList<QgsField> &newFields );
228 double mCellSizeX = 0;
229 double mCellSizeY = 0;
234 QString mAttributePrefix;
ZonalStatistic
Statistics to be calculated during a zonal statistics operation.
@ Default
Default statistics.
@ All
All statistics. For QGIS 3.x this includes ONLY numeric statistics, but for 4.0 this will be extended...
ZonalStatisticResult
Zonal statistics result codes.
QFlags< ZonalStatistic > ZonalStatistics
Statistics to be calculated during a zonal statistics operation.
Represents a coordinate reference system (CRS).
An interface for objects which accept features via addFeature(s) methods.
An interface for objects which provide features via a getFeatures method.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Encapsulate a field in an attribute table or data source.
A geometry is the spatial representation of a feature.
Base class for raster data providers.
Base class for processing filters like renderers, reprojector, resampler etc.
Represents a raster layer.
A rectangle specified with double values.
Represents a vector layer which manages a vector based dataset.
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 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.
bool operator()(double lhs, double rhs) const