QGIS API Documentation 3.41.0-Master (af5edcb665c)
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, int rasterWidth, int rasterHeight, QgsRectangle &rasterBlockExtent );
47
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 );
50
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 );
53
55 bool validPixel( double value );
56
58 void mapToPixel( const double x, const double y, const QgsRectangle bounds, const double unitsPerPixelX, const double unitsPerPixelY, int &px, int &py );
59
61 void pixelToMap( const int px, const int py, const QgsRectangle bounds, const double unitsPerPixelX, const double unitsPerPixelY, double &x, double &y );
62
67 std::unique_ptr<QgsProcessingParameterDefinition> createRasterTypeParameter( const QString &name, const QString &description, Qgis::DataType defaultType = Qgis::DataType::Float32 );
68
73 Qgis::DataType rasterTypeChoiceToDataType( int choice );
74
75 struct RasterLogicInput
76 {
77 std::unique_ptr<QgsRasterInterface> sourceDataProvider;
78 std::unique_ptr<QgsRasterProjector> projector;
79 QgsRasterInterface *interface = nullptr;
80 bool hasNoDataValue = false;
81 std::vector<int> bands { 1 };
82 };
83
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 );
85
89 std::vector<double> getCellValuesFromBlockStack( const std::vector<std::unique_ptr<QgsRasterBlock>> &inputBlocks, int &row, int &col, bool &noDataInStack );
90
94 enum CellValueStatisticMethods
95 {
96 Sum,
97 Count,
98 Mean,
99 Median,
100 StandardDeviation,
101 Variance,
102 Minimum,
103 Maximum,
104 Minority,
105 Majority,
106 Range,
107 Variety
108 };
109
113 double meanFromCellValues( std::vector<double> &cellValues, int stackSize );
114
118 double medianFromCellValues( std::vector<double> &cellValues, int stackSize );
119
123 double stddevFromCellValues( std::vector<double> &cellValues, int stackSize );
124
128 double varianceFromCellValues( std::vector<double> &cellValues, int stackSize );
129
133 double maximumFromCellValues( std::vector<double> &cellValues );
134
138 double minimumFromCellValues( std::vector<double> &cellValues );
139
143 double majorityFromCellValues( std::vector<double> &cellValues, const double noDataValue, int stackSize );
144
148 double minorityFromCellValues( std::vector<double> &cellValues, const double noDataValue, int stackSize );
149
153 double rangeFromCellValues( std::vector<double> &cellValues );
154
158 double varietyFromCellValues( std::vector<double> &cellValues );
159
160 enum CellValuePercentileMethods
161 {
162 NearestRankPercentile,
163 InterpolatedPercentileInc,
164 InterpolatedPercentileExc
165 };
166
171 double nearestRankPercentile( std::vector<double> &cellValues, int stackSize, double percentile );
172
178 double interpolatedPercentileInc( std::vector<double> &cellValues, int stackSize, double percentile );
179
185 double interpolatedPercentileExc( std::vector<double> &cellValues, int stackSize, double percentile, double noDataValue );
186
187 enum CellValuePercentRankMethods
188 {
189 InterpolatedPercentRankInc,
190 InterpolatedPercentRankExc
191 };
192
198 double interpolatedPercentRankInc( std::vector<double> &cellValues, int stackSize, double value, double noDataValue );
199
205 double interpolatedPercentRankExc( std::vector<double> &cellValues, int stackSize, double value, double noDataValue );
206
207} // namespace QgsRasterAnalysisUtils
208
209
211
212#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:6614