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 QFileInfo fi( outputFile );
102 const int rows =
static_cast<int>( 0.5 + mExtent.height() / mPixelSize );
103 const int cols =
static_cast<int>( 0.5 + mExtent.width() / mPixelSize );
107 const QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
109 auto writer = std::make_unique<QgsRasterFileWriter>( outputFile );
110 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
111 if ( !creationOptions.isEmpty() )
113 writer->setCreationOptions( creationOptions.split(
'|' ) );
116 writer->setOutputFormat( outputFormat );
117 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
120 if ( !provider->isValid() )
123 const double step = rows > 0 ? 100.0 / rows : 1;
125 for (
int row = 0; row < rows; row++ )
133 switch ( mRasterDataType )
137 std::vector<quint8> byteRow( cols );
138 for (
int col = 0; col < cols; col++ )
140 byteRow[col] =
static_cast<quint8
>( generateRandomLongValue( mersenneTwister ) );
147 std::vector<qint8> int8Row( cols );
148 for (
int col = 0; col < cols; col++ )
150 int8Row[col] =
static_cast<qint8
>( generateRandomLongValue( mersenneTwister ) );
157 std::vector<qint16> int16Row( cols );
158 for (
int col = 0; col < cols; col++ )
160 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
167 std::vector<quint16> uInt16Row( cols );
168 for (
int col = 0; col < cols; col++ )
170 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
177 std::vector<qint32> int32Row( cols );
178 for (
int col = 0; col < cols; col++ )
180 int32Row[col] = generateRandomLongValue( mersenneTwister );
187 std::vector<quint32> uInt32Row( cols );
188 for (
int col = 0; col < cols; col++ )
190 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
197 std::vector<float> float32Row( cols );
198 for (
int col = 0; col < cols; col++ )
200 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
207 std::vector<double> float64Row( cols );
208 for (
int col = 0; col < cols; col++ )
210 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
218 if ( !provider->writeBlock( &block, 1, 0, row ) )
220 throw QgsProcessingException( QObject::tr(
"Could not write raster block: %1" ).arg( provider->error().summary() ) );
226 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
233QString QgsRandomUniformRasterAlgorithm::name()
const
235 return QStringLiteral(
"createrandomuniformrasterlayer" );
238QString QgsRandomUniformRasterAlgorithm::displayName()
const
240 return QObject::tr(
"Create random raster layer (uniform distribution)" );
243QStringList QgsRandomUniformRasterAlgorithm::tags()
const
245 return QObject::tr(
"raster,create,random" ).split(
',' );
248QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
250 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
251 "filled with random values.\n"
252 "By default, the values will range between the minimum and "
253 "maximum value of the specified output raster type. This can "
254 "be overridden by using the advanced parameters for lower and "
255 "upper bound value. If the bounds have the same value or both "
256 "are zero (default) the algorithm will create random values in "
257 "the full value range of the chosen raster data type. "
258 "Choosing bounds outside the acceptable range of the output "
259 "raster type will abort the algorithm." );
262QString QgsRandomUniformRasterAlgorithm::shortDescription()
const
264 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
265 "filled with random values." );
268QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
270 return new QgsRandomUniformRasterAlgorithm();
273void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
275 QStringList rasterDataTypes = QStringList();
276 rasterDataTypes << QStringLiteral(
"Byte" )
277 << QStringLiteral(
"Integer16" )
278 << QStringLiteral(
"Unsigned Integer16" )
279 << QStringLiteral(
"Integer32" )
280 << QStringLiteral(
"Unsigned Integer32" )
281 << QStringLiteral(
"Float32" )
282 << QStringLiteral(
"Float64" );
284 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
286 addParameter( rasterTypeParameter.release() );
288 auto lowerBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
290 addParameter( lowerBoundParameter.release() );
292 auto upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
294 addParameter( upperBoundParameter.release() );
297Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
320bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
322 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
323 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
325 if ( mRandomLowerBound > mRandomUpperBound )
326 throw QgsProcessingException( QObject::tr(
"The chosen lower bound for random number range is greater than the upper bound. The lower bound value must be smaller than the upper bound value." ) );
328 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
329 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
331 switch ( rasterDataType )
334 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
335 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint8>::min() ).arg( std::numeric_limits<quint8>::max() ).arg( QLatin1String(
"Byte" ) ) );
339 mRandomUpperBound = std::numeric_limits<quint8>::max();
340 mRandomLowerBound = std::numeric_limits<quint8>::min();
344 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
345 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint8>::min() ).arg( std::numeric_limits<qint8>::max() ).arg( QLatin1String(
"Int8" ) ) );
349 mRandomUpperBound = std::numeric_limits<qint8>::max();
350 mRandomLowerBound = std::numeric_limits<qint8>::min();
354 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
355 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint16>::min() ).arg( std::numeric_limits<qint16>::max() ).arg( QLatin1String(
"Integer16" ) ) );
358 mRandomUpperBound = std::numeric_limits<qint16>::max();
359 mRandomLowerBound = std::numeric_limits<qint16>::min();
363 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
364 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint16>::min() ).arg( std::numeric_limits<quint16>::max() ).arg( QLatin1String(
"Unsigned Integer16" ) ) );
367 mRandomUpperBound = std::numeric_limits<quint16>::max();
368 mRandomLowerBound = std::numeric_limits<quint16>::min();
372 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
373 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint32>::min() ).arg( std::numeric_limits<qint32>::max() ).arg( QLatin1String(
"Integer32" ) ) );
376 mRandomUpperBound = std::numeric_limits<qint32>::max();
377 mRandomLowerBound = std::numeric_limits<qint32>::min();
381 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
382 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint32>::min() ).arg( std::numeric_limits<quint32>::max() ).arg( QLatin1String(
"Unsigned Integer32" ) ) );
385 mRandomUpperBound = std::numeric_limits<quint32>::max();
386 mRandomLowerBound = std::numeric_limits<quint32>::min();
392 mRandomUpperBound = std::numeric_limits<float>::max();
393 mRandomLowerBound = std::numeric_limits<float>::min();
399 mRandomUpperBound = std::numeric_limits<double>::max();
400 mRandomLowerBound = std::numeric_limits<double>::min();
413 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
414 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
419long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
421 return mRandomUniformIntDistribution( mersenneTwister );
424double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
426 return mRandomUniformDoubleDistribution( mersenneTwister );
432QString QgsRandomBinomialRasterAlgorithm::name()
const
434 return QStringLiteral(
"createrandombinomialrasterlayer" );
437QString QgsRandomBinomialRasterAlgorithm::displayName()
const
439 return QObject::tr(
"Create random raster layer (binomial distribution)" );
442QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
444 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
447QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
449 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
450 "filled with binomially distributed random values.\n"
451 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
452 "This can be overridden by using the advanced parameter for N and probability. "
453 "The raster data type is set to Integer types (Integer16 by default). "
454 "The binomial distribution random values are defined as positive integer numbers. "
455 "A floating point raster will represent a cast of integer values "
456 "to floating point." );
459QString QgsRandomBinomialRasterAlgorithm::shortDescription()
const
461 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
462 "filled with binomially distributed random values." );
465QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
467 return new QgsRandomBinomialRasterAlgorithm();
471void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams()
473 QStringList rasterDataTypes = QStringList();
474 rasterDataTypes << QStringLiteral(
"Integer16" )
475 << QStringLiteral(
"Unsigned Integer16" )
476 << QStringLiteral(
"Integer32" )
477 << QStringLiteral(
"Unsigned Integer32" )
478 << QStringLiteral(
"Float32" )
479 << QStringLiteral(
"Float64" );
481 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
483 addParameter( rasterTypeParameter.release() );
487 addParameter( nParameter.release() );
491 addParameter( probabilityParameter.release() );
494Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
515bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
517 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
518 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
519 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
523long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
525 return mRandombinomialDistribution( mersenneTwister );
528double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
530 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
536QString QgsRandomExponentialRasterAlgorithm::name()
const
538 return QStringLiteral(
"createrandomexponentialrasterlayer" );
541QString QgsRandomExponentialRasterAlgorithm::displayName()
const
543 return QObject::tr(
"Create random raster layer (exponential distribution)" );
546QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
548 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
551QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
553 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
554 "filled with exponentially distributed random values.\n"
555 "By default, the values will be chosen given a lambda of 1.0. "
556 "This can be overridden by using the advanced parameter for lambda. "
557 "The raster data type is set to Float32 by default as "
558 "the exponential distribution random values are floating point numbers." );
561QString QgsRandomExponentialRasterAlgorithm::shortDescription()
const
563 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
564 "filled with exponentially distributed random values." );
567QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
569 return new QgsRandomExponentialRasterAlgorithm();
573void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
575 QStringList rasterDataTypes = QStringList();
576 rasterDataTypes << QStringLiteral(
"Float32" )
577 << QStringLiteral(
"Float64" );
579 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
581 addParameter( rasterTypeParameter.release() );
585 addParameter( lambdaParameter.release() );
588Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
601bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
603 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
604 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
608long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
610 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
613double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
615 return mRandomExponentialDistribution( mersenneTwister );
621QString QgsRandomGammaRasterAlgorithm::name()
const
623 return QStringLiteral(
"createrandomgammarasterlayer" );
626QString QgsRandomGammaRasterAlgorithm::displayName()
const
628 return QObject::tr(
"Create random raster layer (gamma distribution)" );
631QStringList QgsRandomGammaRasterAlgorithm::tags()
const
633 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
636QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
638 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
639 "filled with gamma distributed random values.\n"
640 "By default, the values will be chosen given an alpha and beta value of 1.0. "
641 "This can be overridden by using the advanced parameter for alpha and beta. "
642 "The raster data type is set to Float32 by default as "
643 "the gamma distribution random values are floating point numbers." );
646QString QgsRandomGammaRasterAlgorithm::shortDescription()
const
648 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
649 "filled with gamma distributed random values." );
652QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
654 return new QgsRandomGammaRasterAlgorithm();
658void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
660 QStringList rasterDataTypes = QStringList();
661 rasterDataTypes << QStringLiteral(
"Float32" )
662 << QStringLiteral(
"Float64" );
664 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
666 addParameter( rasterTypeParameter.release() );
670 addParameter( alphaParameter.release() );
674 addParameter( betaParameter.release() );
677Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
690bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
692 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
693 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
694 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
698long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
700 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
703double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
705 return mRandomGammaDistribution( mersenneTwister );
711QString QgsRandomGeometricRasterAlgorithm::name()
const
713 return QStringLiteral(
"createrandomgeometricrasterlayer" );
716QString QgsRandomGeometricRasterAlgorithm::displayName()
const
718 return QObject::tr(
"Create random raster layer (geometric distribution)" );
721QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
723 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
726QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
728 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
729 "filled with geometrically distributed random values.\n"
730 "By default, the values will be chosen given a probability of 0.5. "
731 "This can be overridden by using the advanced parameter for mean "
732 "value. The raster data type is set to Integer types (Integer16 by default). "
733 "The geometric distribution random values are defined as positive integer numbers. "
734 "A floating point raster will represent a cast of "
735 "integer values to floating point." );
738QString QgsRandomGeometricRasterAlgorithm::shortDescription()
const
740 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
741 "filled with geometrically distributed random values." );
744QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
746 return new QgsRandomGeometricRasterAlgorithm();
750void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
752 QStringList rasterDataTypes = QStringList();
753 rasterDataTypes << QStringLiteral(
"Integer16" )
754 << QStringLiteral(
"Unsigned Integer16" )
755 << QStringLiteral(
"Integer32" )
756 << QStringLiteral(
"Unsigned Integer32" )
757 << QStringLiteral(
"Float32" )
758 << QStringLiteral(
"Float64" );
760 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
762 addParameter( rasterTypeParameter.release() );
766 addParameter( probabilityParameter.release() );
769Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
790bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
792 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
793 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
797long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
799 return mRandomGeometricDistribution( mersenneTwister );
802double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
804 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
810QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
812 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
815QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
817 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
820QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
822 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
825QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
827 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
828 "filled with negative binomially distributed random values.\n"
829 "By default, the values will be chosen given a distribution parameter k of 10.0 "
830 "and a probability of 0.5. "
831 "This can be overridden by using the advanced parameters for k and probability. "
832 "The raster data type is set to Integer types (Integer 16 by default). "
833 "The negative binomial distribution random values are defined as positive integer numbers. "
834 "A floating point raster will represent a cast of "
835 "integer values to floating point." );
838QString QgsRandomNegativeBinomialRasterAlgorithm::shortDescription()
const
840 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
841 "filled with negative binomially distributed random values." );
844QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
846 return new QgsRandomNegativeBinomialRasterAlgorithm();
850void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams()
852 QStringList rasterDataTypes = QStringList();
853 rasterDataTypes << QStringLiteral(
"Integer16" )
854 << QStringLiteral(
"Unsigned Integer16" )
855 << QStringLiteral(
"Integer32" )
856 << QStringLiteral(
"Unsigned Integer32" )
857 << QStringLiteral(
"Float32" )
858 << QStringLiteral(
"Float64" );
860 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
862 addParameter( rasterTypeParameter.release() );
866 addParameter( kParameter.release() );
870 addParameter( probabilityParameter.release() );
873Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
894bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
896 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
897 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
898 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
902long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
904 return mRandomNegativeBinomialDistribution( mersenneTwister );
907double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
909 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
915QString QgsRandomNormalRasterAlgorithm::name()
const
917 return QStringLiteral(
"createrandomnormalrasterlayer" );
920QString QgsRandomNormalRasterAlgorithm::displayName()
const
922 return QObject::tr(
"Create random raster layer (normal distribution)" );
925QStringList QgsRandomNormalRasterAlgorithm::tags()
const
927 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
930QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
932 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
933 "filled with normally distributed random values.\n"
934 "By default, the values will be chosen given a mean of 0.0 and "
935 "a standard deviation of 1.0. This can be overridden by "
936 "using the advanced parameters for mean and standard deviation "
937 "value. The raster data type is set to Float32 by default "
938 "as the normal distribution random values are floating point numbers." );
941QString QgsRandomNormalRasterAlgorithm::shortDescription()
const
943 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
944 "filled with normally distributed random values." );
947QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
949 return new QgsRandomNormalRasterAlgorithm();
952void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
954 QStringList rasterDataTypes = QStringList();
955 rasterDataTypes << QStringLiteral(
"Float32" )
956 << QStringLiteral(
"Float64" );
958 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
960 addParameter( rasterTypeParameter.release() );
964 addParameter( meanParameter.release() );
966 auto stdevParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 1,
true, 0 );
968 addParameter( stdevParameter.release() );
971Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
984bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
986 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
987 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
988 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
992long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
994 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
997double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
999 return mRandomNormalDistribution( mersenneTwister );
1005QString QgsRandomPoissonRasterAlgorithm::name()
const
1007 return QStringLiteral(
"createrandompoissonrasterlayer" );
1010QString QgsRandomPoissonRasterAlgorithm::displayName()
const
1012 return QObject::tr(
"Create random raster layer (poisson distribution)" );
1015QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
1017 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
1020QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
1022 return QObject::tr(
"This algorithm generates a raster layer for a given extent and cell size "
1023 "filled with poisson distributed random values.\n"
1024 "By default, the values will be chosen given a mean of 1.0. "
1025 "This can be overridden by using the advanced parameter for mean "
1026 "value. The raster data type is set to Integer types (Integer16 by default). "
1027 "The poisson distribution random values are positive integer numbers. "
1028 "A floating point raster will represent a cast of integer values to floating point." );
1031QString QgsRandomPoissonRasterAlgorithm::shortDescription()
const
1033 return QObject::tr(
"Generates a raster layer for a given extent and cell size "
1034 "filled with poisson distributed random values." );
1037QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
1039 return new QgsRandomPoissonRasterAlgorithm();
1043void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
1045 QStringList rasterDataTypes = QStringList();
1046 rasterDataTypes << QStringLiteral(
"Integer16" )
1047 << QStringLiteral(
"Unsigned Integer16" )
1048 << QStringLiteral(
"Integer32" )
1049 << QStringLiteral(
"Unsigned Integer32" )
1050 << QStringLiteral(
"Float32" )
1051 << QStringLiteral(
"Float64" );
1053 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
1055 addParameter( rasterTypeParameter.release() );
1059 addParameter( upperBoundParameter.release() );
1062Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1083bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1085 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1086 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1090long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1092 return mRandomPoissonDistribution( mersenneTwister );
1095double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1097 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).