QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsalgorithmrandomraster.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmrandomraster.h
3 ---------------------
4 begin : May 2020
5 copyright : (C) 2020 by Clemens Raffler
6 email : clemens dot raffler at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSRANDOMRASTERALGORITHM_H
19#define QGSRANDOMRASTERALGORITHM_H
20
21#define SIP_NO_FILE
22
23#include "qgis_sip.h"
25#include "qgsapplication.h"
26#include "random"
27
29
30class QgsRandomRasterAlgorithmBase : public QgsProcessingAlgorithm
31{
32 public:
33 QString group() const final;
34 QString groupId() const final;
35 void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) final;
36
37 protected:
38
43 virtual void addAlgorithmParams() = 0;
44
45 bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
46
50 virtual Qgis::DataType getRasterDataType( int typeId ) = 0;
51 virtual bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) = 0;
52
56 QVariantMap processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) final;
57
61 virtual long generateRandomLongValue( std::mt19937 &mersenneTwister ) = 0;
62 virtual double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) = 0;
63
64 private:
65 QgsRectangle mExtent;
67 double mPixelSize = 0;
69};
70
71
72class QgsRandomUniformRasterAlgorithm : public QgsRandomRasterAlgorithmBase
73{
74 public:
75 QgsRandomUniformRasterAlgorithm() = default;
76 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomRaster.svg" ) ); }
77 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomRaster.svg" ) ); }
78 QString name() const override;
79 QString displayName() const override;
80 QStringList tags() const override;
81 QString shortHelpString() const override;
82 QgsRandomUniformRasterAlgorithm *createInstance() const override SIP_FACTORY;
83
84 protected:
85 void addAlgorithmParams() final;
86 Qgis::DataType getRasterDataType( int typeId ) final;
87 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
88 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
89 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
90
91 private:
92 double mRandomUpperBound = 0;
93 double mRandomLowerBound = 0;
94 std::uniform_int_distribution<long> mRandomUniformIntDistribution;
95 std::uniform_real_distribution<double> mRandomUniformDoubleDistribution;
96};
97
98class QgsRandomBinomialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
99{
100 public:
101 QgsRandomBinomialRasterAlgorithm() = default;
102 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
103 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomNormalRaster.svg" ) ); }
104 QString name() const override;
105 QString displayName() const override;
106 QStringList tags() const override;
107 QString shortHelpString() const override;
108 QgsRandomBinomialRasterAlgorithm *createInstance() const override SIP_FACTORY;
109
110 protected:
111 void addAlgorithmParams() final;
112 Qgis::DataType getRasterDataType( int typeId ) final;
113 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
114 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
115 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
116
117 private:
118 std::binomial_distribution<long> mRandombinomialDistribution;
119};
120
121class QgsRandomExponentialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
122{
123 public:
124 QgsRandomExponentialRasterAlgorithm() = default;
125 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
126 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
127 QString name() const override;
128 QString displayName() const override;
129 QStringList tags() const override;
130 QString shortHelpString() const override;
131 QgsRandomExponentialRasterAlgorithm *createInstance() const override SIP_FACTORY;
132
133 protected:
134 void addAlgorithmParams() final;
135 Qgis::DataType getRasterDataType( int typeId ) final;
136 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
137 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
138 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
139
140 private:
141 std::exponential_distribution<double> mRandomExponentialDistribution;
142};
143
144
145class QgsRandomGammaRasterAlgorithm : public QgsRandomRasterAlgorithmBase
146{
147 public:
148 QgsRandomGammaRasterAlgorithm() = default;
149 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomGammaRaster.svg" ) ); }
150 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomGammaRaster.svg" ) ); }
151 QString name() const override;
152 QString displayName() const override;
153 QStringList tags() const override;
154 QString shortHelpString() const override;
155 QgsRandomGammaRasterAlgorithm *createInstance() const override SIP_FACTORY;
156
157 protected:
158 void addAlgorithmParams() final;
159 Qgis::DataType getRasterDataType( int typeId ) final;
160 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
161 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
162 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
163
164 private:
165 std::gamma_distribution<double> mRandomGammaDistribution;
166};
167
168class QgsRandomGeometricRasterAlgorithm : public QgsRandomRasterAlgorithmBase
169{
170 public:
171 QgsRandomGeometricRasterAlgorithm() = default;
172 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
173 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomExponentialRaster.svg" ) ); }
174 QString name() const override;
175 QString displayName() const override;
176 QStringList tags() const override;
177 QString shortHelpString() const override;
178 QgsRandomGeometricRasterAlgorithm *createInstance() const override SIP_FACTORY;
179
180 protected:
181 void addAlgorithmParams() override;
182 Qgis::DataType getRasterDataType( int typeId ) override;
183 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) override;
184 long generateRandomLongValue( std::mt19937 &mersenneTwister ) override;
185 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) override;
186
187 private:
188 std::geometric_distribution<long> mRandomGeometricDistribution;
189};
190
191
192class QgsRandomNegativeBinomialRasterAlgorithm : public QgsRandomRasterAlgorithmBase
193{
194 public:
195 QgsRandomNegativeBinomialRasterAlgorithm() = default;
196 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
197 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
198 QString name() const override;
199 QString displayName() const override;
200 QStringList tags() const override;
201 QString shortHelpString() const override;
202 QgsRandomNegativeBinomialRasterAlgorithm *createInstance() const override SIP_FACTORY;
203
204 protected:
205 void addAlgorithmParams() final;
206 Qgis::DataType getRasterDataType( int typeId ) final;
207 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
208 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
209 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
210
211 private:
212 std::negative_binomial_distribution<long> mRandomNegativeBinomialDistribution;
213};
214
215class QgsRandomNormalRasterAlgorithm : public QgsRandomRasterAlgorithmBase
216{
217 public:
218 QgsRandomNormalRasterAlgorithm() = default;
219 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
220 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmNormalRaster.svg" ) ); }
221 QString name() const override;
222 QString displayName() const override;
223 QStringList tags() const override;
224 QString shortHelpString() const override;
225 QgsRandomNormalRasterAlgorithm *createInstance() const override SIP_FACTORY;
226
227 protected:
228 void addAlgorithmParams() final;
229 Qgis::DataType getRasterDataType( int typeId ) final;
230 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
231 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
232 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
233
234 private:
235 std::normal_distribution<double> mRandomNormalDistribution;
236};
237
238class QgsRandomPoissonRasterAlgorithm : public QgsRandomRasterAlgorithmBase
239{
240 public:
241 QgsRandomPoissonRasterAlgorithm() = default;
242 QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/algorithms/mAlgorithmRandomPoissonRaster.svg" ) ); }
243 QString svgIconPath() const override { return QgsApplication::iconPath( QStringLiteral( "/algorithms/mAlgorithmRandomPoissonRaster.svg" ) ); }
244 QString name() const override;
245 QString displayName() const override;
246 QStringList tags() const override;
247 QString shortHelpString() const override;
248 QgsRandomPoissonRasterAlgorithm *createInstance() const override SIP_FACTORY;
249
250 protected:
251 void addAlgorithmParams() final;
252 Qgis::DataType getRasterDataType( int typeId ) final;
253 bool prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context ) final;
254 long generateRandomLongValue( std::mt19937 &mersenneTwister ) final;
255 double generateRandomDoubleValue( std::mt19937 &mersenneTwister ) final;
256
257 private:
258 std::poisson_distribution<long> mRandomPoissonDistribution;
259};
260
261
263
264#endif // QGSRANDOMRASTERALGORITHM_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
DataType
Raster data types.
Definition qgis.h:351
@ UnknownDataType
Unknown or unspecified type.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
This class represents a coordinate reference system (CRS).
Abstract base class for processing algorithms.
virtual QString group() const
Returns the name of the group this algorithm belongs to.
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm to run using the specified parameters.
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
virtual QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)=0
Runs the algorithm using the specified parameters.
virtual void initAlgorithm(const QVariantMap &configuration=QVariantMap())=0
Initializes the algorithm using the specified configuration.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
A rectangle specified with double values.
#define SIP_FACTORY
Definition qgis_sip.h:76