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" ) ) );
55 mCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
56 mExtent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context, mCrs );
57 mPixelSize = parameterAsDouble( parameters, QStringLiteral(
"PIXEL_SIZE" ), context );
59 if ( mPixelSize <= 0 )
69 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
71 mRasterDataType = getRasterDataType( typeId );
72 prepareRandomParameters( parameters, context );
74 std::random_device rd {};
75 std::mt19937 mersenneTwister{rd()};
77 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
78 const QFileInfo fi( outputFile );
81 const int rows = std::max( std::ceil( mExtent.height() / mPixelSize ), 1.0 );
82 const int cols = std::max( std::ceil( mExtent.width() / mPixelSize ), 1.0 );
86 const QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
88 std::unique_ptr< QgsRasterFileWriter > writer = std::make_unique< QgsRasterFileWriter >( outputFile );
89 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
90 writer->setOutputFormat( outputFormat );
91 std::unique_ptr<QgsRasterDataProvider > provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
94 if ( !provider->isValid() )
97 const double step = rows > 0 ? 100.0 / rows : 1;
99 for (
int row = 0; row < rows ; row++ )
107 switch ( mRasterDataType )
111 std::vector<quint8> byteRow( cols );
112 for (
int col = 0; col < cols; col++ )
114 byteRow[col] =
static_cast<quint8
>( generateRandomLongValue( mersenneTwister ) );
121 std::vector<qint8> int8Row( cols );
122 for (
int col = 0; col < cols; col++ )
124 int8Row[col] =
static_cast<qint8
>( generateRandomLongValue( mersenneTwister ) );
131 std::vector<qint16> int16Row( cols );
132 for (
int col = 0; col < cols; col++ )
134 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
141 std::vector<quint16> uInt16Row( cols );
142 for (
int col = 0; col < cols; col++ )
144 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
151 std::vector<qint32> int32Row( cols );
152 for (
int col = 0; col < cols; col++ )
154 int32Row[col] = generateRandomLongValue( mersenneTwister );
161 std::vector<quint32> uInt32Row( cols );
162 for (
int col = 0; col < cols; col++ )
164 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
171 std::vector<float> float32Row( cols );
172 for (
int col = 0; col < cols; col++ )
174 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
181 std::vector<double> float64Row( cols );
182 for (
int col = 0; col < cols; col++ )
184 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
192 provider->writeBlock( &block, 1, 0, row );
197 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
204QString QgsRandomUniformRasterAlgorithm::name()
const
206 return QStringLiteral(
"createrandomuniformrasterlayer" );
209QString QgsRandomUniformRasterAlgorithm::displayName()
const
211 return QObject::tr(
"Create random raster layer (uniform distribution)" );
214QStringList QgsRandomUniformRasterAlgorithm::tags()
const
216 return QObject::tr(
"raster,create,random" ).split(
',' );
219QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
221 return QObject::tr(
"Generates a raster layer for given extent and cell size "
222 "filled with random values.\n"
223 "By default, the values will range between the minimum and "
224 "maximum value of the specified output raster type. This can "
225 "be overridden by using the advanced parameters for lower and "
226 "upper bound value. If the bounds have the same value or both "
227 "are zero (default) the algorithm will create random values in "
228 "the full value range of the chosen raster data type. "
229 "Choosing bounds outside the acceptable range of the output "
230 "raster type will abort the algorithm." );
233QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
235 return new QgsRandomUniformRasterAlgorithm();
238void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
240 QStringList rasterDataTypes = QStringList();
241 rasterDataTypes << QStringLiteral(
"Byte" )
242 << QStringLiteral(
"Integer16" )
243 << QStringLiteral(
"Unsigned Integer16" )
244 << QStringLiteral(
"Integer32" )
245 << QStringLiteral(
"Unsigned Integer32" )
246 << QStringLiteral(
"Float32" )
247 << QStringLiteral(
"Float64" );
249 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
251 addParameter( rasterTypeParameter.release() );
253 std::unique_ptr< QgsProcessingParameterNumber > lowerBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
QgsProcessingParameterNumber::Double, QVariant(),
true );
255 addParameter( lowerBoundParameter.release() );
257 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
QgsProcessingParameterNumber::Double, QVariant(),
true );
259 addParameter( upperBoundParameter.release() );
262Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
285bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
287 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
288 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
290 if ( mRandomLowerBound > mRandomUpperBound )
291 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." ) );
293 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
294 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
296 switch ( rasterDataType )
299 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
300 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" ) ) );
304 mRandomUpperBound = std::numeric_limits<quint8>::max();
305 mRandomLowerBound = std::numeric_limits<quint8>::min();
309 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
310 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" ) ) );
314 mRandomUpperBound = std::numeric_limits<qint8>::max();
315 mRandomLowerBound = std::numeric_limits<qint8>::min();
319 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
320 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" ) ) );
323 mRandomUpperBound = std::numeric_limits<qint16>::max();
324 mRandomLowerBound = std::numeric_limits<qint16>::min();
328 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
329 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" ) ) );
332 mRandomUpperBound = std::numeric_limits<quint16>::max();
333 mRandomLowerBound = std::numeric_limits<quint16>::min();
337 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
338 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" ) ) );
341 mRandomUpperBound = std::numeric_limits<qint32>::max();
342 mRandomLowerBound = std::numeric_limits<qint32>::min();
346 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
347 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" ) ) );
350 mRandomUpperBound = std::numeric_limits<quint32>::max();
351 mRandomLowerBound = std::numeric_limits<quint32>::min();
357 mRandomUpperBound = std::numeric_limits<float>::max();
358 mRandomLowerBound = std::numeric_limits<float>::min();
364 mRandomUpperBound = std::numeric_limits<double>::max();
365 mRandomLowerBound = std::numeric_limits<double>::min();
378 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
379 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
384long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
386 return mRandomUniformIntDistribution( mersenneTwister );
389double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
391 return mRandomUniformDoubleDistribution( mersenneTwister );
397QString QgsRandomBinomialRasterAlgorithm::name()
const
399 return QStringLiteral(
"createrandombinomialrasterlayer" );
402QString QgsRandomBinomialRasterAlgorithm::displayName()
const
404 return QObject::tr(
"Create random raster layer (binomial distribution)" );
407QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
409 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
412QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
414 return QObject::tr(
"Generates a raster layer for given extent and cell size "
415 "filled with binomially distributed random values.\n"
416 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
417 "This can be overridden by using the advanced parameter for N and probability. "
418 "The raster data type is set to Integer types (Integer16 by default). "
419 "The binomial distribution random values are defined as positive integer numbers. "
420 "A floating point raster will represent a cast of integer values "
421 "to floating point." );
424QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
426 return new QgsRandomBinomialRasterAlgorithm();
430void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams( )
432 QStringList rasterDataTypes = QStringList();
433 rasterDataTypes << QStringLiteral(
"Integer16" )
434 << QStringLiteral(
"Unsigned Integer16" )
435 << QStringLiteral(
"Integer32" )
436 << QStringLiteral(
"Unsigned Integer32" )
437 << QStringLiteral(
"Float32" )
438 << QStringLiteral(
"Float64" );
440 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
442 addParameter( rasterTypeParameter.release() );
444 std::unique_ptr< QgsProcessingParameterNumber > nParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"N" ), QStringLiteral(
"N" ),
QgsProcessingParameterNumber::Integer, 10,
true, 0 );
446 addParameter( nParameter.release() );
448 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0 );
450 addParameter( probabilityParameter.release() );
453Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
474bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
476 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
477 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
478 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
482long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
484 return mRandombinomialDistribution( mersenneTwister );
487double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
489 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
495QString QgsRandomExponentialRasterAlgorithm::name()
const
497 return QStringLiteral(
"createrandomexponentialrasterlayer" );
500QString QgsRandomExponentialRasterAlgorithm::displayName()
const
502 return QObject::tr(
"Create random raster layer (exponential distribution)" );
505QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
507 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
510QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
512 return QObject::tr(
"Generates a raster layer for given extent and cell size "
513 "filled with exponentially distributed random values.\n"
514 "By default, the values will be chosen given a lambda of 1.0. "
515 "This can be overridden by using the advanced parameter for lambda. "
516 "The raster data type is set to Float32 by default as "
517 "the exponential distribution random values are floating point numbers." );
520QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
522 return new QgsRandomExponentialRasterAlgorithm();
526void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
528 QStringList rasterDataTypes = QStringList();
529 rasterDataTypes << QStringLiteral(
"Float32" )
530 << QStringLiteral(
"Float64" );
532 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
534 addParameter( rasterTypeParameter.release() );
536 std::unique_ptr< QgsProcessingParameterNumber > lambdaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"LAMBDA" ), QStringLiteral(
"Lambda" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
538 addParameter( lambdaParameter.release() );
541Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
554bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
556 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
557 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
561long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
563 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
566double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
568 return mRandomExponentialDistribution( mersenneTwister );
574QString QgsRandomGammaRasterAlgorithm::name()
const
576 return QStringLiteral(
"createrandomgammarasterlayer" );
579QString QgsRandomGammaRasterAlgorithm::displayName()
const
581 return QObject::tr(
"Create random raster layer (gamma distribution)" );
584QStringList QgsRandomGammaRasterAlgorithm::tags()
const
586 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
589QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
591 return QObject::tr(
"Generates a raster layer for given extent and cell size "
592 "filled with gamma distributed random values.\n"
593 "By default, the values will be chosen given an alpha and beta value of 1.0. "
594 "This can be overridden by using the advanced parameter for alpha and beta. "
595 "The raster data type is set to Float32 by default as "
596 "the gamma distribution random values are floating point numbers." );
599QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
601 return new QgsRandomGammaRasterAlgorithm();
605void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
607 QStringList rasterDataTypes = QStringList();
608 rasterDataTypes << QStringLiteral(
"Float32" )
609 << QStringLiteral(
"Float64" );
611 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
613 addParameter( rasterTypeParameter.release() );
615 std::unique_ptr< QgsProcessingParameterNumber > alphaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ALPHA" ), QStringLiteral(
"Alpha" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
617 addParameter( alphaParameter.release() );
619 std::unique_ptr< QgsProcessingParameterNumber > betaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"BETA" ), QStringLiteral(
"Beta" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
621 addParameter( betaParameter.release() );
624Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
637bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
639 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
640 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
641 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
645long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
647 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
650double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
652 return mRandomGammaDistribution( mersenneTwister );
658QString QgsRandomGeometricRasterAlgorithm::name()
const
660 return QStringLiteral(
"createrandomgeometricrasterlayer" );
663QString QgsRandomGeometricRasterAlgorithm::displayName()
const
665 return QObject::tr(
"Create random raster layer (geometric distribution)" );
668QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
670 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
673QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
675 return QObject::tr(
"Generates a raster layer for given extent and cell size "
676 "filled with geometrically distributed random values.\n"
677 "By default, the values will be chosen given a probability of 0.5. "
678 "This can be overridden by using the advanced parameter for mean "
679 "value. The raster data type is set to Integer types (Integer16 by default). "
680 "The geometric distribution random values are defined as positive integer numbers. "
681 "A floating point raster will represent a cast of "
682 "integer values to floating point." );
685QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
687 return new QgsRandomGeometricRasterAlgorithm();
691void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
693 QStringList rasterDataTypes = QStringList();
694 rasterDataTypes << QStringLiteral(
"Integer16" )
695 << QStringLiteral(
"Unsigned Integer16" )
696 << QStringLiteral(
"Integer32" )
697 << QStringLiteral(
"Unsigned Integer32" )
698 << QStringLiteral(
"Float32" )
699 << QStringLiteral(
"Float64" );
701 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
703 addParameter( rasterTypeParameter.release() );
705 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0.00001 );
707 addParameter( probabilityParameter.release() );
710Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
731bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
733 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
734 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
738long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
740 return mRandomGeometricDistribution( mersenneTwister );
743double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
745 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
751QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
753 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
756QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
758 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
761QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
763 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
766QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
768 return QObject::tr(
"Generates a raster layer for given extent and cell size "
769 "filled with negative binomially distributed random values.\n"
770 "By default, the values will be chosen given a distribution parameter k of 10.0 "
771 "and a probability of 0.5. "
772 "This can be overridden by using the advanced parameters for k and probability. "
773 "The raster data type is set to Integer types (Integer 16 by default). "
774 "The negative binomial distribution random values are defined as positive integer numbers. "
775 "A floating point raster will represent a cast of "
776 "integer values to floating point." );
779QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
781 return new QgsRandomNegativeBinomialRasterAlgorithm();
785void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams( )
787 QStringList rasterDataTypes = QStringList();
788 rasterDataTypes << QStringLiteral(
"Integer16" )
789 << QStringLiteral(
"Unsigned Integer16" )
790 << QStringLiteral(
"Integer32" )
791 << QStringLiteral(
"Unsigned Integer32" )
792 << QStringLiteral(
"Float32" )
793 << QStringLiteral(
"Float64" );
795 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
797 addParameter( rasterTypeParameter.release() );
799 std::unique_ptr< QgsProcessingParameterNumber > kParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"K_PARAMETER" ), QStringLiteral(
"Distribution parameter k" ),
QgsProcessingParameterNumber::Integer, 10,
true, 0.00001 );
801 addParameter( kParameter.release() );
803 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0.00001 );
805 addParameter( probabilityParameter.release() );
808Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
829bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
831 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
832 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
833 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
837long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
839 return mRandomNegativeBinomialDistribution( mersenneTwister );
842double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
844 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
850QString QgsRandomNormalRasterAlgorithm::name()
const
852 return QStringLiteral(
"createrandomnormalrasterlayer" );
855QString QgsRandomNormalRasterAlgorithm::displayName()
const
857 return QObject::tr(
"Create random raster layer (normal distribution)" );
860QStringList QgsRandomNormalRasterAlgorithm::tags()
const
862 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
865QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
867 return QObject::tr(
"Generates a raster layer for given extent and cell size "
868 "filled with normally distributed random values.\n"
869 "By default, the values will be chosen given a mean of 0.0 and "
870 "a standard deviation of 1.0. This can be overridden by "
871 "using the advanced parameters for mean and standard deviation "
872 "value. The raster data type is set to Float32 by default "
873 "as the normal distribution random values are floating point numbers." );
876QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
878 return new QgsRandomNormalRasterAlgorithm();
881void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
883 QStringList rasterDataTypes = QStringList();
884 rasterDataTypes << QStringLiteral(
"Float32" )
885 << QStringLiteral(
"Float64" );
887 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
889 addParameter( rasterTypeParameter.release() );
891 std::unique_ptr< QgsProcessingParameterNumber > meanParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean of normal distribution" ),
QgsProcessingParameterNumber::Double, 0,
true );
893 addParameter( meanParameter.release() );
895 std::unique_ptr< QgsProcessingParameterNumber > stdevParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
QgsProcessingParameterNumber::Double, 1,
true, 0 );
897 addParameter( stdevParameter.release() );
900Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
913bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
915 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
916 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
917 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
921long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
923 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
926double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
928 return mRandomNormalDistribution( mersenneTwister );
934QString QgsRandomPoissonRasterAlgorithm::name()
const
936 return QStringLiteral(
"createrandompoissonrasterlayer" );
939QString QgsRandomPoissonRasterAlgorithm::displayName()
const
941 return QObject::tr(
"Create random raster layer (poisson distribution)" );
944QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
946 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
949QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
951 return QObject::tr(
"Generates a raster layer for given extent and cell size "
952 "filled with poisson distributed random values.\n"
953 "By default, the values will be chosen given a mean of 1.0. "
954 "This can be overridden by using the advanced parameter for mean "
955 "value. The raster data type is set to Integer types (Integer16 by default). "
956 "The poisson distribution random values are positive integer numbers. "
957 "A floating point raster will represent a cast of integer values to floating point." );
960QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
962 return new QgsRandomPoissonRasterAlgorithm();
966void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
968 QStringList rasterDataTypes = QStringList();
969 rasterDataTypes << QStringLiteral(
"Integer16" )
970 << QStringLiteral(
"Unsigned Integer16" )
971 << QStringLiteral(
"Integer32" )
972 << QStringLiteral(
"Unsigned Integer32" )
973 << QStringLiteral(
"Float32" )
974 << QStringLiteral(
"Float64" );
976 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
978 addParameter( rasterTypeParameter.release() );
980 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0 );
982 addParameter( upperBoundParameter.release() );
985Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1006bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1008 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1009 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1013long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1015 return mRandomPoissonDistribution( mersenneTwister );
1018double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1020 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)
bool isCanceled() const SIP_HOLDGIL
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.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
A rectangular map extent parameter for processing algorithms.
A numeric parameter for processing algorithms.
@ Double
Double/float values.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
static int typeSize(Qgis::DataType dataType) SIP_HOLDGIL
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)