QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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 "qgis_analysis.h"
20#include "qgis.h"
21#include "qgspointxy.h"
22
23#include <functional>
24#include <memory>
25#include <vector>
26
27#define SIP_NO_FILE
28
30
32class QgsGeometry;
33class QgsRectangle;
37class QgsFeedback;
38class QgsRasterBlock;
39
40namespace QgsRasterAnalysisUtils
41{
42
46 void cellInfoForBBox( const QgsRectangle &rasterBBox, const QgsRectangle &featureBBox, double cellSizeX, double cellSizeY, int &nCellsX, int &nCellsY,
47 int rasterWidth, int rasterHeight,
48 QgsRectangle &rasterBlockExtent );
49
51 void statisticsFromMiddlePointTest( QgsRasterInterface *rasterInterface, int rasterBand, const QgsGeometry &poly, int nCellsX, int nCellsY,
52 double cellSizeX, double cellSizeY, const QgsRectangle &rasterBBox, const std::function<void( double, const QgsPointXY & )> &addValue, bool skipNodata = true );
53
55 void statisticsFromPreciseIntersection( QgsRasterInterface *rasterInterface, int rasterBand, const QgsGeometry &poly, int nCellsX, int nCellsY,
56 double cellSizeX, double cellSizeY, const QgsRectangle &rasterBBox, const std::function<void( double, double, const QgsPointXY & )> &addValue, bool skipNodata = true );
57
59 bool validPixel( double value );
60
62 void mapToPixel( const double x, const double y, const QgsRectangle bounds, const double unitsPerPixelX, const double unitsPerPixelY, int &px, int &py );
63
65 void pixelToMap( const int px, const int py, const QgsRectangle bounds, const double unitsPerPixelX, const double unitsPerPixelY, double &x, double &y );
66
71 std::unique_ptr< QgsProcessingParameterDefinition > createRasterTypeParameter( const QString &name,
72 const QString &description,
74
79 Qgis::DataType rasterTypeChoiceToDataType( int choice );
80
81 struct RasterLogicInput
82 {
83 std::unique_ptr< QgsRasterInterface > sourceDataProvider;
84 std::unique_ptr< QgsRasterProjector> projector;
85 QgsRasterInterface *interface = nullptr;
86 bool hasNoDataValue = false;
87 std::vector< int > bands { 1 };
88 };
89
90 ANALYSIS_EXPORT void applyRasterLogicOperator( const std::vector< QgsRasterAnalysisUtils::RasterLogicInput > &inputs, QgsRasterDataProvider *destinationRaster, double outputNoDataValue, const bool treatNoDataAsFalse,
91 int width, int height, const QgsRectangle &extent, QgsFeedback *feedback,
92 std::function<void( const std::vector< std::unique_ptr< QgsRasterBlock > > &, bool &, bool &, int, int, bool )> &applyLogicFunc,
93 qgssize &noDataCount, qgssize &trueCount, qgssize &falseCount );
94
98 std::vector<double> getCellValuesFromBlockStack( const std::vector< std::unique_ptr< QgsRasterBlock > > &inputBlocks, int &row, int &col, bool &noDataInStack );
99
103 enum CellValueStatisticMethods
104 {
105 Sum,
106 Count,
107 Mean,
108 Median,
109 StandardDeviation,
110 Variance,
111 Minimum,
112 Maximum,
113 Minority,
114 Majority,
115 Range,
116 Variety
117 };
118
122 double meanFromCellValues( std::vector<double> &cellValues, int stackSize );
123
127 double medianFromCellValues( std::vector<double> &cellValues, int stackSize );
128
132 double stddevFromCellValues( std::vector<double> &cellValues, int stackSize );
133
137 double varianceFromCellValues( std::vector<double> &cellValues, int stackSize );
138
142 double maximumFromCellValues( std::vector<double> &cellValues );
143
147 double minimumFromCellValues( std::vector<double> &cellValues );
148
152 double majorityFromCellValues( std::vector<double> &cellValues, const double noDataValue, int stackSize );
153
157 double minorityFromCellValues( std::vector<double> &cellValues, const double noDataValue, int stackSize );
158
162 double rangeFromCellValues( std::vector<double> &cellValues );
163
167 double varietyFromCellValues( std::vector<double> &cellValues );
168
169 enum CellValuePercentileMethods
170 {
171 NearestRankPercentile,
172 InterpolatedPercentileInc,
173 InterpolatedPercentileExc
174 };
175
180 double nearestRankPercentile( std::vector<double> &cellValues, int stackSize, double percentile );
181
187 double interpolatedPercentileInc( std::vector<double> &cellValues, int stackSize, double percentile );
188
194 double interpolatedPercentileExc( std::vector<double> &cellValues, int stackSize, double percentile, double noDataValue );
195
196 enum CellValuePercentRankMethods
197 {
198 InterpolatedPercentRankInc,
199 InterpolatedPercentRankExc
200 };
201
207 double interpolatedPercentRankInc( std::vector<double> &cellValues, int stackSize, double value, double noDataValue );
208
214 double interpolatedPercentRankExc( std::vector<double> &cellValues, int stackSize, double value, double noDataValue );
215
216}
217
218
220
221#endif // QGSRASTERANALYSISUTILS_H
DataType
Raster data types.
Definition qgis.h:351
@ 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:44
A geometry is the spatial representation of a feature.
A class to represent a 2D point.
Definition qgspointxy.h:60
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:6506