QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
Loading...
Searching...
No Matches
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 <functional>
20#include <memory>
21#include <vector>
22
23#include "qgis.h"
24#include "qgis_analysis.h"
25#include "qgspointxy.h"
26
27#define SIP_NO_FILE
28
30
32class QgsGeometry;
33class QgsRectangle;
37class QgsFeedback;
38class QgsRasterBlock;
39
40namespace QgsRasterAnalysisUtils
41{
42
46 void cellInfoForBBox(
47 const QgsRectangle &rasterBBox, const QgsRectangle &featureBBox, double cellSizeX, double cellSizeY, int &nCellsX, int &nCellsY, int rasterWidth, int rasterHeight, QgsRectangle &rasterBlockExtent
48 );
49
51 void statisticsFromMiddlePointTest(
52 QgsRasterInterface *rasterInterface,
53 int rasterBand,
54 const QgsGeometry &poly,
55 int nCellsX,
56 int nCellsY,
57 double cellSizeX,
58 double cellSizeY,
59 const QgsRectangle &rasterBBox,
60 const std::function<void( double, const QgsPointXY & )> &addValue,
61 bool skipNodata = true
62 );
63
65 void statisticsFromPreciseIntersection(
66 QgsRasterInterface *rasterInterface,
67 int rasterBand,
68 const QgsGeometry &poly,
69 int nCellsX,
70 int nCellsY,
71 double cellSizeX,
72 double cellSizeY,
73 const QgsRectangle &rasterBBox,
74 const std::function<void( double, double, const QgsPointXY & )> &addValue,
75 bool skipNodata = true
76 );
77
79 bool validPixel( double value );
80
82 void mapToPixel( const double x, const double y, const QgsRectangle bounds, const double unitsPerPixelX, const double unitsPerPixelY, int &px, int &py );
83
85 void pixelToMap( const int px, const int py, const QgsRectangle bounds, const double unitsPerPixelX, const double unitsPerPixelY, double &x, double &y );
86
91 std::unique_ptr<QgsProcessingParameterDefinition> createRasterTypeParameter( const QString &name, const QString &description, Qgis::DataType defaultType = Qgis::DataType::Float32 );
92
97 Qgis::DataType rasterTypeChoiceToDataType( int choice );
98
99 struct RasterLogicInput
100 {
101 std::unique_ptr<QgsRasterInterface> sourceDataProvider;
102 std::unique_ptr<QgsRasterProjector> projector;
103 QgsRasterInterface *interface = nullptr;
104 bool hasNoDataValue = false;
105 std::vector<int> bands { 1 };
106 };
107
108 ANALYSIS_EXPORT void applyRasterLogicOperator(
109 const std::vector<QgsRasterAnalysisUtils::RasterLogicInput> &inputs,
110 std::unique_ptr<QgsRasterDataProvider> destinationRaster,
111 double outputNoDataValue,
112 const bool treatNoDataAsFalse,
113 int width,
114 int height,
115 const QgsRectangle &extent,
116 QgsFeedback *feedback,
117 std::function<void( const std::vector<std::unique_ptr<QgsRasterBlock>> &, bool &, bool &, int, int, bool )> &applyLogicFunc,
118 qgssize &noDataCount,
119 qgssize &trueCount,
120 qgssize &falseCount
121 );
122
126 std::vector<double> getCellValuesFromBlockStack( const std::vector<std::unique_ptr<QgsRasterBlock>> &inputBlocks, int &row, int &col, bool &noDataInStack );
127
131 enum CellValueStatisticMethods
132 {
133 Sum,
134 Count,
135 Mean,
136 Median,
137 StandardDeviation,
138 Variance,
139 Minimum,
140 Maximum,
141 Minority,
142 Majority,
143 Range,
144 Variety
145 };
146
150 double meanFromCellValues( std::vector<double> &cellValues, int stackSize );
151
155 double medianFromCellValues( std::vector<double> &cellValues, int stackSize );
156
160 double stddevFromCellValues( std::vector<double> &cellValues, int stackSize );
161
165 double varianceFromCellValues( std::vector<double> &cellValues, int stackSize );
166
170 double maximumFromCellValues( std::vector<double> &cellValues );
171
175 double minimumFromCellValues( std::vector<double> &cellValues );
176
180 double majorityFromCellValues( std::vector<double> &cellValues, const double noDataValue, int stackSize );
181
185 double minorityFromCellValues( std::vector<double> &cellValues, const double noDataValue, int stackSize );
186
190 double rangeFromCellValues( std::vector<double> &cellValues );
191
195 double varietyFromCellValues( std::vector<double> &cellValues );
196
197 enum CellValuePercentileMethods
198 {
199 NearestRankPercentile,
200 InterpolatedPercentileInc,
201 InterpolatedPercentileExc
202 };
203
208 double nearestRankPercentile( std::vector<double> &cellValues, int stackSize, double percentile );
209
215 double interpolatedPercentileInc( std::vector<double> &cellValues, int stackSize, double percentile );
216
222 double interpolatedPercentileExc( std::vector<double> &cellValues, int stackSize, double percentile, double noDataValue );
223
224 enum CellValuePercentRankMethods
225 {
226 InterpolatedPercentRankInc,
227 InterpolatedPercentRankExc
228 };
229
235 double interpolatedPercentRankInc( std::vector<double> &cellValues, int stackSize, double value, double noDataValue );
236
242 double interpolatedPercentRankExc( std::vector<double> &cellValues, int stackSize, double value, double noDataValue );
243
244} // namespace QgsRasterAnalysisUtils
245
246
248
249#endif // QGSRASTERANALYSISUTILS_H
DataType
Raster data types.
Definition qgis.h:393
@ Float32
Thirty two bit floating point (float).
Definition qgis.h:401
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
A geometry is the spatial representation of a feature.
Represents a 2D point.
Definition qgspointxy.h:62
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.
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...
Definition qgis.h:7485