QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
94 }
95 
96 
98 
99 #endif // QGSRASTERANALYSISUTILS_H
Qgis::Float32
@ Float32
Thirty two bit floating point (float)
Definition: qgis.h:122
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:114
qgis.h
QgsProcessingParameterDefinition
Definition: qgsprocessingparameters.h:330
QgsRectangle
Definition: qgsrectangle.h:41
QgsRasterProjector
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
Definition: qgsrasterprojector.h:47
QgsFeedback
Definition: qgsfeedback.h:43
QgsRasterInterface
Definition: qgsrasterinterface.h:116
QgsGeometry
Definition: qgsgeometry.h:122
QgsRasterDataProvider
Definition: qgsrasterdataprovider.h:88
QgsRasterBlock
Definition: qgsrasterblock.h:36
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:723