16#ifndef QGSRASTERANALYSISUTILS_H
17#define QGSRASTERANALYSISUTILS_H
19#include "qgis_analysis.h"
40namespace QgsRasterAnalysisUtils
46 void cellInfoForBBox(
const QgsRectangle &rasterBBox,
const QgsRectangle &featureBBox,
double cellSizeX,
double cellSizeY,
int &nCellsX,
int &nCellsY,
int rasterWidth,
int rasterHeight,
QgsRectangle &rasterBlockExtent );
49 void statisticsFromMiddlePointTest(
QgsRasterInterface *rasterInterface,
int rasterBand,
const QgsGeometry &poly,
int nCellsX,
int nCellsY,
double cellSizeX,
double cellSizeY,
const QgsRectangle &rasterBBox,
const std::function<
void(
double,
const QgsPointXY & )> &addValue,
bool skipNodata =
true );
52 void statisticsFromPreciseIntersection(
QgsRasterInterface *rasterInterface,
int rasterBand,
const QgsGeometry &poly,
int nCellsX,
int nCellsY,
double cellSizeX,
double cellSizeY,
const QgsRectangle &rasterBBox,
const std::function<
void(
double,
double,
const QgsPointXY & )> &addValue,
bool skipNodata =
true );
55 bool validPixel(
double value );
58 void mapToPixel(
const double x,
const double y,
const QgsRectangle bounds,
const double unitsPerPixelX,
const double unitsPerPixelY,
int &px,
int &py );
61 void pixelToMap(
const int px,
const int py,
const QgsRectangle bounds,
const double unitsPerPixelX,
const double unitsPerPixelY,
double &x,
double &y );
75 struct RasterLogicInput
77 std::unique_ptr<QgsRasterInterface> sourceDataProvider;
78 std::unique_ptr<QgsRasterProjector> projector;
80 bool hasNoDataValue =
false;
81 std::vector<int> bands { 1 };
84 ANALYSIS_EXPORT
void applyRasterLogicOperator(
const std::vector<QgsRasterAnalysisUtils::RasterLogicInput> &inputs,
QgsRasterDataProvider *destinationRaster,
double outputNoDataValue,
const bool treatNoDataAsFalse,
int width,
int height,
const QgsRectangle &extent,
QgsFeedback *feedback, std::function<
void(
const std::vector<std::unique_ptr<QgsRasterBlock>> &,
bool &,
bool &,
int,
int,
bool )> &applyLogicFunc,
qgssize &noDataCount,
qgssize &trueCount,
qgssize &falseCount );
89 std::vector<double> getCellValuesFromBlockStack(
const std::vector<std::unique_ptr<QgsRasterBlock>> &inputBlocks,
int &row,
int &col,
bool &noDataInStack );
94 enum CellValueStatisticMethods
113 double meanFromCellValues( std::vector<double> &cellValues,
int stackSize );
118 double medianFromCellValues( std::vector<double> &cellValues,
int stackSize );
123 double stddevFromCellValues( std::vector<double> &cellValues,
int stackSize );
128 double varianceFromCellValues( std::vector<double> &cellValues,
int stackSize );
133 double maximumFromCellValues( std::vector<double> &cellValues );
138 double minimumFromCellValues( std::vector<double> &cellValues );
143 double majorityFromCellValues( std::vector<double> &cellValues,
const double noDataValue,
int stackSize );
148 double minorityFromCellValues( std::vector<double> &cellValues,
const double noDataValue,
int stackSize );
153 double rangeFromCellValues( std::vector<double> &cellValues );
158 double varietyFromCellValues( std::vector<double> &cellValues );
160 enum CellValuePercentileMethods
162 NearestRankPercentile,
163 InterpolatedPercentileInc,
164 InterpolatedPercentileExc
171 double nearestRankPercentile( std::vector<double> &cellValues,
int stackSize,
double percentile );
178 double interpolatedPercentileInc( std::vector<double> &cellValues,
int stackSize,
double percentile );
185 double interpolatedPercentileExc( std::vector<double> &cellValues,
int stackSize,
double percentile,
double noDataValue );
187 enum CellValuePercentRankMethods
189 InterpolatedPercentRankInc,
190 InterpolatedPercentRankExc
198 double interpolatedPercentRankInc( std::vector<double> &cellValues,
int stackSize,
double value,
double noDataValue );
205 double interpolatedPercentRankExc( std::vector<double> &cellValues,
int stackSize,
double value,
double noDataValue );
DataType
Raster data types.
@ Float32
Thirty two bit floating point (float)
Base class for feedback objects to be used for cancellation of something running in a worker thread.
A geometry is the spatial representation of a feature.
A class to represent a 2D point.
Base class for the definition of processing parameters.
Base class for raster data providers.
Base class for processing filters like renderers, reprojector, resampler etc.
Implements approximate projection support for optimised raster transformation.
A rectangle specified with double values.
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...