31QString QgsRandomRasterAlgorithmBase::group()
const
33 return QObject::tr(
"Raster creation" );
36QString QgsRandomRasterAlgorithmBase::groupId()
const
38 return QStringLiteral(
"rastercreation" );
41void QgsRandomRasterAlgorithmBase::initAlgorithm(
const QVariantMap & )
44 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"TARGET_CRS" ), QObject::tr(
"Target CRS" ), QStringLiteral(
"ProjectCrs" ) ) );
52 auto createOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATE_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
53 createOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
55 addParameter( createOptsParam.release() );
57 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATION_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
58 creationOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
60 addParameter( creationOptsParam.release() );
68 mCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
69 mExtent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context, mCrs );
70 mPixelSize = parameterAsDouble( parameters, QStringLiteral(
"PIXEL_SIZE" ), context );
72 if ( mPixelSize <= 0 )
82 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
84 mRasterDataType = getRasterDataType( typeId );
85 prepareRandomParameters( parameters, context );
87 std::random_device rd {};
88 std::mt19937 mersenneTwister { rd() };
90 QString creationOptions = parameterAsString( parameters, QStringLiteral(
"CREATION_OPTIONS" ), context ).trimmed();
92 const QString optionsString = parameterAsString( parameters, QStringLiteral(
"CREATE_OPTIONS" ), context );
93 if ( !optionsString.isEmpty() )
94 creationOptions = optionsString;
96 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
97 const QString outputFormat = parameterAsOutputRasterFormat( parameters, QStringLiteral(
"OUTPUT" ), context );
101 const int rows =
static_cast<int>( 0.5 + mExtent.height() / mPixelSize );
102 const int cols =
static_cast<int>( 0.5 + mExtent.width() / mPixelSize );
106 const QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
108 auto writer = std::make_unique<QgsRasterFileWriter>( outputFile );
109 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
110 if ( !creationOptions.isEmpty() )
112 writer->setCreationOptions( creationOptions.split(
'|' ) );
115 writer->setOutputFormat( outputFormat );
116 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
119 if ( !provider->isValid() )
122 const double step = rows > 0 ? 100.0 / rows : 1;
124 for (
int row = 0; row < rows; row++ )
132 switch ( mRasterDataType )
136 std::vector<quint8> byteRow( cols );
137 for (
int col = 0; col < cols; col++ )
139 byteRow[col] =
static_cast<quint8
>( generateRandomLongValue( mersenneTwister ) );
146 std::vector<qint8> int8Row( cols );
147 for (
int col = 0; col < cols; col++ )
149 int8Row[col] =
static_cast<qint8
>( generateRandomLongValue( mersenneTwister ) );
156 std::vector<qint16> int16Row( cols );
157 for (
int col = 0; col < cols; col++ )
159 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
166 std::vector<quint16> uInt16Row( cols );
167 for (
int col = 0; col < cols; col++ )
169 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
176 std::vector<qint32> int32Row( cols );
177 for (
int col = 0; col < cols; col++ )
179 int32Row[col] = generateRandomLongValue( mersenneTwister );
186 std::vector<quint32> uInt32Row( cols );
187 for (
int col = 0; col < cols; col++ )
189 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
196 std::vector<float> float32Row( cols );
197 for (
int col = 0; col < cols; col++ )
199 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
206 std::vector<double> float64Row( cols );
207 for (
int col = 0; col < cols; col++ )
209 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
217 if ( !provider->writeBlock( &block, 1, 0, row ) )
219 throw QgsProcessingException( QObject::tr(
"Could not write raster block: %1" ).arg( provider->error().summary() ) );
225 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
232QString QgsRandomUniformRasterAlgorithm::name()
const
234 return QStringLiteral(
"createrandomuniformrasterlayer" );
237QString QgsRandomUniformRasterAlgorithm::displayName()
const
239 return QObject::tr(
"Create random raster layer (uniform distribution)" );
242QStringList QgsRandomUniformRasterAlgorithm::tags()
const
244 return QObject::tr(
"raster,create,random" ).split(
',' );
247QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
249 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
250 "filled with random values.\n"
251 "By default, the values will range between the minimum and "
252 "maximum value of the specified output raster type. This can "
253 "be overridden by using the advanced parameters for lower and "
254 "upper bound value. If the bounds have the same value or both "
255 "are zero (default) the algorithm will create random values in "
256 "the full value range of the chosen raster data type. "
257 "Choosing bounds outside the acceptable range of the output "
258 "raster type will abort the algorithm." );
261QString QgsRandomUniformRasterAlgorithm::shortDescription()
const
263 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
264 "filled with random values." );
267QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
269 return new QgsRandomUniformRasterAlgorithm();
272void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
274 QStringList rasterDataTypes = QStringList();
275 rasterDataTypes << QStringLiteral(
"Byte" )
276 << QStringLiteral(
"Integer16" )
277 << QStringLiteral(
"Unsigned Integer16" )
278 << QStringLiteral(
"Integer32" )
279 << QStringLiteral(
"Unsigned Integer32" )
280 << QStringLiteral(
"Float32" )
281 << QStringLiteral(
"Float64" );
283 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
285 addParameter( rasterTypeParameter.release() );
287 auto lowerBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
289 addParameter( lowerBoundParameter.release() );
291 auto upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
293 addParameter( upperBoundParameter.release() );
296Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
319bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
321 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
322 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
324 if ( mRandomLowerBound > mRandomUpperBound )
325 throw QgsProcessingException( QObject::tr(
"The chosen lower bound for random number range is greater than the upper bound. The lower bound value must be smaller than the upper bound value." ) );
327 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
328 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
330 switch ( rasterDataType )
333 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
334 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint8>::min() ).arg( std::numeric_limits<quint8>::max() ).arg( QLatin1String(
"Byte" ) ) );
338 mRandomUpperBound = std::numeric_limits<quint8>::max();
339 mRandomLowerBound = std::numeric_limits<quint8>::min();
343 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
344 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint8>::min() ).arg( std::numeric_limits<qint8>::max() ).arg( QLatin1String(
"Int8" ) ) );
348 mRandomUpperBound = std::numeric_limits<qint8>::max();
349 mRandomLowerBound = std::numeric_limits<qint8>::min();
353 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
354 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint16>::min() ).arg( std::numeric_limits<qint16>::max() ).arg( QLatin1String(
"Integer16" ) ) );
357 mRandomUpperBound = std::numeric_limits<qint16>::max();
358 mRandomLowerBound = std::numeric_limits<qint16>::min();
362 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
363 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint16>::min() ).arg( std::numeric_limits<quint16>::max() ).arg( QLatin1String(
"Unsigned Integer16" ) ) );
366 mRandomUpperBound = std::numeric_limits<quint16>::max();
367 mRandomLowerBound = std::numeric_limits<quint16>::min();
371 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
372 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint32>::min() ).arg( std::numeric_limits<qint32>::max() ).arg( QLatin1String(
"Integer32" ) ) );
375 mRandomUpperBound = std::numeric_limits<qint32>::max();
376 mRandomLowerBound = std::numeric_limits<qint32>::min();
380 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
381 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint32>::min() ).arg( std::numeric_limits<quint32>::max() ).arg( QLatin1String(
"Unsigned Integer32" ) ) );
384 mRandomUpperBound = std::numeric_limits<quint32>::max();
385 mRandomLowerBound = std::numeric_limits<quint32>::min();
391 mRandomUpperBound = std::numeric_limits<float>::max();
392 mRandomLowerBound = std::numeric_limits<float>::min();
398 mRandomUpperBound = std::numeric_limits<double>::max();
399 mRandomLowerBound = std::numeric_limits<double>::min();
412 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
413 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
418long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
420 return mRandomUniformIntDistribution( mersenneTwister );
423double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
425 return mRandomUniformDoubleDistribution( mersenneTwister );
431QString QgsRandomBinomialRasterAlgorithm::name()
const
433 return QStringLiteral(
"createrandombinomialrasterlayer" );
436QString QgsRandomBinomialRasterAlgorithm::displayName()
const
438 return QObject::tr(
"Create random raster layer (binomial distribution)" );
441QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
443 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
446QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
448 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
449 "filled with binomially distributed random values.\n"
450 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
451 "This can be overridden by using the advanced parameter for N and probability. "
452 "The raster data type is set to Integer types (Integer16 by default). "
453 "The binomial distribution random values are defined as positive integer numbers. "
454 "A floating point raster will represent a cast of integer values "
455 "to floating point." );
458QString QgsRandomBinomialRasterAlgorithm::shortDescription()
const
460 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
461 "filled with binomially distributed random values." );
464QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
466 return new QgsRandomBinomialRasterAlgorithm();
470void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams()
472 QStringList rasterDataTypes = QStringList();
473 rasterDataTypes << QStringLiteral(
"Integer16" )
474 << QStringLiteral(
"Unsigned Integer16" )
475 << QStringLiteral(
"Integer32" )
476 << QStringLiteral(
"Unsigned Integer32" )
477 << QStringLiteral(
"Float32" )
478 << QStringLiteral(
"Float64" );
480 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
482 addParameter( rasterTypeParameter.release() );
486 addParameter( nParameter.release() );
490 addParameter( probabilityParameter.release() );
493Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
514bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
516 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
517 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
518 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
522long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
524 return mRandombinomialDistribution( mersenneTwister );
527double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
529 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
535QString QgsRandomExponentialRasterAlgorithm::name()
const
537 return QStringLiteral(
"createrandomexponentialrasterlayer" );
540QString QgsRandomExponentialRasterAlgorithm::displayName()
const
542 return QObject::tr(
"Create random raster layer (exponential distribution)" );
545QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
547 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
550QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
552 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
553 "filled with exponentially distributed random values.\n"
554 "By default, the values will be chosen given a lambda of 1.0. "
555 "This can be overridden by using the advanced parameter for lambda. "
556 "The raster data type is set to Float32 by default as "
557 "the exponential distribution random values are floating point numbers." );
560QString QgsRandomExponentialRasterAlgorithm::shortDescription()
const
562 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
563 "filled with exponentially distributed random values." );
566QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
568 return new QgsRandomExponentialRasterAlgorithm();
572void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
574 QStringList rasterDataTypes = QStringList();
575 rasterDataTypes << QStringLiteral(
"Float32" )
576 << QStringLiteral(
"Float64" );
578 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
580 addParameter( rasterTypeParameter.release() );
584 addParameter( lambdaParameter.release() );
587Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
600bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
602 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
603 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
607long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
609 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
612double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
614 return mRandomExponentialDistribution( mersenneTwister );
620QString QgsRandomGammaRasterAlgorithm::name()
const
622 return QStringLiteral(
"createrandomgammarasterlayer" );
625QString QgsRandomGammaRasterAlgorithm::displayName()
const
627 return QObject::tr(
"Create random raster layer (gamma distribution)" );
630QStringList QgsRandomGammaRasterAlgorithm::tags()
const
632 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
635QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
637 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
638 "filled with gamma distributed random values.\n"
639 "By default, the values will be chosen given an alpha and beta value of 1.0. "
640 "This can be overridden by using the advanced parameter for alpha and beta. "
641 "The raster data type is set to Float32 by default as "
642 "the gamma distribution random values are floating point numbers." );
645QString QgsRandomGammaRasterAlgorithm::shortDescription()
const
647 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
648 "filled with gamma distributed random values." );
651QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
653 return new QgsRandomGammaRasterAlgorithm();
657void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
659 QStringList rasterDataTypes = QStringList();
660 rasterDataTypes << QStringLiteral(
"Float32" )
661 << QStringLiteral(
"Float64" );
663 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
665 addParameter( rasterTypeParameter.release() );
669 addParameter( alphaParameter.release() );
673 addParameter( betaParameter.release() );
676Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
689bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
691 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
692 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
693 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
697long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
699 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
702double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
704 return mRandomGammaDistribution( mersenneTwister );
710QString QgsRandomGeometricRasterAlgorithm::name()
const
712 return QStringLiteral(
"createrandomgeometricrasterlayer" );
715QString QgsRandomGeometricRasterAlgorithm::displayName()
const
717 return QObject::tr(
"Create random raster layer (geometric distribution)" );
720QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
722 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
725QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
727 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
728 "filled with geometrically distributed random values.\n"
729 "By default, the values will be chosen given a probability of 0.5. "
730 "This can be overridden by using the advanced parameter for mean "
731 "value. The raster data type is set to Integer types (Integer16 by default). "
732 "The geometric distribution random values are defined as positive integer numbers. "
733 "A floating point raster will represent a cast of "
734 "integer values to floating point." );
737QString QgsRandomGeometricRasterAlgorithm::shortDescription()
const
739 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
740 "filled with geometrically distributed random values." );
743QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
745 return new QgsRandomGeometricRasterAlgorithm();
749void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
751 QStringList rasterDataTypes = QStringList();
752 rasterDataTypes << QStringLiteral(
"Integer16" )
753 << QStringLiteral(
"Unsigned Integer16" )
754 << QStringLiteral(
"Integer32" )
755 << QStringLiteral(
"Unsigned Integer32" )
756 << QStringLiteral(
"Float32" )
757 << QStringLiteral(
"Float64" );
759 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
761 addParameter( rasterTypeParameter.release() );
765 addParameter( probabilityParameter.release() );
768Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
789bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
791 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
792 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
796long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
798 return mRandomGeometricDistribution( mersenneTwister );
801double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
803 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
809QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
811 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
814QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
816 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
819QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
821 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
824QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
826 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
827 "filled with negative binomially distributed random values.\n"
828 "By default, the values will be chosen given a distribution parameter k of 10.0 "
829 "and a probability of 0.5. "
830 "This can be overridden by using the advanced parameters for k and probability. "
831 "The raster data type is set to Integer types (Integer 16 by default). "
832 "The negative binomial distribution random values are defined as positive integer numbers. "
833 "A floating point raster will represent a cast of "
834 "integer values to floating point." );
837QString QgsRandomNegativeBinomialRasterAlgorithm::shortDescription()
const
839 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
840 "filled with negative binomially distributed random values." );
843QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
845 return new QgsRandomNegativeBinomialRasterAlgorithm();
849void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams()
851 QStringList rasterDataTypes = QStringList();
852 rasterDataTypes << QStringLiteral(
"Integer16" )
853 << QStringLiteral(
"Unsigned Integer16" )
854 << QStringLiteral(
"Integer32" )
855 << QStringLiteral(
"Unsigned Integer32" )
856 << QStringLiteral(
"Float32" )
857 << QStringLiteral(
"Float64" );
859 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
861 addParameter( rasterTypeParameter.release() );
865 addParameter( kParameter.release() );
869 addParameter( probabilityParameter.release() );
872Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
893bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
895 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
896 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
897 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
901long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
903 return mRandomNegativeBinomialDistribution( mersenneTwister );
906double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
908 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
914QString QgsRandomNormalRasterAlgorithm::name()
const
916 return QStringLiteral(
"createrandomnormalrasterlayer" );
919QString QgsRandomNormalRasterAlgorithm::displayName()
const
921 return QObject::tr(
"Create random raster layer (normal distribution)" );
924QStringList QgsRandomNormalRasterAlgorithm::tags()
const
926 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
929QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
931 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
932 "filled with normally distributed random values.\n"
933 "By default, the values will be chosen given a mean of 0.0 and "
934 "a standard deviation of 1.0. This can be overridden by "
935 "using the advanced parameters for mean and standard deviation "
936 "value. The raster data type is set to Float32 by default "
937 "as the normal distribution random values are floating point numbers." );
940QString QgsRandomNormalRasterAlgorithm::shortDescription()
const
942 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
943 "filled with normally distributed random values." );
946QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
948 return new QgsRandomNormalRasterAlgorithm();
951void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
953 QStringList rasterDataTypes = QStringList();
954 rasterDataTypes << QStringLiteral(
"Float32" )
955 << QStringLiteral(
"Float64" );
957 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
959 addParameter( rasterTypeParameter.release() );
963 addParameter( meanParameter.release() );
965 auto stdevParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 1,
true, 0 );
967 addParameter( stdevParameter.release() );
970Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
983bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
985 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
986 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
987 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
991long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
993 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
996double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
998 return mRandomNormalDistribution( mersenneTwister );
1004QString QgsRandomPoissonRasterAlgorithm::name()
const
1006 return QStringLiteral(
"createrandompoissonrasterlayer" );
1009QString QgsRandomPoissonRasterAlgorithm::displayName()
const
1011 return QObject::tr(
"Create random raster layer (poisson distribution)" );
1014QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
1016 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
1019QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
1021 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
1022 "filled with poisson distributed random values.\n"
1023 "By default, the values will be chosen given a mean of 1.0. "
1024 "This can be overridden by using the advanced parameter for mean "
1025 "value. The raster data type is set to Integer types (Integer16 by default). "
1026 "The poisson distribution random values are positive integer numbers. "
1027 "A floating point raster will represent a cast of integer values to floating point." );
1030QString QgsRandomPoissonRasterAlgorithm::shortDescription()
const
1032 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
1033 "filled with poisson distributed random values." );
1036QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
1038 return new QgsRandomPoissonRasterAlgorithm();
1042void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
1044 QStringList rasterDataTypes = QStringList();
1045 rasterDataTypes << QStringLiteral(
"Integer16" )
1046 << QStringLiteral(
"Unsigned Integer16" )
1047 << QStringLiteral(
"Integer32" )
1048 << QStringLiteral(
"Unsigned Integer32" )
1049 << QStringLiteral(
"Float32" )
1050 << QStringLiteral(
"Float64" );
1052 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
1054 addParameter( rasterTypeParameter.release() );
1058 addParameter( upperBoundParameter.release() );
1061Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1082bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1084 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1085 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1089long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1091 return mRandomPoissonDistribution( mersenneTwister );
1094double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1096 return static_cast<double>( mRandomPoissonDistribution( mersenneTwister ) );
DataType
Raster data types.
@ Float32
Thirty two bit floating point (float).
@ CFloat64
Complex Float64.
@ Int16
Sixteen bit signed integer (qint16).
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
@ Int8
Eight bit signed integer (qint8) (added in QGIS 3.30).
@ UInt16
Sixteen bit unsigned integer (quint16).
@ Byte
Eight bit unsigned integer (quint8).
@ UnknownDataType
Unknown or unspecified type.
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
@ Int32
Thirty two bit signed integer (qint32).
@ Float64
Sixty four bit floating point (double).
@ CFloat32
Complex Float32.
@ UInt32
Thirty two bit unsigned integer (quint32).
@ Hidden
Parameter is hidden and should not be shown to users.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
@ Double
Double/float values.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
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 ...
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).