Quantum GIS API Documentation  1.7.4
Public Member Functions | Private Member Functions | Private Attributes
QgsZonalStatistics Class Reference

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>

Collaboration diagram for QgsZonalStatistics:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QgsZonalStatistics (QgsVectorLayer *polygonLayer, const QString &rasterFile, const QString &attributePrefix="", int rasterBand=1)
 ~QgsZonalStatistics ()
int calculateStatistics (QProgressDialog *p)
 Starts the calculation.

Private Member Functions

 QgsZonalStatistics ()
int cellInfoForBBox (const QgsRectangle &rasterBBox, const QgsRectangle &featureBBox, double cellSizeX, double cellSizeY, int &offsetX, int &offsetY, int &nCellsX, int &nCellsY) const
 Analysis what cells need to be considered to cover the bounding box of a feature.
void statisticsFromMiddlePointTest (void *band, QgsGeometry *poly, int pixelOffsetX, int pixelOffsetY, int nCellsX, int nCellsY, double cellSizeX, double cellSizeY, const QgsRectangle &rasterBBox, double &sum, double &count)
 Returns statistics by considering the pixels where the center point is within the polygon (fast)
void statisticsFromMiddlePointTest_improved (void *band, QgsGeometry *poly, int pixelOffsetX, int pixelOffsetY, int nCellsX, int nCellsY, double cellSizeX, double cellSizeY, const QgsRectangle &rasterBBox, double &sum, double &count)
void statisticsFromPreciseIntersection (void *band, QgsGeometry *poly, int pixelOffsetX, int pixelOffsetY, int nCellsX, int nCellsY, double cellSizeX, double cellSizeY, const QgsRectangle &rasterBBox, double &sum, double &count)
 Returns statistics with precise pixel - polygon intersection test (slow)

Private Attributes

QString mRasterFilePath
int mRasterBand
 Raster band to calculate statistics from (defaults to 1)
QgsVectorLayermPolygonLayer
QString mAttributePrefix
float mInputNodataValue
 The nodata value of the input layer.

Detailed Description

A class that calculates raster statistics (count, sum, mean) for a polygon or multipolygon layer and appends the results as attributes.

Definition at line 29 of file qgszonalstatistics.h.


Constructor & Destructor Documentation

QgsZonalStatistics::QgsZonalStatistics ( QgsVectorLayer polygonLayer,
const QString &  rasterFile,
const QString &  attributePrefix = "",
int  rasterBand = 1 
)

Definition at line 32 of file qgszonalstatistics.cpp.

Definition at line 49 of file qgszonalstatistics.cpp.

Definition at line 42 of file qgszonalstatistics.cpp.


Member Function Documentation

int QgsZonalStatistics::calculateStatistics ( QProgressDialog *  p)
int QgsZonalStatistics::cellInfoForBBox ( const QgsRectangle rasterBBox,
const QgsRectangle featureBBox,
double  cellSizeX,
double  cellSizeY,
int &  offsetX,
int &  offsetY,
int &  nCellsX,
int &  nCellsY 
) const [private]

Analysis what cells need to be considered to cover the bounding box of a feature.

Returns:
0 in case of success

Definition at line 221 of file qgszonalstatistics.cpp.

References QgsRectangle::intersect(), QgsRectangle::isEmpty(), QgsRectangle::xMaximum(), QgsRectangle::xMinimum(), QgsRectangle::yMaximum(), and QgsRectangle::yMinimum().

Referenced by calculateStatistics().

void QgsZonalStatistics::statisticsFromMiddlePointTest ( void *  band,
QgsGeometry poly,
int  pixelOffsetX,
int  pixelOffsetY,
int  nCellsX,
int  nCellsY,
double  cellSizeX,
double  cellSizeY,
const QgsRectangle rasterBBox,
double &  sum,
double &  count 
) [private]

Returns statistics by considering the pixels where the center point is within the polygon (fast)

Definition at line 245 of file qgszonalstatistics.cpp.

References QgsGeometry::contains(), mInputNodataValue, QgsRectangle::xMinimum(), and QgsRectangle::yMaximum().

void QgsZonalStatistics::statisticsFromMiddlePointTest_improved ( void *  band,
QgsGeometry poly,
int  pixelOffsetX,
int  pixelOffsetY,
int  nCellsX,
int  nCellsY,
double  cellSizeX,
double  cellSizeY,
const QgsRectangle rasterBBox,
double &  sum,
double &  count 
) [private]
void QgsZonalStatistics::statisticsFromPreciseIntersection ( void *  band,
QgsGeometry poly,
int  pixelOffsetX,
int  pixelOffsetY,
int  nCellsX,
int  nCellsY,
double  cellSizeX,
double  cellSizeY,
const QgsRectangle rasterBBox,
double &  sum,
double &  count 
) [private]

Returns statistics with precise pixel - polygon intersection test (slow)

Definition at line 278 of file qgszonalstatistics.cpp.

References QgsGeometry::area(), QgsGeometry::fromRect(), QgsGeometry::intersection(), QgsRectangle::xMinimum(), and QgsRectangle::yMaximum().

Referenced by calculateStatistics().


Member Data Documentation

Definition at line 62 of file qgszonalstatistics.h.

Referenced by calculateStatistics().

The nodata value of the input layer.

Definition at line 64 of file qgszonalstatistics.h.

Referenced by calculateStatistics(), statisticsFromMiddlePointTest(), and statisticsFromMiddlePointTest_improved().

Definition at line 61 of file qgszonalstatistics.h.

Referenced by calculateStatistics().

Raster band to calculate statistics from (defaults to 1)

Definition at line 60 of file qgszonalstatistics.h.

Referenced by calculateStatistics().

Definition at line 58 of file qgszonalstatistics.h.

Referenced by calculateStatistics().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines