QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsalgorithmrandomraster.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmrandomraster.cpp
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
19
20#include <limits>
21#include <random>
22
23#include "qgsrasterfilewriter.h"
24#include "qgsstringutils.h"
25
27
28//
29// QgsRandomRasterAlgorithmBase
30//
31QString QgsRandomRasterAlgorithmBase::group() const
32{
33 return QObject::tr( "Raster creation" );
34}
35
36QString QgsRandomRasterAlgorithmBase::groupId() const
37{
38 return QStringLiteral( "rastercreation" );
39}
40
41void QgsRandomRasterAlgorithmBase::initAlgorithm( const QVariantMap & )
42{
43 addParameter( new QgsProcessingParameterExtent( QStringLiteral( "EXTENT" ), QObject::tr( "Desired extent" ) ) );
44 addParameter( new QgsProcessingParameterCrs( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "ProjectCrs" ) ) );
45 addParameter( new QgsProcessingParameterNumber( QStringLiteral( "PIXEL_SIZE" ), QObject::tr( "Pixel size" ), Qgis::ProcessingNumberParameterType::Double, 1, false, 0 ) );
46
47 //add specific parameters
48 addAlgorithmParams();
49
50 // backwards compatibility parameter
51 // TODO QGIS 4: remove parameter and related logic
52 auto createOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral( "CREATE_OPTIONS" ), QObject::tr( "Creation options" ), QVariant(), false, true );
53 createOptsParam->setMetadata( QVariantMap( { { QStringLiteral( "widget_wrapper" ), QVariantMap( { { QStringLiteral( "widget_type" ), QStringLiteral( "rasteroptions" ) } } ) } } ) );
54 createOptsParam->setFlags( createOptsParam->flags() | Qgis::ProcessingParameterFlag::Hidden );
55 addParameter( createOptsParam.release() );
56
57 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral( "CREATION_OPTIONS" ), QObject::tr( "Creation options" ), QVariant(), false, true );
58 creationOptsParam->setMetadata( QVariantMap( { { QStringLiteral( "widget_wrapper" ), QVariantMap( { { QStringLiteral( "widget_type" ), QStringLiteral( "rasteroptions" ) } } ) } } ) );
59 creationOptsParam->setFlags( creationOptsParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
60 addParameter( creationOptsParam.release() );
61
62 addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Output raster" ) ) );
63}
64
65bool QgsRandomRasterAlgorithmBase::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
66{
67 Q_UNUSED( feedback );
68 mCrs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context );
69 mExtent = parameterAsExtent( parameters, QStringLiteral( "EXTENT" ), context, mCrs );
70 mPixelSize = parameterAsDouble( parameters, QStringLiteral( "PIXEL_SIZE" ), context );
71
72 if ( mPixelSize <= 0 )
73 {
74 throw QgsProcessingException( QObject::tr( "Pixel size must be greater than 0." ) );
75 }
76
77 return true;
78}
79
80QVariantMap QgsRandomRasterAlgorithmBase::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
81{
82 const int typeId = parameterAsInt( parameters, QStringLiteral( "OUTPUT_TYPE" ), context );
83 //prepare specific parameters
84 mRasterDataType = getRasterDataType( typeId );
85 prepareRandomParameters( parameters, context );
86
87 std::random_device rd {};
88 std::mt19937 mersenneTwister { rd() };
89
90 QString creationOptions = parameterAsString( parameters, QStringLiteral( "CREATION_OPTIONS" ), context ).trimmed();
91 // handle backwards compatibility parameter CREATE_OPTIONS
92 const QString optionsString = parameterAsString( parameters, QStringLiteral( "CREATE_OPTIONS" ), context );
93 if ( !optionsString.isEmpty() )
94 creationOptions = optionsString;
95
96 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
97 const QFileInfo fi( outputFile );
98 const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
99
100 // round up width and height to the nearest integer as GDAL does (e.g. in gdal_rasterize)
101 // see https://github.com/qgis/QGIS/issues/43547
102 const int rows = static_cast<int>( 0.5 + mExtent.height() / mPixelSize );
103 const int cols = static_cast<int>( 0.5 + mExtent.width() / mPixelSize );
104
105 //build new raster extent based on number of columns and cellsize
106 //this prevents output cellsize being calculated too small
107 const QgsRectangle rasterExtent = QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
108
109 auto writer = std::make_unique<QgsRasterFileWriter>( outputFile );
110 writer->setOutputProviderKey( QStringLiteral( "gdal" ) );
111 if ( !creationOptions.isEmpty() )
112 {
113 writer->setCreationOptions( creationOptions.split( '|' ) );
114 }
115
116 writer->setOutputFormat( outputFormat );
117 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
118 if ( !provider )
119 throw QgsProcessingException( QObject::tr( "Could not create raster output: %1" ).arg( outputFile ) );
120 if ( !provider->isValid() )
121 throw QgsProcessingException( QObject::tr( "Could not create raster output %1: %2" ).arg( outputFile, provider->error().message( QgsErrorMessage::Text ) ) );
122
123 const double step = rows > 0 ? 100.0 / rows : 1;
124
125 for ( int row = 0; row < rows; row++ )
126 {
127 if ( feedback->isCanceled() )
128 {
129 break;
130 }
131 //prepare raw data depending on raster data type
132 QgsRasterBlock block( mRasterDataType, cols, 1 );
133 switch ( mRasterDataType )
134 {
136 {
137 std::vector<quint8> byteRow( cols );
138 for ( int col = 0; col < cols; col++ )
139 {
140 byteRow[col] = static_cast<quint8>( generateRandomLongValue( mersenneTwister ) );
141 }
142 block.setData( QByteArray( reinterpret_cast<const char *>( byteRow.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Byte ) * cols ) );
143 break;
144 }
146 {
147 std::vector<qint8> int8Row( cols );
148 for ( int col = 0; col < cols; col++ )
149 {
150 int8Row[col] = static_cast<qint8>( generateRandomLongValue( mersenneTwister ) );
151 }
152 block.setData( QByteArray( reinterpret_cast<const char *>( int8Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Int8 ) * cols ) );
153 break;
154 }
156 {
157 std::vector<qint16> int16Row( cols );
158 for ( int col = 0; col < cols; col++ )
159 {
160 int16Row[col] = static_cast<qint16>( generateRandomLongValue( mersenneTwister ) );
161 }
162 block.setData( QByteArray( reinterpret_cast<const char *>( int16Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Int16 ) * cols ) );
163 break;
164 }
166 {
167 std::vector<quint16> uInt16Row( cols );
168 for ( int col = 0; col < cols; col++ )
169 {
170 uInt16Row[col] = static_cast<quint16>( generateRandomLongValue( mersenneTwister ) );
171 }
172 block.setData( QByteArray( reinterpret_cast<const char *>( uInt16Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::UInt16 ) * cols ) );
173 break;
174 }
176 {
177 std::vector<qint32> int32Row( cols );
178 for ( int col = 0; col < cols; col++ )
179 {
180 int32Row[col] = generateRandomLongValue( mersenneTwister );
181 }
182 block.setData( QByteArray( reinterpret_cast<const char *>( int32Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Int32 ) * cols ) );
183 break;
184 }
186 {
187 std::vector<quint32> uInt32Row( cols );
188 for ( int col = 0; col < cols; col++ )
189 {
190 uInt32Row[col] = static_cast<quint32>( generateRandomLongValue( mersenneTwister ) );
191 }
192 block.setData( QByteArray( reinterpret_cast<const char *>( uInt32Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::UInt32 ) * cols ) );
193 break;
194 }
196 {
197 std::vector<float> float32Row( cols );
198 for ( int col = 0; col < cols; col++ )
199 {
200 float32Row[col] = static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
201 }
202 block.setData( QByteArray( reinterpret_cast<const char *>( float32Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Float32 ) * cols ) );
203 break;
204 }
206 {
207 std::vector<double> float64Row( cols );
208 for ( int col = 0; col < cols; col++ )
209 {
210 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
211 }
212 block.setData( QByteArray( reinterpret_cast<const char *>( float64Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Float64 ) * cols ) );
213 break;
214 }
215 default:
216 break;
217 }
218 if ( !provider->writeBlock( &block, 1, 0, row ) )
219 {
220 throw QgsProcessingException( QObject::tr( "Could not write raster block: %1" ).arg( provider->error().summary() ) );
221 }
222 feedback->setProgress( row * step );
223 }
224
225 QVariantMap outputs;
226 outputs.insert( QStringLiteral( "OUTPUT" ), outputFile );
227 return outputs;
228}
229
230//
231//QgsRandomUniformRasterAlgorithm
232//
233QString QgsRandomUniformRasterAlgorithm::name() const
234{
235 return QStringLiteral( "createrandomuniformrasterlayer" );
236}
237
238QString QgsRandomUniformRasterAlgorithm::displayName() const
239{
240 return QObject::tr( "Create random raster layer (uniform distribution)" );
241}
242
243QStringList QgsRandomUniformRasterAlgorithm::tags() const
244{
245 return QObject::tr( "raster,create,random" ).split( ',' );
246}
247
248QString QgsRandomUniformRasterAlgorithm::shortHelpString() const
249{
250 return QObject::tr( "This algorithm generates a raster layer for a given extent and cell size "
251 "filled with random values.\n"
252 "By default, the values will range between the minimum and "
253 "maximum value of the specified output raster type. This can "
254 "be overridden by using the advanced parameters for lower and "
255 "upper bound value. If the bounds have the same value or both "
256 "are zero (default) the algorithm will create random values in "
257 "the full value range of the chosen raster data type. "
258 "Choosing bounds outside the acceptable range of the output "
259 "raster type will abort the algorithm." );
260}
261
262QString QgsRandomUniformRasterAlgorithm::shortDescription() const
263{
264 return QObject::tr( "Generates a raster layer for a given extent and cell size "
265 "filled with random values." );
266}
267
268QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance() const
269{
270 return new QgsRandomUniformRasterAlgorithm();
271}
272
273void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
274{
275 QStringList rasterDataTypes = QStringList();
276 rasterDataTypes << QStringLiteral( "Byte" )
277 << QStringLiteral( "Integer16" )
278 << QStringLiteral( "Unsigned Integer16" )
279 << QStringLiteral( "Integer32" )
280 << QStringLiteral( "Unsigned Integer32" )
281 << QStringLiteral( "Float32" )
282 << QStringLiteral( "Float64" );
283
284 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 5, false );
285 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
286 addParameter( rasterTypeParameter.release() );
287
288 auto lowerBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "LOWER_BOUND" ), QStringLiteral( "Lower bound for random number range" ), Qgis::ProcessingNumberParameterType::Double, QVariant(), true );
289 lowerBoundParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
290 addParameter( lowerBoundParameter.release() );
291
292 auto upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "UPPER_BOUND" ), QStringLiteral( "Upper bound for random number range" ), Qgis::ProcessingNumberParameterType::Double, QVariant(), true );
293 upperBoundParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
294 addParameter( upperBoundParameter.release() );
295}
296
297Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType( int typeId )
298{
299 switch ( typeId )
300 {
301 case 0:
303 case 1:
305 case 2:
307 case 3:
309 case 4:
311 case 5:
313 case 6:
315 default:
317 }
318}
319
320bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
321{
322 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral( "UPPER_BOUND" ), context );
323 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral( "LOWER_BOUND" ), context );
324
325 if ( mRandomLowerBound > mRandomUpperBound )
326 throw QgsProcessingException( QObject::tr( "The chosen lower bound for random number range is greater than the upper bound. The lower bound value must be smaller than the upper bound value." ) );
327
328 const int typeId = parameterAsInt( parameters, QStringLiteral( "OUTPUT_TYPE" ), context );
329 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
330
331 switch ( rasterDataType )
332 {
334 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
335 throw QgsProcessingException( QObject::tr( "Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint8>::min() ).arg( std::numeric_limits<quint8>::max() ).arg( QLatin1String( "Byte" ) ) );
336 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
337 {
338 //if parameters unset (=both are 0 or equal) --> use the whole value range
339 mRandomUpperBound = std::numeric_limits<quint8>::max();
340 mRandomLowerBound = std::numeric_limits<quint8>::min();
341 }
342 break;
344 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
345 throw QgsProcessingException( QObject::tr( "Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint8>::min() ).arg( std::numeric_limits<qint8>::max() ).arg( QLatin1String( "Int8" ) ) );
346 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
347 {
348 //if parameters unset (=both are 0 or equal) --> use the whole value range
349 mRandomUpperBound = std::numeric_limits<qint8>::max();
350 mRandomLowerBound = std::numeric_limits<qint8>::min();
351 }
352 break;
354 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
355 throw QgsProcessingException( QObject::tr( "Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint16>::min() ).arg( std::numeric_limits<qint16>::max() ).arg( QLatin1String( "Integer16" ) ) );
356 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
357 {
358 mRandomUpperBound = std::numeric_limits<qint16>::max();
359 mRandomLowerBound = std::numeric_limits<qint16>::min();
360 }
361 break;
363 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
364 throw QgsProcessingException( QObject::tr( "Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint16>::min() ).arg( std::numeric_limits<quint16>::max() ).arg( QLatin1String( "Unsigned Integer16" ) ) );
365 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
366 {
367 mRandomUpperBound = std::numeric_limits<quint16>::max();
368 mRandomLowerBound = std::numeric_limits<quint16>::min();
369 }
370 break;
372 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
373 throw QgsProcessingException( QObject::tr( "Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint32>::min() ).arg( std::numeric_limits<qint32>::max() ).arg( QLatin1String( "Integer32" ) ) );
374 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
375 {
376 mRandomUpperBound = std::numeric_limits<qint32>::max();
377 mRandomLowerBound = std::numeric_limits<qint32>::min();
378 }
379 break;
381 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
382 throw QgsProcessingException( QObject::tr( "Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint32>::min() ).arg( std::numeric_limits<quint32>::max() ).arg( QLatin1String( "Unsigned Integer32" ) ) );
383 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
384 {
385 mRandomUpperBound = std::numeric_limits<quint32>::max();
386 mRandomLowerBound = std::numeric_limits<quint32>::min();
387 }
388 break;
390 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
391 {
392 mRandomUpperBound = std::numeric_limits<float>::max();
393 mRandomLowerBound = std::numeric_limits<float>::min();
394 }
395 break;
397 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
398 {
399 mRandomUpperBound = std::numeric_limits<double>::max();
400 mRandomLowerBound = std::numeric_limits<double>::min();
401 }
402 break;
410 break;
411 }
412
413 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
414 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
415
416 return true;
417}
418
419long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
420{
421 return mRandomUniformIntDistribution( mersenneTwister );
422}
423
424double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
425{
426 return mRandomUniformDoubleDistribution( mersenneTwister );
427}
428
429//
430// QgsRandomBinomialRasterAlgorithm
431//
432QString QgsRandomBinomialRasterAlgorithm::name() const
433{
434 return QStringLiteral( "createrandombinomialrasterlayer" );
435}
436
437QString QgsRandomBinomialRasterAlgorithm::displayName() const
438{
439 return QObject::tr( "Create random raster layer (binomial distribution)" );
440}
441
442QStringList QgsRandomBinomialRasterAlgorithm::tags() const
443{
444 return QObject::tr( "raster,create,binomial,random" ).split( ',' );
445}
446
447QString QgsRandomBinomialRasterAlgorithm::shortHelpString() const
448{
449 return QObject::tr( "This algorithm generates a raster layer for a given extent and cell size "
450 "filled with binomially distributed random values.\n"
451 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
452 "This can be overridden by using the advanced parameter for N and probability. "
453 "The raster data type is set to Integer types (Integer16 by default). "
454 "The binomial distribution random values are defined as positive integer numbers. "
455 "A floating point raster will represent a cast of integer values "
456 "to floating point." );
457}
458
459QString QgsRandomBinomialRasterAlgorithm::shortDescription() const
460{
461 return QObject::tr( "Generates a raster layer for a given extent and cell size "
462 "filled with binomially distributed random values." );
463}
464
465QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance() const
466{
467 return new QgsRandomBinomialRasterAlgorithm();
468}
469
470
471void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams()
472{
473 QStringList rasterDataTypes = QStringList();
474 rasterDataTypes << QStringLiteral( "Integer16" )
475 << QStringLiteral( "Unsigned Integer16" )
476 << QStringLiteral( "Integer32" )
477 << QStringLiteral( "Unsigned Integer32" )
478 << QStringLiteral( "Float32" )
479 << QStringLiteral( "Float64" );
480
481 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
482 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
483 addParameter( rasterTypeParameter.release() );
484
485 auto nParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "N" ), QStringLiteral( "N" ), Qgis::ProcessingNumberParameterType::Integer, 10, true, 0 );
486 nParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
487 addParameter( nParameter.release() );
488
489 auto probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "PROBABILITY" ), QStringLiteral( "Probability" ), Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0 );
490 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
491 addParameter( probabilityParameter.release() );
492}
493
494Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType( int typeId )
495{
496 switch ( typeId )
497 {
498 case 0:
500 case 1:
502 case 2:
504 case 3:
506 case 4:
508 case 5:
510 default:
512 }
513}
514
515bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
516{
517 const int n = parameterAsInt( parameters, QStringLiteral( "N" ), context );
518 const double probability = parameterAsDouble( parameters, QStringLiteral( "PROBABILITY" ), context );
519 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
520 return true;
521}
522
523long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
524{
525 return mRandombinomialDistribution( mersenneTwister );
526}
527
528double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
529{
530 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
531}
532
533//
534// QgsRandomExponentialRasterAlgorithm
535//
536QString QgsRandomExponentialRasterAlgorithm::name() const
537{
538 return QStringLiteral( "createrandomexponentialrasterlayer" );
539}
540
541QString QgsRandomExponentialRasterAlgorithm::displayName() const
542{
543 return QObject::tr( "Create random raster layer (exponential distribution)" );
544}
545
546QStringList QgsRandomExponentialRasterAlgorithm::tags() const
547{
548 return QObject::tr( "raster,create,random,exponential" ).split( ',' );
549}
550
551QString QgsRandomExponentialRasterAlgorithm::shortHelpString() const
552{
553 return QObject::tr( "This algorithm generates a raster layer for a given extent and cell size "
554 "filled with exponentially distributed random values.\n"
555 "By default, the values will be chosen given a lambda of 1.0. "
556 "This can be overridden by using the advanced parameter for lambda. "
557 "The raster data type is set to Float32 by default as "
558 "the exponential distribution random values are floating point numbers." );
559}
560
561QString QgsRandomExponentialRasterAlgorithm::shortDescription() const
562{
563 return QObject::tr( "Generates a raster layer for a given extent and cell size "
564 "filled with exponentially distributed random values." );
565}
566
567QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance() const
568{
569 return new QgsRandomExponentialRasterAlgorithm();
570}
571
572
573void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
574{
575 QStringList rasterDataTypes = QStringList();
576 rasterDataTypes << QStringLiteral( "Float32" )
577 << QStringLiteral( "Float64" );
578
579 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
580 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
581 addParameter( rasterTypeParameter.release() );
582
583 auto lambdaParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "LAMBDA" ), QStringLiteral( "Lambda" ), Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
584 lambdaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
585 addParameter( lambdaParameter.release() );
586}
587
588Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType( int typeId )
589{
590 switch ( typeId )
591 {
592 case 0:
594 case 1:
596 default:
598 }
599}
600
601bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
602{
603 const double lambda = parameterAsDouble( parameters, QStringLiteral( "LAMBDA" ), context );
604 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
605 return true;
606}
607
608long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
609{
610 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
611}
612
613double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
614{
615 return mRandomExponentialDistribution( mersenneTwister );
616}
617
618//
619// QgsRandomGammaRasterAlgorithm
620//
621QString QgsRandomGammaRasterAlgorithm::name() const
622{
623 return QStringLiteral( "createrandomgammarasterlayer" );
624}
625
626QString QgsRandomGammaRasterAlgorithm::displayName() const
627{
628 return QObject::tr( "Create random raster layer (gamma distribution)" );
629}
630
631QStringList QgsRandomGammaRasterAlgorithm::tags() const
632{
633 return QObject::tr( "raster,create,random,gamma" ).split( ',' );
634}
635
636QString QgsRandomGammaRasterAlgorithm::shortHelpString() const
637{
638 return QObject::tr( "This algorithm generates a raster layer for a given extent and cell size "
639 "filled with gamma distributed random values.\n"
640 "By default, the values will be chosen given an alpha and beta value of 1.0. "
641 "This can be overridden by using the advanced parameter for alpha and beta. "
642 "The raster data type is set to Float32 by default as "
643 "the gamma distribution random values are floating point numbers." );
644}
645
646QString QgsRandomGammaRasterAlgorithm::shortDescription() const
647{
648 return QObject::tr( "Generates a raster layer for a given extent and cell size "
649 "filled with gamma distributed random values." );
650}
651
652QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance() const
653{
654 return new QgsRandomGammaRasterAlgorithm();
655}
656
657
658void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
659{
660 QStringList rasterDataTypes = QStringList();
661 rasterDataTypes << QStringLiteral( "Float32" )
662 << QStringLiteral( "Float64" );
663
664 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
665 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
666 addParameter( rasterTypeParameter.release() );
667
668 auto alphaParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "ALPHA" ), QStringLiteral( "Alpha" ), Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
669 alphaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
670 addParameter( alphaParameter.release() );
671
672 auto betaParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "BETA" ), QStringLiteral( "Beta" ), Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
673 betaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
674 addParameter( betaParameter.release() );
675}
676
677Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType( int typeId )
678{
679 switch ( typeId )
680 {
681 case 0:
683 case 1:
685 default:
687 }
688}
689
690bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
691{
692 const double alpha = parameterAsDouble( parameters, QStringLiteral( "ALPHA" ), context );
693 const double beta = parameterAsDouble( parameters, QStringLiteral( "BETA" ), context );
694 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
695 return true;
696}
697
698long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
699{
700 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
701}
702
703double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
704{
705 return mRandomGammaDistribution( mersenneTwister );
706}
707
708//
709// QgsRandomGeometricRasterAlgorithm
710//
711QString QgsRandomGeometricRasterAlgorithm::name() const
712{
713 return QStringLiteral( "createrandomgeometricrasterlayer" );
714}
715
716QString QgsRandomGeometricRasterAlgorithm::displayName() const
717{
718 return QObject::tr( "Create random raster layer (geometric distribution)" );
719}
720
721QStringList QgsRandomGeometricRasterAlgorithm::tags() const
722{
723 return QObject::tr( "raster,create,random,geometric" ).split( ',' );
724}
725
726QString QgsRandomGeometricRasterAlgorithm::shortHelpString() const
727{
728 return QObject::tr( "This algorithm generates a raster layer for a given extent and cell size "
729 "filled with geometrically distributed random values.\n"
730 "By default, the values will be chosen given a probability of 0.5. "
731 "This can be overridden by using the advanced parameter for mean "
732 "value. The raster data type is set to Integer types (Integer16 by default). "
733 "The geometric distribution random values are defined as positive integer numbers. "
734 "A floating point raster will represent a cast of "
735 "integer values to floating point." );
736}
737
738QString QgsRandomGeometricRasterAlgorithm::shortDescription() const
739{
740 return QObject::tr( "Generates a raster layer for a given extent and cell size "
741 "filled with geometrically distributed random values." );
742}
743
744QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance() const
745{
746 return new QgsRandomGeometricRasterAlgorithm();
747}
748
749
750void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
751{
752 QStringList rasterDataTypes = QStringList();
753 rasterDataTypes << QStringLiteral( "Integer16" )
754 << QStringLiteral( "Unsigned Integer16" )
755 << QStringLiteral( "Integer32" )
756 << QStringLiteral( "Unsigned Integer32" )
757 << QStringLiteral( "Float32" )
758 << QStringLiteral( "Float64" );
759
760 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
761 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
762 addParameter( rasterTypeParameter.release() );
763
764 auto probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "PROBABILITY" ), QStringLiteral( "Probability" ), Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0.00001 );
765 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
766 addParameter( probabilityParameter.release() );
767}
768
769Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType( int typeId )
770{
771 switch ( typeId )
772 {
773 case 0:
775 case 1:
777 case 2:
779 case 3:
781 case 4:
783 case 5:
785 default:
787 }
788}
789
790bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
791{
792 const double probability = parameterAsDouble( parameters, QStringLiteral( "PROBABILITY" ), context );
793 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
794 return true;
795}
796
797long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
798{
799 return mRandomGeometricDistribution( mersenneTwister );
800}
801
802double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
803{
804 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
805}
806
807//
808// QgsRandomNegativeBinomialRasterAlgorithm
809//
810QString QgsRandomNegativeBinomialRasterAlgorithm::name() const
811{
812 return QStringLiteral( "createrandomnegativebinomialrasterlayer" );
813}
814
815QString QgsRandomNegativeBinomialRasterAlgorithm::displayName() const
816{
817 return QObject::tr( "Create random raster layer (negative binomial distribution)" );
818}
819
820QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags() const
821{
822 return QObject::tr( "raster,create,random,negative,binomial,negative-binomial" ).split( ',' );
823}
824
825QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString() const
826{
827 return QObject::tr( "This algorithm generates a raster layer for a given extent and cell size "
828 "filled with negative binomially distributed random values.\n"
829 "By default, the values will be chosen given a distribution parameter k of 10.0 "
830 "and a probability of 0.5. "
831 "This can be overridden by using the advanced parameters for k and probability. "
832 "The raster data type is set to Integer types (Integer 16 by default). "
833 "The negative binomial distribution random values are defined as positive integer numbers. "
834 "A floating point raster will represent a cast of "
835 "integer values to floating point." );
836}
837
838QString QgsRandomNegativeBinomialRasterAlgorithm::shortDescription() const
839{
840 return QObject::tr( "Generates a raster layer for a given extent and cell size "
841 "filled with negative binomially distributed random values." );
842}
843
844QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance() const
845{
846 return new QgsRandomNegativeBinomialRasterAlgorithm();
847}
848
849
850void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams()
851{
852 QStringList rasterDataTypes = QStringList();
853 rasterDataTypes << QStringLiteral( "Integer16" )
854 << QStringLiteral( "Unsigned Integer16" )
855 << QStringLiteral( "Integer32" )
856 << QStringLiteral( "Unsigned Integer32" )
857 << QStringLiteral( "Float32" )
858 << QStringLiteral( "Float64" );
859
860 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
861 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
862 addParameter( rasterTypeParameter.release() );
863
864 auto kParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "K_PARAMETER" ), QStringLiteral( "Distribution parameter k" ), Qgis::ProcessingNumberParameterType::Integer, 10, true, 0.00001 );
865 kParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
866 addParameter( kParameter.release() );
867
868 auto probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "PROBABILITY" ), QStringLiteral( "Probability" ), Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0.00001 );
869 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
870 addParameter( probabilityParameter.release() );
871}
872
873Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType( int typeId )
874{
875 switch ( typeId )
876 {
877 case 0:
879 case 1:
881 case 2:
883 case 3:
885 case 4:
887 case 5:
889 default:
891 }
892}
893
894bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
895{
896 const int k = parameterAsInt( parameters, QStringLiteral( "K_PARAMETER" ), context );
897 const double probability = parameterAsDouble( parameters, QStringLiteral( "PROBABILITY" ), context );
898 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
899 return true;
900}
901
902long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
903{
904 return mRandomNegativeBinomialDistribution( mersenneTwister );
905}
906
907double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
908{
909 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
910}
911
912//
913// QgsRandomNormalRasterAlgorithm
914//
915QString QgsRandomNormalRasterAlgorithm::name() const
916{
917 return QStringLiteral( "createrandomnormalrasterlayer" );
918}
919
920QString QgsRandomNormalRasterAlgorithm::displayName() const
921{
922 return QObject::tr( "Create random raster layer (normal distribution)" );
923}
924
925QStringList QgsRandomNormalRasterAlgorithm::tags() const
926{
927 return QObject::tr( "raster,create,normal,distribution,random" ).split( ',' );
928}
929
930QString QgsRandomNormalRasterAlgorithm::shortHelpString() const
931{
932 return QObject::tr( "This algorithm generates a raster layer for a given extent and cell size "
933 "filled with normally distributed random values.\n"
934 "By default, the values will be chosen given a mean of 0.0 and "
935 "a standard deviation of 1.0. This can be overridden by "
936 "using the advanced parameters for mean and standard deviation "
937 "value. The raster data type is set to Float32 by default "
938 "as the normal distribution random values are floating point numbers." );
939}
940
941QString QgsRandomNormalRasterAlgorithm::shortDescription() const
942{
943 return QObject::tr( "Generates a raster layer for a given extent and cell size "
944 "filled with normally distributed random values." );
945}
946
947QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance() const
948{
949 return new QgsRandomNormalRasterAlgorithm();
950}
951
952void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
953{
954 QStringList rasterDataTypes = QStringList();
955 rasterDataTypes << QStringLiteral( "Float32" )
956 << QStringLiteral( "Float64" );
957
958 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
959 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
960 addParameter( rasterTypeParameter.release() );
961
962 auto meanParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "MEAN" ), QStringLiteral( "Mean of normal distribution" ), Qgis::ProcessingNumberParameterType::Double, 0, true );
963 meanParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
964 addParameter( meanParameter.release() );
965
966 auto stdevParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "STDDEV" ), QStringLiteral( "Standard deviation of normal distribution" ), Qgis::ProcessingNumberParameterType::Double, 1, true, 0 );
967 stdevParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
968 addParameter( stdevParameter.release() );
969}
970
971Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType( int typeId )
972{
973 switch ( typeId )
974 {
975 case 0:
977 case 1:
979 default:
981 }
982}
983
984bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
985{
986 const double mean = parameterAsDouble( parameters, QStringLiteral( "MEAN" ), context );
987 const double stddev = parameterAsDouble( parameters, QStringLiteral( "STDDEV" ), context );
988 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
989 return true;
990}
991
992long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
993{
994 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
995}
996
997double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
998{
999 return mRandomNormalDistribution( mersenneTwister );
1000}
1001
1002//
1003// QgsRandomPoissonRasterAlgorithm
1004//
1005QString QgsRandomPoissonRasterAlgorithm::name() const
1006{
1007 return QStringLiteral( "createrandompoissonrasterlayer" );
1008}
1009
1010QString QgsRandomPoissonRasterAlgorithm::displayName() const
1011{
1012 return QObject::tr( "Create random raster layer (poisson distribution)" );
1013}
1014
1015QStringList QgsRandomPoissonRasterAlgorithm::tags() const
1016{
1017 return QObject::tr( "raster,create,random,poisson" ).split( ',' );
1018}
1019
1020QString QgsRandomPoissonRasterAlgorithm::shortHelpString() const
1021{
1022 return QObject::tr( "This algorithm generates a raster layer for a given extent and cell size "
1023 "filled with poisson distributed random values.\n"
1024 "By default, the values will be chosen given a mean of 1.0. "
1025 "This can be overridden by using the advanced parameter for mean "
1026 "value. The raster data type is set to Integer types (Integer16 by default). "
1027 "The poisson distribution random values are positive integer numbers. "
1028 "A floating point raster will represent a cast of integer values to floating point." );
1029}
1030
1031QString QgsRandomPoissonRasterAlgorithm::shortDescription() const
1032{
1033 return QObject::tr( "Generates a raster layer for a given extent and cell size "
1034 "filled with poisson distributed random values." );
1035}
1036
1037QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance() const
1038{
1039 return new QgsRandomPoissonRasterAlgorithm();
1040}
1041
1042
1043void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
1044{
1045 QStringList rasterDataTypes = QStringList();
1046 rasterDataTypes << QStringLiteral( "Integer16" )
1047 << QStringLiteral( "Unsigned Integer16" )
1048 << QStringLiteral( "Integer32" )
1049 << QStringLiteral( "Unsigned Integer32" )
1050 << QStringLiteral( "Float32" )
1051 << QStringLiteral( "Float64" );
1052
1053 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
1054 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
1055 addParameter( rasterTypeParameter.release() );
1056
1057 auto upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral( "MEAN" ), QStringLiteral( "Mean" ), Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0 );
1058 upperBoundParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
1059 addParameter( upperBoundParameter.release() );
1060}
1061
1062Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType( int typeId )
1063{
1064 switch ( typeId )
1065 {
1066 case 0:
1067 return Qgis::DataType::Int16;
1068 case 1:
1070 case 2:
1071 return Qgis::DataType::Int32;
1072 case 3:
1074 case 4:
1076 case 5:
1078 default:
1080 }
1081}
1082
1083bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
1084{
1085 const double mean = parameterAsDouble( parameters, QStringLiteral( "MEAN" ), context );
1086 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1087 return true;
1088}
1089
1090long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1091{
1092 return mRandomPoissonDistribution( mersenneTwister );
1093}
1094
1095double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1096{
1097 return static_cast<double>( mRandomPoissonDistribution( mersenneTwister ) );
1098}
1099
DataType
Raster data types.
Definition qgis.h:372
@ CInt32
Complex Int32.
Definition qgis.h:383
@ Float32
Thirty two bit floating point (float).
Definition qgis.h:380
@ CFloat64
Complex Float64.
Definition qgis.h:385
@ Int16
Sixteen bit signed integer (qint16).
Definition qgis.h:377
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Definition qgis.h:387
@ Int8
Eight bit signed integer (qint8) (added in QGIS 3.30).
Definition qgis.h:375
@ UInt16
Sixteen bit unsigned integer (quint16).
Definition qgis.h:376
@ Byte
Eight bit unsigned integer (quint8).
Definition qgis.h:374
@ UnknownDataType
Unknown or unspecified type.
Definition qgis.h:373
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
Definition qgis.h:386
@ Int32
Thirty two bit signed integer (qint32).
Definition qgis.h:379
@ Float64
Sixty four bit floating point (double).
Definition qgis.h:381
@ CFloat32
Complex Float32.
Definition qgis.h:384
@ CInt16
Complex Int16.
Definition qgis.h:382
@ UInt32
Thirty two bit unsigned integer (quint32).
Definition qgis.h:378
@ Hidden
Parameter is hidden and should not be shown to users.
Definition qgis.h:3764
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
Definition qgis.h:3763
@ Double
Double/float values.
Definition qgis.h:3804
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:61
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A coordinate reference system parameter for processing algorithms.
A rectangular map extent parameter for processing algorithms.
A numeric parameter for processing algorithms.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
Raster data container.
static int typeSize(Qgis::DataType dataType)
Returns the size in bytes for the specified dataType.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
A rectangle specified with double values.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6607