QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
30 class QgsRasterInterface;
31 class QgsGeometry;
32 class QgsRectangle;
34 class QgsRasterProjector;
36 class QgsFeedback;
37 class QgsRasterBlock;
38 
39 namespace 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,
72  Qgis::DataType defaultType = Qgis::Float32 );
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 }
169 
170 
172 
173 #endif // QGSRASTERANALYSISUTILS_H
Qgis::Float32
@ Float32
Thirty two bit floating point (float)
Definition: qgis.h:109
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:102
qgis.h
QgsProcessingParameterDefinition
Base class for the definition of processing parameters.
Definition: qgsprocessingparameters.h:331
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsRasterProjector
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
Definition: qgsrasterprojector.h:48
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsRasterInterface
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:117
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:89
QgsRasterBlock
Raster data container.
Definition: qgsrasterblock.h:37
qgssize
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:768