Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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]

Public Member Functions

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

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. More...
 
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) More...
 
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) More...
 

Private Attributes

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

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.

QgsZonalStatistics::~QgsZonalStatistics ( )

Definition at line 49 of file qgszonalstatistics.cpp.

QgsZonalStatistics::QgsZonalStatistics ( )
private

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

QString QgsZonalStatistics::mAttributePrefix
private

Definition at line 62 of file qgszonalstatistics.h.

Referenced by calculateStatistics().

float QgsZonalStatistics::mInputNodataValue
private

The nodata value of the input layer.

Definition at line 64 of file qgszonalstatistics.h.

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

QgsVectorLayer* QgsZonalStatistics::mPolygonLayer
private

Definition at line 61 of file qgszonalstatistics.h.

Referenced by calculateStatistics().

int QgsZonalStatistics::mRasterBand
private

Raster band to calculate statistics from (defaults to 1)

Definition at line 60 of file qgszonalstatistics.h.

Referenced by calculateStatistics().

QString QgsZonalStatistics::mRasterFilePath
private

Definition at line 58 of file qgszonalstatistics.h.

Referenced by calculateStatistics().


The documentation for this class was generated from the following files: