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