29QString QgsRandomRasterAlgorithmBase::group()
const
31 return QObject::tr(
"Raster creation" );
34QString QgsRandomRasterAlgorithmBase::groupId()
const
36 return QStringLiteral(
"rastercreation" );
39void QgsRandomRasterAlgorithmBase::initAlgorithm(
const QVariantMap & )
42 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"TARGET_CRS" ), QObject::tr(
"Target CRS" ), QStringLiteral(
"ProjectCrs" ) ) );
50 auto createOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATE_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
51 createOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
53 addParameter( createOptsParam.release() );
55 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATION_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
56 creationOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
58 addParameter( creationOptsParam.release() );
66 mCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
67 mExtent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context, mCrs );
68 mPixelSize = parameterAsDouble( parameters, QStringLiteral(
"PIXEL_SIZE" ), context );
70 if ( mPixelSize <= 0 )
80 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
82 mRasterDataType = getRasterDataType( typeId );
83 prepareRandomParameters( parameters, context );
85 std::random_device rd {};
86 std::mt19937 mersenneTwister { rd() };
88 QString creationOptions = parameterAsString( parameters, QStringLiteral(
"CREATION_OPTIONS" ), context ).trimmed();
90 const QString optionsString = parameterAsString( parameters, QStringLiteral(
"CREATE_OPTIONS" ), context );
91 if ( !optionsString.isEmpty() )
92 creationOptions = optionsString;
94 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
95 const QFileInfo fi( outputFile );
100 const int rows =
static_cast<int>( 0.5 + mExtent.height() / mPixelSize );
101 const int cols =
static_cast<int>( 0.5 + mExtent.width() / mPixelSize );
105 const QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
107 auto writer = std::make_unique<QgsRasterFileWriter>( outputFile );
108 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
109 if ( !creationOptions.isEmpty() )
111 writer->setCreationOptions( creationOptions.split(
'|' ) );
114 writer->setOutputFormat( outputFormat );
115 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
118 if ( !provider->isValid() )
121 const double step = rows > 0 ? 100.0 / rows : 1;
123 for (
int row = 0; row < rows; row++ )
131 switch ( mRasterDataType )
135 std::vector<quint8> byteRow( cols );
136 for (
int col = 0; col < cols; col++ )
138 byteRow[col] =
static_cast<quint8
>( generateRandomLongValue( mersenneTwister ) );
145 std::vector<qint8> int8Row( cols );
146 for (
int col = 0; col < cols; col++ )
148 int8Row[col] =
static_cast<qint8
>( generateRandomLongValue( mersenneTwister ) );
155 std::vector<qint16> int16Row( cols );
156 for (
int col = 0; col < cols; col++ )
158 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
165 std::vector<quint16> uInt16Row( cols );
166 for (
int col = 0; col < cols; col++ )
168 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
175 std::vector<qint32> int32Row( cols );
176 for (
int col = 0; col < cols; col++ )
178 int32Row[col] = generateRandomLongValue( mersenneTwister );
185 std::vector<quint32> uInt32Row( cols );
186 for (
int col = 0; col < cols; col++ )
188 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
195 std::vector<float> float32Row( cols );
196 for (
int col = 0; col < cols; col++ )
198 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
205 std::vector<double> float64Row( cols );
206 for (
int col = 0; col < cols; col++ )
208 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
216 if ( !provider->writeBlock( &block, 1, 0, row ) )
218 throw QgsProcessingException( QObject::tr(
"Could not write raster block: %1" ).arg( provider->error().summary() ) );
224 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
231QString QgsRandomUniformRasterAlgorithm::name()
const
233 return QStringLiteral(
"createrandomuniformrasterlayer" );
236QString QgsRandomUniformRasterAlgorithm::displayName()
const
238 return QObject::tr(
"Create random raster layer (uniform distribution)" );
241QStringList QgsRandomUniformRasterAlgorithm::tags()
const
243 return QObject::tr(
"raster,create,random" ).split(
',' );
246QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
248 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
249 "filled with random values.\n"
250 "By default, the values will range between the minimum and "
251 "maximum value of the specified output raster type. This can "
252 "be overridden by using the advanced parameters for lower and "
253 "upper bound value. If the bounds have the same value or both "
254 "are zero (default) the algorithm will create random values in "
255 "the full value range of the chosen raster data type. "
256 "Choosing bounds outside the acceptable range of the output "
257 "raster type will abort the algorithm." );
260QString QgsRandomUniformRasterAlgorithm::shortDescription()
const
262 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
263 "filled with random values." );
266QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
268 return new QgsRandomUniformRasterAlgorithm();
271void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
273 QStringList rasterDataTypes = QStringList();
274 rasterDataTypes << QStringLiteral(
"Byte" )
275 << QStringLiteral(
"Integer16" )
276 << QStringLiteral(
"Unsigned Integer16" )
277 << QStringLiteral(
"Integer32" )
278 << QStringLiteral(
"Unsigned Integer32" )
279 << QStringLiteral(
"Float32" )
280 << QStringLiteral(
"Float64" );
282 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
284 addParameter( rasterTypeParameter.release() );
286 auto lowerBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
288 addParameter( lowerBoundParameter.release() );
290 auto upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
292 addParameter( upperBoundParameter.release() );
295Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
318bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
320 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
321 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
323 if ( mRandomLowerBound > mRandomUpperBound )
324 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." ) );
326 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
327 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
329 switch ( rasterDataType )
332 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
333 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" ) ) );
337 mRandomUpperBound = std::numeric_limits<quint8>::max();
338 mRandomLowerBound = std::numeric_limits<quint8>::min();
342 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
343 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" ) ) );
347 mRandomUpperBound = std::numeric_limits<qint8>::max();
348 mRandomLowerBound = std::numeric_limits<qint8>::min();
352 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
353 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint16>::min() ).arg( std::numeric_limits<qint16>::max() ).arg( QLatin1String(
"Integer16" ) ) );
356 mRandomUpperBound = std::numeric_limits<qint16>::max();
357 mRandomLowerBound = std::numeric_limits<qint16>::min();
361 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
362 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint16>::min() ).arg( std::numeric_limits<quint16>::max() ).arg( QLatin1String(
"Unsigned Integer16" ) ) );
365 mRandomUpperBound = std::numeric_limits<quint16>::max();
366 mRandomLowerBound = std::numeric_limits<quint16>::min();
370 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
371 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint32>::min() ).arg( std::numeric_limits<qint32>::max() ).arg( QLatin1String(
"Integer32" ) ) );
374 mRandomUpperBound = std::numeric_limits<qint32>::max();
375 mRandomLowerBound = std::numeric_limits<qint32>::min();
379 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
380 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint32>::min() ).arg( std::numeric_limits<quint32>::max() ).arg( QLatin1String(
"Unsigned Integer32" ) ) );
383 mRandomUpperBound = std::numeric_limits<quint32>::max();
384 mRandomLowerBound = std::numeric_limits<quint32>::min();
390 mRandomUpperBound = std::numeric_limits<float>::max();
391 mRandomLowerBound = std::numeric_limits<float>::min();
397 mRandomUpperBound = std::numeric_limits<double>::max();
398 mRandomLowerBound = std::numeric_limits<double>::min();
411 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
412 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
417long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
419 return mRandomUniformIntDistribution( mersenneTwister );
422double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
424 return mRandomUniformDoubleDistribution( mersenneTwister );
430QString QgsRandomBinomialRasterAlgorithm::name()
const
432 return QStringLiteral(
"createrandombinomialrasterlayer" );
435QString QgsRandomBinomialRasterAlgorithm::displayName()
const
437 return QObject::tr(
"Create random raster layer (binomial distribution)" );
440QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
442 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
445QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
447 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
448 "filled with binomially distributed random values.\n"
449 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
450 "This can be overridden by using the advanced parameter for N and probability. "
451 "The raster data type is set to Integer types (Integer16 by default). "
452 "The binomial distribution random values are defined as positive integer numbers. "
453 "A floating point raster will represent a cast of integer values "
454 "to floating point." );
457QString QgsRandomBinomialRasterAlgorithm::shortDescription()
const
459 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
460 "filled with binomially distributed random values." );
463QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
465 return new QgsRandomBinomialRasterAlgorithm();
469void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams()
471 QStringList rasterDataTypes = QStringList();
472 rasterDataTypes << QStringLiteral(
"Integer16" )
473 << QStringLiteral(
"Unsigned Integer16" )
474 << QStringLiteral(
"Integer32" )
475 << QStringLiteral(
"Unsigned Integer32" )
476 << QStringLiteral(
"Float32" )
477 << QStringLiteral(
"Float64" );
479 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
481 addParameter( rasterTypeParameter.release() );
485 addParameter( nParameter.release() );
489 addParameter( probabilityParameter.release() );
492Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
513bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
515 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
516 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
517 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
521long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
523 return mRandombinomialDistribution( mersenneTwister );
526double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
528 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
534QString QgsRandomExponentialRasterAlgorithm::name()
const
536 return QStringLiteral(
"createrandomexponentialrasterlayer" );
539QString QgsRandomExponentialRasterAlgorithm::displayName()
const
541 return QObject::tr(
"Create random raster layer (exponential distribution)" );
544QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
546 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
549QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
551 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
552 "filled with exponentially distributed random values.\n"
553 "By default, the values will be chosen given a lambda of 1.0. "
554 "This can be overridden by using the advanced parameter for lambda. "
555 "The raster data type is set to Float32 by default as "
556 "the exponential distribution random values are floating point numbers." );
559QString QgsRandomExponentialRasterAlgorithm::shortDescription()
const
561 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
562 "filled with exponentially distributed random values." );
565QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
567 return new QgsRandomExponentialRasterAlgorithm();
571void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
573 QStringList rasterDataTypes = QStringList();
574 rasterDataTypes << QStringLiteral(
"Float32" )
575 << QStringLiteral(
"Float64" );
577 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
579 addParameter( rasterTypeParameter.release() );
583 addParameter( lambdaParameter.release() );
586Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
599bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
601 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
602 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
606long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
608 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
611double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
613 return mRandomExponentialDistribution( mersenneTwister );
619QString QgsRandomGammaRasterAlgorithm::name()
const
621 return QStringLiteral(
"createrandomgammarasterlayer" );
624QString QgsRandomGammaRasterAlgorithm::displayName()
const
626 return QObject::tr(
"Create random raster layer (gamma distribution)" );
629QStringList QgsRandomGammaRasterAlgorithm::tags()
const
631 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
634QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
636 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
637 "filled with gamma distributed random values.\n"
638 "By default, the values will be chosen given an alpha and beta value of 1.0. "
639 "This can be overridden by using the advanced parameter for alpha and beta. "
640 "The raster data type is set to Float32 by default as "
641 "the gamma distribution random values are floating point numbers." );
644QString QgsRandomGammaRasterAlgorithm::shortDescription()
const
646 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
647 "filled with gamma distributed random values." );
650QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
652 return new QgsRandomGammaRasterAlgorithm();
656void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
658 QStringList rasterDataTypes = QStringList();
659 rasterDataTypes << QStringLiteral(
"Float32" )
660 << QStringLiteral(
"Float64" );
662 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
664 addParameter( rasterTypeParameter.release() );
668 addParameter( alphaParameter.release() );
672 addParameter( betaParameter.release() );
675Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
688bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
690 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
691 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
692 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
696long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
698 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
701double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
703 return mRandomGammaDistribution( mersenneTwister );
709QString QgsRandomGeometricRasterAlgorithm::name()
const
711 return QStringLiteral(
"createrandomgeometricrasterlayer" );
714QString QgsRandomGeometricRasterAlgorithm::displayName()
const
716 return QObject::tr(
"Create random raster layer (geometric distribution)" );
719QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
721 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
724QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
726 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
727 "filled with geometrically distributed random values.\n"
728 "By default, the values will be chosen given a probability of 0.5. "
729 "This can be overridden by using the advanced parameter for mean "
730 "value. The raster data type is set to Integer types (Integer16 by default). "
731 "The geometric distribution random values are defined as positive integer numbers. "
732 "A floating point raster will represent a cast of "
733 "integer values to floating point." );
736QString QgsRandomGeometricRasterAlgorithm::shortDescription()
const
738 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
739 "filled with geometrically distributed random values." );
742QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
744 return new QgsRandomGeometricRasterAlgorithm();
748void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
750 QStringList rasterDataTypes = QStringList();
751 rasterDataTypes << QStringLiteral(
"Integer16" )
752 << QStringLiteral(
"Unsigned Integer16" )
753 << QStringLiteral(
"Integer32" )
754 << QStringLiteral(
"Unsigned Integer32" )
755 << QStringLiteral(
"Float32" )
756 << QStringLiteral(
"Float64" );
758 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
760 addParameter( rasterTypeParameter.release() );
764 addParameter( probabilityParameter.release() );
767Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
788bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
790 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
791 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
795long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
797 return mRandomGeometricDistribution( mersenneTwister );
800double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
802 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
808QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
810 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
813QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
815 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
818QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
820 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
823QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
825 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
826 "filled with negative binomially distributed random values.\n"
827 "By default, the values will be chosen given a distribution parameter k of 10.0 "
828 "and a probability of 0.5. "
829 "This can be overridden by using the advanced parameters for k and probability. "
830 "The raster data type is set to Integer types (Integer 16 by default). "
831 "The negative binomial distribution random values are defined as positive integer numbers. "
832 "A floating point raster will represent a cast of "
833 "integer values to floating point." );
836QString QgsRandomNegativeBinomialRasterAlgorithm::shortDescription()
const
838 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
839 "filled with negative binomially distributed random values." );
842QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
844 return new QgsRandomNegativeBinomialRasterAlgorithm();
848void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams()
850 QStringList rasterDataTypes = QStringList();
851 rasterDataTypes << QStringLiteral(
"Integer16" )
852 << QStringLiteral(
"Unsigned Integer16" )
853 << QStringLiteral(
"Integer32" )
854 << QStringLiteral(
"Unsigned Integer32" )
855 << QStringLiteral(
"Float32" )
856 << QStringLiteral(
"Float64" );
858 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
860 addParameter( rasterTypeParameter.release() );
864 addParameter( kParameter.release() );
868 addParameter( probabilityParameter.release() );
871Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
892bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
894 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
895 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
896 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
900long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
902 return mRandomNegativeBinomialDistribution( mersenneTwister );
905double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
907 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
913QString QgsRandomNormalRasterAlgorithm::name()
const
915 return QStringLiteral(
"createrandomnormalrasterlayer" );
918QString QgsRandomNormalRasterAlgorithm::displayName()
const
920 return QObject::tr(
"Create random raster layer (normal distribution)" );
923QStringList QgsRandomNormalRasterAlgorithm::tags()
const
925 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
928QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
930 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
931 "filled with normally distributed random values.\n"
932 "By default, the values will be chosen given a mean of 0.0 and "
933 "a standard deviation of 1.0. This can be overridden by "
934 "using the advanced parameters for mean and standard deviation "
935 "value. The raster data type is set to Float32 by default "
936 "as the normal distribution random values are floating point numbers." );
939QString QgsRandomNormalRasterAlgorithm::shortDescription()
const
941 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
942 "filled with normally distributed random values." );
945QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
947 return new QgsRandomNormalRasterAlgorithm();
950void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
952 QStringList rasterDataTypes = QStringList();
953 rasterDataTypes << QStringLiteral(
"Float32" )
954 << QStringLiteral(
"Float64" );
956 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
958 addParameter( rasterTypeParameter.release() );
962 addParameter( meanParameter.release() );
964 auto stdevParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 1,
true, 0 );
966 addParameter( stdevParameter.release() );
969Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
982bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
984 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
985 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
986 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
990long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
992 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
995double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
997 return mRandomNormalDistribution( mersenneTwister );
1003QString QgsRandomPoissonRasterAlgorithm::name()
const
1005 return QStringLiteral(
"createrandompoissonrasterlayer" );
1008QString QgsRandomPoissonRasterAlgorithm::displayName()
const
1010 return QObject::tr(
"Create random raster layer (poisson distribution)" );
1013QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
1015 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
1018QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
1020 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
1021 "filled with poisson distributed random values.\n"
1022 "By default, the values will be chosen given a mean of 1.0. "
1023 "This can be overridden by using the advanced parameter for mean "
1024 "value. The raster data type is set to Integer types (Integer16 by default). "
1025 "The poisson distribution random values are positive integer numbers. "
1026 "A floating point raster will represent a cast of integer values to floating point." );
1029QString QgsRandomPoissonRasterAlgorithm::shortDescription()
const
1031 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
1032 "filled with poisson distributed random values." );
1035QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
1037 return new QgsRandomPoissonRasterAlgorithm();
1041void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
1043 QStringList rasterDataTypes = QStringList();
1044 rasterDataTypes << QStringLiteral(
"Integer16" )
1045 << QStringLiteral(
"Unsigned Integer16" )
1046 << QStringLiteral(
"Integer32" )
1047 << QStringLiteral(
"Unsigned Integer32" )
1048 << QStringLiteral(
"Float32" )
1049 << QStringLiteral(
"Float64" );
1051 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
1053 addParameter( rasterTypeParameter.release() );
1057 addParameter( upperBoundParameter.release() );
1060Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1081bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1083 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1084 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1088long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1090 return mRandomPoissonDistribution( mersenneTwister );
1093double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1095 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.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
A rectangle specified with double values.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)