QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsrasteranalysisutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasteranalysisutils.h
3 ---------------------
4 Date : June 2018
5 Copyright : (C) 2018 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSRASTERANALYSISUTILS_H
17#define QGSRASTERANALYSISUTILS_H
18
19#include "qgis_analysis.h"
20#include "qgis.h"
21
22#include <functional>
23#include <memory>
24#include <vector>
25
26#define SIP_NO_FILE
27
29
31class QgsGeometry;
32class QgsRectangle;
36class QgsFeedback;
37class QgsRasterBlock;
38
39namespace QgsRasterAnalysisUtils
40{
41
45 void cellInfoForBBox( const QgsRectangle &rasterBBox, const QgsRectangle &featureBBox, double cellSizeX, double cellSizeY, int &nCellsX, int &nCellsY,
46 int rasterWidth, int rasterHeight,
47 QgsRectangle &rasterBlockExtent );
48
50 void statisticsFromMiddlePointTest( QgsRasterInterface *rasterInterface, int rasterBand, const QgsGeometry &poly, int nCellsX, int nCellsY,
51 double cellSizeX, double cellSizeY, const QgsRectangle &rasterBBox, const std::function<void( double )> &addValue, bool skipNodata = true );
52
54 void statisticsFromPreciseIntersection( QgsRasterInterface *rasterInterface, int rasterBand, const QgsGeometry &poly, int nCellsX, int nCellsY,
55 double cellSizeX, double cellSizeY, const QgsRectangle &rasterBBox, const std::function<void( double, double )> &addValue, bool skipNodata = true );
56
58 bool validPixel( double value );
59
61 void mapToPixel( const double x, const double y, const QgsRectangle bounds, const double unitsPerPixelX, const double unitsPerPixelY, int &px, int &py );
62
64 void pixelToMap( const int px, const int py, const QgsRectangle bounds, const double unitsPerPixelX, const double unitsPerPixelY, double &x, double &y );
65
70 std::unique_ptr< QgsProcessingParameterDefinition > createRasterTypeParameter( const QString &name,
71 const QString &description,
73
78 Qgis::DataType rasterTypeChoiceToDataType( int choice );
79
80 struct RasterLogicInput
81 {
82 std::unique_ptr< QgsRasterInterface > sourceDataProvider;
83 std::unique_ptr< QgsRasterProjector> projector;
84 QgsRasterInterface *interface = nullptr;
85 bool hasNoDataValue = false;
86 std::vector< int > bands { 1 };
87 };
88
89 ANALYSIS_EXPORT void applyRasterLogicOperator( const std::vector< QgsRasterAnalysisUtils::RasterLogicInput > &inputs, QgsRasterDataProvider *destinationRaster, double outputNoDataValue, const bool treatNoDataAsFalse,
90 int width, int height, const QgsRectangle &extent, QgsFeedback *feedback,
91 std::function<void( const std::vector< std::unique_ptr< QgsRasterBlock > > &, bool &, bool &, int, int, bool )> &applyLogicFunc,
92 qgssize &noDataCount, qgssize &trueCount, qgssize &falseCount );
93
97 std::vector<double> getCellValuesFromBlockStack( const std::vector< std::unique_ptr< QgsRasterBlock > > &inputBlocks, int &row, int &col, bool &noDataInStack );
98
102 enum CellValueStatisticMethods
103 {
104 Sum,
105 Count,
106 Mean,
107 Median,
108 StandardDeviation,
109 Variance,
110 Minimum,
111 Maximum,
112 Minority,
113 Majority,
114 Range,
115 Variety
116 };
117
121 double meanFromCellValues( std::vector<double> &cellValues, int stackSize );
122
126 double medianFromCellValues( std::vector<double> &cellValues, int stackSize );
127
131 double stddevFromCellValues( std::vector<double> &cellValues, int stackSize );
132
136 double varianceFromCellValues( std::vector<double> &cellValues, int stackSize );
137
141 double maximumFromCellValues( std::vector<double> &cellValues );
142
146 double minimumFromCellValues( std::vector<double> &cellValues );
147
151 double majorityFromCellValues( std::vector<double> &cellValues, const double noDataValue, int stackSize );
152
156 double minorityFromCellValues( std::vector<double> &cellValues, const double noDataValue, int stackSize );
157
161 double rangeFromCellValues( std::vector<double> &cellValues );
162
166 double varietyFromCellValues( std::vector<double> &cellValues );
167
168 enum CellValuePercentileMethods
169 {
170 NearestRankPercentile,
171 InterpolatedPercentileInc,
172 InterpolatedPercentileExc
173 };
174
179 double nearestRankPercentile( std::vector<double> &cellValues, int stackSize, double percentile );
180
186 double interpolatedPercentileInc( std::vector<double> &cellValues, int stackSize, double percentile );
187
193 double interpolatedPercentileExc( std::vector<double> &cellValues, int stackSize, double percentile, double noDataValue );
194
195 enum CellValuePercentRankMethods
196 {
197 InterpolatedPercentRankInc,
198 InterpolatedPercentRankExc
199 };
200
206 double interpolatedPercentRankInc( std::vector<double> &cellValues, int stackSize, double value, double noDataValue );
207
213 double interpolatedPercentRankExc( std::vector<double> &cellValues, int stackSize, double value, double noDataValue );
214
215}
216
217
219
220#endif // QGSRASTERANALYSISUTILS_H
DataType
Raster data types.
Definition: qgis.h:129
@ Float32
Thirty two bit floating point (float)
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Base class for the definition of processing parameters.
Raster data container.
Base class for raster data providers.
Base class for processing filters like renderers, reprojector, resampler etc.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
A rectangle specified with double values.
Definition: qgsrectangle.h:42
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...
Definition: qgis.h:3032