QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 mRandomUpperBound = parameterAsDouble( parameters, u"UPPER_BOUND"_s, context );
339 mRandomLowerBound = parameterAsDouble( parameters, u"LOWER_BOUND"_s, context );
340
341 if ( mRandomLowerBound > mRandomUpperBound )
342 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." ) );
343
344 const int typeId = parameterAsInt( parameters, u"OUTPUT_TYPE"_s, context );
345 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
346
347 switch ( rasterDataType )
348 {
350 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
352 QObject::tr( "Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." )
353 .arg( std::numeric_limits<quint8>::min() )
354 .arg( std::numeric_limits<quint8>::max() )
355 .arg( "Byte"_L1 )
356 );
357 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
358 {
359 //if parameters unset (=both are 0 or equal) --> use the whole value range
360 mRandomUpperBound = std::numeric_limits<quint8>::max();
361 mRandomLowerBound = std::numeric_limits<quint8>::min();
362 }
363 break;
365 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
367 QObject::tr( "Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." )
368 .arg( std::numeric_limits<qint8>::min() )
369 .arg( std::numeric_limits<qint8>::max() )
370 .arg( "Int8"_L1 )
371 );
372 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
373 {
374 //if parameters unset (=both are 0 or equal) --> use the whole value range
375 mRandomUpperBound = std::numeric_limits<qint8>::max();
376 mRandomLowerBound = std::numeric_limits<qint8>::min();
377 }
378 break;
380 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
382 QObject::tr( "Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." )
383 .arg( std::numeric_limits<qint16>::min() )
384 .arg( std::numeric_limits<qint16>::max() )
385 .arg( "Integer16"_L1 )
386 );
387 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
388 {
389 mRandomUpperBound = std::numeric_limits<qint16>::max();
390 mRandomLowerBound = std::numeric_limits<qint16>::min();
391 }
392 break;
394 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
396 QObject::tr( "Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." )
397 .arg( std::numeric_limits<quint16>::min() )
398 .arg( std::numeric_limits<quint16>::max() )
399 .arg( "Unsigned Integer16"_L1 )
400 );
401 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
402 {
403 mRandomUpperBound = std::numeric_limits<quint16>::max();
404 mRandomLowerBound = std::numeric_limits<quint16>::min();
405 }
406 break;
408 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
410 QObject::tr( "Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." )
411 .arg( std::numeric_limits<qint32>::min() )
412 .arg( std::numeric_limits<qint32>::max() )
413 .arg( "Integer32"_L1 )
414 );
415 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
416 {
417 mRandomUpperBound = std::numeric_limits<qint32>::max();
418 mRandomLowerBound = std::numeric_limits<qint32>::min();
419 }
420 break;
422 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
424 QObject::tr( "Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." )
425 .arg( std::numeric_limits<quint32>::min() )
426 .arg( std::numeric_limits<quint32>::max() )
427 .arg( "Unsigned Integer32"_L1 )
428 );
429 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
430 {
431 mRandomUpperBound = std::numeric_limits<quint32>::max();
432 mRandomLowerBound = std::numeric_limits<quint32>::min();
433 }
434 break;
436 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
437 {
438 mRandomUpperBound = std::numeric_limits<float>::max();
439 mRandomLowerBound = std::numeric_limits<float>::min();
440 }
441 break;
443 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
444 {
445 mRandomUpperBound = std::numeric_limits<double>::max();
446 mRandomLowerBound = std::numeric_limits<double>::min();
447 }
448 break;
456 break;
457 }
458
459 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
460 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
461
462 return true;
463}
464
465long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
466{
467 return mRandomUniformIntDistribution( mersenneTwister );
468}
469
470double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
471{
472 return mRandomUniformDoubleDistribution( mersenneTwister );
473}
474
475//
476// QgsRandomBinomialRasterAlgorithm
477//
478QString QgsRandomBinomialRasterAlgorithm::name() const
479{
480 return u"createrandombinomialrasterlayer"_s;
481}
482
483QString QgsRandomBinomialRasterAlgorithm::displayName() const
484{
485 return QObject::tr( "Create random raster layer (binomial distribution)" );
486}
487
488QStringList QgsRandomBinomialRasterAlgorithm::tags() const
489{
490 return QObject::tr( "raster,create,binomial,random" ).split( ',' );
491}
492
493QString QgsRandomBinomialRasterAlgorithm::shortHelpString() const
494{
495 return QObject::tr(
496 "This algorithm generates a raster layer for a given extent and cell size "
497 "filled with binomially distributed random values.\n"
498 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
499 "This can be overridden by using the advanced parameter for N and probability. "
500 "The raster data type is set to Integer types (Integer16 by default). "
501 "The binomial distribution random values are defined as positive integer numbers. "
502 "A floating point raster will represent a cast of integer values "
503 "to floating point."
504 );
505}
506
507QString QgsRandomBinomialRasterAlgorithm::shortDescription() const
508{
509 return QObject::tr(
510 "Generates a raster layer for a given extent and cell size "
511 "filled with binomially distributed random values."
512 );
513}
514
515QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance() const
516{
517 return new QgsRandomBinomialRasterAlgorithm();
518}
519
520
521void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams()
522{
523 QStringList rasterDataTypes = QStringList();
524 rasterDataTypes << u"Integer16"_s << u"Unsigned Integer16"_s << u"Integer32"_s << u"Unsigned Integer32"_s << u"Float32"_s << u"Float64"_s;
525
526 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter
527 = std::make_unique<QgsProcessingParameterEnum>( u"OUTPUT_TYPE"_s, QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
528 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
529 addParameter( rasterTypeParameter.release() );
530
531 auto nParameter = std::make_unique<QgsProcessingParameterNumber>( u"N"_s, u"N"_s, Qgis::ProcessingNumberParameterType::Integer, 10, true, 0 );
532 nParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
533 addParameter( nParameter.release() );
534
535 auto probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( u"PROBABILITY"_s, u"Probability"_s, Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0 );
536 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
537 addParameter( probabilityParameter.release() );
538}
539
540Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType( int typeId )
541{
542 switch ( typeId )
543 {
544 case 0:
546 case 1:
548 case 2:
550 case 3:
552 case 4:
554 case 5:
556 default:
558 }
559}
560
561bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
562{
563 const int n = parameterAsInt( parameters, u"N"_s, context );
564 const double probability = parameterAsDouble( parameters, u"PROBABILITY"_s, context );
565 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
566 return true;
567}
568
569long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
570{
571 return mRandombinomialDistribution( mersenneTwister );
572}
573
574double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
575{
576 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
577}
578
579//
580// QgsRandomExponentialRasterAlgorithm
581//
582QString QgsRandomExponentialRasterAlgorithm::name() const
583{
584 return u"createrandomexponentialrasterlayer"_s;
585}
586
587QString QgsRandomExponentialRasterAlgorithm::displayName() const
588{
589 return QObject::tr( "Create random raster layer (exponential distribution)" );
590}
591
592QStringList QgsRandomExponentialRasterAlgorithm::tags() const
593{
594 return QObject::tr( "raster,create,random,exponential" ).split( ',' );
595}
596
597QString QgsRandomExponentialRasterAlgorithm::shortHelpString() const
598{
599 return QObject::tr(
600 "This algorithm generates a raster layer for a given extent and cell size "
601 "filled with exponentially distributed random values.\n"
602 "By default, the values will be chosen given a lambda of 1.0. "
603 "This can be overridden by using the advanced parameter for lambda. "
604 "The raster data type is set to Float32 by default as "
605 "the exponential distribution random values are floating point numbers."
606 );
607}
608
609QString QgsRandomExponentialRasterAlgorithm::shortDescription() const
610{
611 return QObject::tr(
612 "Generates a raster layer for a given extent and cell size "
613 "filled with exponentially distributed random values."
614 );
615}
616
617QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance() const
618{
619 return new QgsRandomExponentialRasterAlgorithm();
620}
621
622
623void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
624{
625 QStringList rasterDataTypes = QStringList();
626 rasterDataTypes << u"Float32"_s << u"Float64"_s;
627
628 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter
629 = std::make_unique<QgsProcessingParameterEnum>( u"OUTPUT_TYPE"_s, QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
630 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
631 addParameter( rasterTypeParameter.release() );
632
633 auto lambdaParameter = std::make_unique<QgsProcessingParameterNumber>( u"LAMBDA"_s, u"Lambda"_s, Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
634 lambdaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
635 addParameter( lambdaParameter.release() );
636}
637
638Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType( int typeId )
639{
640 switch ( typeId )
641 {
642 case 0:
644 case 1:
646 default:
648 }
649}
650
651bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
652{
653 const double lambda = parameterAsDouble( parameters, u"LAMBDA"_s, context );
654 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
655 return true;
656}
657
658long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
659{
660 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
661}
662
663double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
664{
665 return mRandomExponentialDistribution( mersenneTwister );
666}
667
668//
669// QgsRandomGammaRasterAlgorithm
670//
671QString QgsRandomGammaRasterAlgorithm::name() const
672{
673 return u"createrandomgammarasterlayer"_s;
674}
675
676QString QgsRandomGammaRasterAlgorithm::displayName() const
677{
678 return QObject::tr( "Create random raster layer (gamma distribution)" );
679}
680
681QStringList QgsRandomGammaRasterAlgorithm::tags() const
682{
683 return QObject::tr( "raster,create,random,gamma" ).split( ',' );
684}
685
686QString QgsRandomGammaRasterAlgorithm::shortHelpString() const
687{
688 return QObject::tr(
689 "This algorithm generates a raster layer for a given extent and cell size "
690 "filled with gamma distributed random values.\n"
691 "By default, the values will be chosen given an alpha and beta value of 1.0. "
692 "This can be overridden by using the advanced parameter for alpha and beta. "
693 "The raster data type is set to Float32 by default as "
694 "the gamma distribution random values are floating point numbers."
695 );
696}
697
698QString QgsRandomGammaRasterAlgorithm::shortDescription() const
699{
700 return QObject::tr(
701 "Generates a raster layer for a given extent and cell size "
702 "filled with gamma distributed random values."
703 );
704}
705
706QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance() const
707{
708 return new QgsRandomGammaRasterAlgorithm();
709}
710
711
712void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
713{
714 QStringList rasterDataTypes = QStringList();
715 rasterDataTypes << u"Float32"_s << u"Float64"_s;
716
717 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter
718 = std::make_unique<QgsProcessingParameterEnum>( u"OUTPUT_TYPE"_s, QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
719 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
720 addParameter( rasterTypeParameter.release() );
721
722 auto alphaParameter = std::make_unique<QgsProcessingParameterNumber>( u"ALPHA"_s, u"Alpha"_s, Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
723 alphaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
724 addParameter( alphaParameter.release() );
725
726 auto betaParameter = std::make_unique<QgsProcessingParameterNumber>( u"BETA"_s, u"Beta"_s, Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
727 betaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
728 addParameter( betaParameter.release() );
729}
730
731Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType( int typeId )
732{
733 switch ( typeId )
734 {
735 case 0:
737 case 1:
739 default:
741 }
742}
743
744bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
745{
746 const double alpha = parameterAsDouble( parameters, u"ALPHA"_s, context );
747 const double beta = parameterAsDouble( parameters, u"BETA"_s, context );
748 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
749 return true;
750}
751
752long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
753{
754 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
755}
756
757double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
758{
759 return mRandomGammaDistribution( mersenneTwister );
760}
761
762//
763// QgsRandomGeometricRasterAlgorithm
764//
765QString QgsRandomGeometricRasterAlgorithm::name() const
766{
767 return u"createrandomgeometricrasterlayer"_s;
768}
769
770QString QgsRandomGeometricRasterAlgorithm::displayName() const
771{
772 return QObject::tr( "Create random raster layer (geometric distribution)" );
773}
774
775QStringList QgsRandomGeometricRasterAlgorithm::tags() const
776{
777 return QObject::tr( "raster,create,random,geometric" ).split( ',' );
778}
779
780QString QgsRandomGeometricRasterAlgorithm::shortHelpString() const
781{
782 return QObject::tr(
783 "This algorithm generates a raster layer for a given extent and cell size "
784 "filled with geometrically distributed random values.\n"
785 "By default, the values will be chosen given a probability of 0.5. "
786 "This can be overridden by using the advanced parameter for mean "
787 "value. The raster data type is set to Integer types (Integer16 by default). "
788 "The geometric distribution random values are defined as positive integer numbers. "
789 "A floating point raster will represent a cast of "
790 "integer values to floating point."
791 );
792}
793
794QString QgsRandomGeometricRasterAlgorithm::shortDescription() const
795{
796 return QObject::tr(
797 "Generates a raster layer for a given extent and cell size "
798 "filled with geometrically distributed random values."
799 );
800}
801
802QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance() const
803{
804 return new QgsRandomGeometricRasterAlgorithm();
805}
806
807
808void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
809{
810 QStringList rasterDataTypes = QStringList();
811 rasterDataTypes << u"Integer16"_s << u"Unsigned Integer16"_s << u"Integer32"_s << u"Unsigned Integer32"_s << u"Float32"_s << u"Float64"_s;
812
813 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter
814 = std::make_unique<QgsProcessingParameterEnum>( u"OUTPUT_TYPE"_s, QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
815 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
816 addParameter( rasterTypeParameter.release() );
817
818 auto probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( u"PROBABILITY"_s, u"Probability"_s, Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0.00001 );
819 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
820 addParameter( probabilityParameter.release() );
821}
822
823Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType( int typeId )
824{
825 switch ( typeId )
826 {
827 case 0:
829 case 1:
831 case 2:
833 case 3:
835 case 4:
837 case 5:
839 default:
841 }
842}
843
844bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
845{
846 const double probability = parameterAsDouble( parameters, u"PROBABILITY"_s, context );
847 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
848 return true;
849}
850
851long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
852{
853 return mRandomGeometricDistribution( mersenneTwister );
854}
855
856double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
857{
858 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
859}
860
861//
862// QgsRandomNegativeBinomialRasterAlgorithm
863//
864QString QgsRandomNegativeBinomialRasterAlgorithm::name() const
865{
866 return u"createrandomnegativebinomialrasterlayer"_s;
867}
868
869QString QgsRandomNegativeBinomialRasterAlgorithm::displayName() const
870{
871 return QObject::tr( "Create random raster layer (negative binomial distribution)" );
872}
873
874QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags() const
875{
876 return QObject::tr( "raster,create,random,negative,binomial,negative-binomial" ).split( ',' );
877}
878
879QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString() const
880{
881 return QObject::tr(
882 "This algorithm generates a raster layer for a given extent and cell size "
883 "filled with negative binomially distributed random values.\n"
884 "By default, the values will be chosen given a distribution parameter k of 10.0 "
885 "and a probability of 0.5. "
886 "This can be overridden by using the advanced parameters for k and probability. "
887 "The raster data type is set to Integer types (Integer 16 by default). "
888 "The negative binomial distribution random values are defined as positive integer numbers. "
889 "A floating point raster will represent a cast of "
890 "integer values to floating point."
891 );
892}
893
894QString QgsRandomNegativeBinomialRasterAlgorithm::shortDescription() const
895{
896 return QObject::tr(
897 "Generates a raster layer for a given extent and cell size "
898 "filled with negative binomially distributed random values."
899 );
900}
901
902QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance() const
903{
904 return new QgsRandomNegativeBinomialRasterAlgorithm();
905}
906
907
908void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams()
909{
910 QStringList rasterDataTypes = QStringList();
911 rasterDataTypes << u"Integer16"_s << u"Unsigned Integer16"_s << u"Integer32"_s << u"Unsigned Integer32"_s << u"Float32"_s << u"Float64"_s;
912
913 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter
914 = std::make_unique<QgsProcessingParameterEnum>( u"OUTPUT_TYPE"_s, QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
915 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
916 addParameter( rasterTypeParameter.release() );
917
918 auto kParameter = std::make_unique<QgsProcessingParameterNumber>( u"K_PARAMETER"_s, u"Distribution parameter k"_s, Qgis::ProcessingNumberParameterType::Integer, 10, true, 0.00001 );
919 kParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
920 addParameter( kParameter.release() );
921
922 auto probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( u"PROBABILITY"_s, u"Probability"_s, Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0.00001 );
923 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
924 addParameter( probabilityParameter.release() );
925}
926
927Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType( int typeId )
928{
929 switch ( typeId )
930 {
931 case 0:
933 case 1:
935 case 2:
937 case 3:
939 case 4:
941 case 5:
943 default:
945 }
946}
947
948bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
949{
950 const int k = parameterAsInt( parameters, u"K_PARAMETER"_s, context );
951 const double probability = parameterAsDouble( parameters, u"PROBABILITY"_s, context );
952 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
953 return true;
954}
955
956long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
957{
958 return mRandomNegativeBinomialDistribution( mersenneTwister );
959}
960
961double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
962{
963 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
964}
965
966//
967// QgsRandomNormalRasterAlgorithm
968//
969QString QgsRandomNormalRasterAlgorithm::name() const
970{
971 return u"createrandomnormalrasterlayer"_s;
972}
973
974QString QgsRandomNormalRasterAlgorithm::displayName() const
975{
976 return QObject::tr( "Create random raster layer (normal distribution)" );
977}
978
979QStringList QgsRandomNormalRasterAlgorithm::tags() const
980{
981 return QObject::tr( "raster,create,normal,distribution,random" ).split( ',' );
982}
983
984QString QgsRandomNormalRasterAlgorithm::shortHelpString() const
985{
986 return QObject::tr(
987 "This algorithm generates a raster layer for a given extent and cell size "
988 "filled with normally distributed random values.\n"
989 "By default, the values will be chosen given a mean of 0.0 and "
990 "a standard deviation of 1.0. This can be overridden by "
991 "using the advanced parameters for mean and standard deviation "
992 "value. The raster data type is set to Float32 by default "
993 "as the normal distribution random values are floating point numbers."
994 );
995}
996
997QString QgsRandomNormalRasterAlgorithm::shortDescription() const
998{
999 return QObject::tr(
1000 "Generates a raster layer for a given extent and cell size "
1001 "filled with normally distributed random values."
1002 );
1003}
1004
1005QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance() const
1006{
1007 return new QgsRandomNormalRasterAlgorithm();
1008}
1009
1010void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
1011{
1012 QStringList rasterDataTypes = QStringList();
1013 rasterDataTypes << u"Float32"_s << u"Float64"_s;
1014
1015 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter
1016 = std::make_unique<QgsProcessingParameterEnum>( u"OUTPUT_TYPE"_s, QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
1017 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
1018 addParameter( rasterTypeParameter.release() );
1019
1020 auto meanParameter = std::make_unique<QgsProcessingParameterNumber>( u"MEAN"_s, u"Mean of normal distribution"_s, Qgis::ProcessingNumberParameterType::Double, 0, true );
1021 meanParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
1022 addParameter( meanParameter.release() );
1023
1024 auto stdevParameter = std::make_unique<QgsProcessingParameterNumber>( u"STDDEV"_s, u"Standard deviation of normal distribution"_s, Qgis::ProcessingNumberParameterType::Double, 1, true, 0 );
1025 stdevParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
1026 addParameter( stdevParameter.release() );
1027}
1028
1029Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType( int typeId )
1030{
1031 switch ( typeId )
1032 {
1033 case 0:
1035 case 1:
1037 default:
1039 }
1040}
1041
1042bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
1043{
1044 const double mean = parameterAsDouble( parameters, u"MEAN"_s, context );
1045 const double stddev = parameterAsDouble( parameters, u"STDDEV"_s, context );
1046 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
1047 return true;
1048}
1049
1050long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1051{
1052 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
1053}
1054
1055double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1056{
1057 return mRandomNormalDistribution( mersenneTwister );
1058}
1059
1060//
1061// QgsRandomPoissonRasterAlgorithm
1062//
1063QString QgsRandomPoissonRasterAlgorithm::name() const
1064{
1065 return u"createrandompoissonrasterlayer"_s;
1066}
1067
1068QString QgsRandomPoissonRasterAlgorithm::displayName() const
1069{
1070 return QObject::tr( "Create random raster layer (poisson distribution)" );
1071}
1072
1073QStringList QgsRandomPoissonRasterAlgorithm::tags() const
1074{
1075 return QObject::tr( "raster,create,random,poisson" ).split( ',' );
1076}
1077
1078QString QgsRandomPoissonRasterAlgorithm::shortHelpString() const
1079{
1080 return QObject::tr(
1081 "This algorithm generates a raster layer for a given extent and cell size "
1082 "filled with poisson distributed random values.\n"
1083 "By default, the values will be chosen given a mean of 1.0. "
1084 "This can be overridden by using the advanced parameter for mean "
1085 "value. The raster data type is set to Integer types (Integer16 by default). "
1086 "The poisson distribution random values are positive integer numbers. "
1087 "A floating point raster will represent a cast of integer values to floating point."
1088 );
1089}
1090
1091QString QgsRandomPoissonRasterAlgorithm::shortDescription() const
1092{
1093 return QObject::tr(
1094 "Generates a raster layer for a given extent and cell size "
1095 "filled with poisson distributed random values."
1096 );
1097}
1098
1099QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance() const
1100{
1101 return new QgsRandomPoissonRasterAlgorithm();
1102}
1103
1104
1105void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
1106{
1107 QStringList rasterDataTypes = QStringList();
1108 rasterDataTypes << u"Integer16"_s << u"Unsigned Integer16"_s << u"Integer32"_s << u"Unsigned Integer32"_s << u"Float32"_s << u"Float64"_s;
1109
1110 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter
1111 = std::make_unique<QgsProcessingParameterEnum>( u"OUTPUT_TYPE"_s, QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
1112 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
1113 addParameter( rasterTypeParameter.release() );
1114
1115 auto upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( u"MEAN"_s, u"Mean"_s, Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0 );
1116 upperBoundParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
1117 addParameter( upperBoundParameter.release() );
1118}
1119
1120Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType( int typeId )
1121{
1122 switch ( typeId )
1123 {
1124 case 0:
1125 return Qgis::DataType::Int16;
1126 case 1:
1128 case 2:
1129 return Qgis::DataType::Int32;
1130 case 3:
1132 case 4:
1134 case 5:
1136 default:
1138 }
1139}
1140
1141bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
1142{
1143 const double mean = parameterAsDouble( parameters, u"MEAN"_s, context );
1144 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1145 return true;
1146}
1147
1148long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1149{
1150 return mRandomPoissonDistribution( mersenneTwister );
1151}
1152
1153double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1154{
1155 return static_cast<double>( mRandomPoissonDistribution( mersenneTwister ) );
1156}
1157
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:3881
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
Definition qgis.h:3880
@ Double
Double/float values.
Definition qgis.h:3921
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:6975