29 QString QgsRandomRasterAlgorithmBase::group()
const
31 return QObject::tr(
"Raster creation" );
34 QString QgsRandomRasterAlgorithmBase::groupId()
const
36 return QStringLiteral(
"rastercreation" );
39 void 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 );
64 int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
66 mRasterDataType = getRasterDataType( typeId );
67 prepareRandomParameters( parameters, context );
69 std::random_device rd {};
70 std::mt19937 mersenneTwister{rd()};
72 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
73 QFileInfo fi( outputFile );
76 int rows = std::max( std::ceil( mExtent.height() / mPixelSize ), 1.0 );
77 int cols = std::max( std::ceil( mExtent.width() / mPixelSize ), 1.0 );
81 QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
83 std::unique_ptr< QgsRasterFileWriter > writer = qgis::make_unique< QgsRasterFileWriter >( outputFile );
84 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
85 writer->setOutputFormat( outputFormat );
86 std::unique_ptr<QgsRasterDataProvider > provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
89 if ( !provider->isValid() )
92 double step = rows > 0 ? 100.0 / rows : 1;
94 for (
int row = 0; row < rows ; row++ )
102 switch ( mRasterDataType )
106 std::vector<quint8> byteRow( cols );
107 for (
int col = 0; col < cols; col++ )
109 byteRow[col] =
static_cast<quint8
>( generateRandomLongValue( mersenneTwister ) );
116 std::vector<qint16> int16Row( cols );
117 for (
int col = 0; col < cols; col++ )
119 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
126 std::vector<quint16> uInt16Row( cols );
127 for (
int col = 0; col < cols; col++ )
129 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
136 std::vector<qint32> int32Row( cols );
137 for (
int col = 0; col < cols; col++ )
139 int32Row[col] = generateRandomLongValue( mersenneTwister );
146 std::vector<quint32> uInt32Row( cols );
147 for (
int col = 0; col < cols; col++ )
149 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
156 std::vector<float> float32Row( cols );
157 for (
int col = 0; col < cols; col++ )
159 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
166 std::vector<double> float64Row( cols );
167 for (
int col = 0; col < cols; col++ )
169 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
177 provider->writeBlock( &block, 1, 0, row );
182 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
189 QString QgsRandomUniformRasterAlgorithm::name()
const
191 return QStringLiteral(
"createrandomuniformrasterlayer" );
194 QString QgsRandomUniformRasterAlgorithm::displayName()
const
196 return QObject::tr(
"Create random raster layer (uniform distribution)" );
199 QStringList QgsRandomUniformRasterAlgorithm::tags()
const
201 return QObject::tr(
"raster,create,random" ).split(
',' );
204 QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
206 return QObject::tr(
"Generates a raster layer for given extent and cell size "
207 "filled with random values.\n"
208 "By default, the values will range between the minimum and "
209 "maximum value of the specified output raster type. This can "
210 "be overridden by using the advanced parameters for lower and "
211 "upper bound value. If the bounds have the same value or both "
212 "are zero (default) the algorithm will create random values in "
213 "the full value range of the chosen raster data type. "
214 "Choosing bounds outside the acceptable range of the output "
215 "raster type will abort the algorithm." );
218 QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
220 return new QgsRandomUniformRasterAlgorithm();
223 void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
225 QStringList rasterDataTypes = QStringList();
226 rasterDataTypes << QStringLiteral(
"Byte" )
227 << QStringLiteral(
"Integer16" )
228 << QStringLiteral(
"Unsigned Integer16" )
229 << QStringLiteral(
"Integer32" )
230 << QStringLiteral(
"Unsigned Integer32" )
231 << QStringLiteral(
"Float32" )
232 << QStringLiteral(
"Float64" );
234 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
236 addParameter( rasterTypeParameter.release() );
238 std::unique_ptr< QgsProcessingParameterNumber > lowerBoundParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
QgsProcessingParameterNumber::Double, QVariant(),
true );
240 addParameter( lowerBoundParameter.release() );
242 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
QgsProcessingParameterNumber::Double, QVariant(),
true );
244 addParameter( upperBoundParameter.release() );
247 Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
270 bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
272 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
273 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
275 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
276 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
278 if ( mRandomLowerBound > mRandomUpperBound )
279 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." ) );
281 int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
284 switch ( rasterDataType )
287 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
288 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" ) ) );
292 mRandomUpperBound = std::numeric_limits<quint8>::max();
293 mRandomLowerBound = std::numeric_limits<quint8>::min();
297 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
298 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" ) ) );
301 mRandomUpperBound = std::numeric_limits<qint16>::max();
302 mRandomLowerBound = std::numeric_limits<qint16>::min();
306 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
307 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" ) ) );
310 mRandomUpperBound = std::numeric_limits<quint16>::max();
311 mRandomLowerBound = std::numeric_limits<quint16>::min();
315 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
316 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" ) ) );
319 mRandomUpperBound = std::numeric_limits<qint32>::max();
320 mRandomLowerBound = std::numeric_limits<qint32>::min();
324 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
325 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" ) ) );
328 mRandomUpperBound = std::numeric_limits<quint32>::max();
329 mRandomLowerBound = std::numeric_limits<quint32>::min();
335 mRandomUpperBound = std::numeric_limits<float>::max();
336 mRandomLowerBound = std::numeric_limits<float>::min();
342 mRandomUpperBound = std::numeric_limits<double>::max();
343 mRandomLowerBound = std::numeric_limits<double>::min();
352 long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
354 return mRandomUniformIntDistribution( mersenneTwister );
357 double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
359 return mRandomUniformIntDistribution( mersenneTwister );
365 QString QgsRandomBinomialRasterAlgorithm::name()
const
367 return QStringLiteral(
"createrandombinomialrasterlayer" );
370 QString QgsRandomBinomialRasterAlgorithm::displayName()
const
372 return QObject::tr(
"Create random raster layer (binomial distribution)" );
375 QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
377 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
380 QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
382 return QObject::tr(
"Generates a raster layer for given extent and cell size "
383 "filled with binomially distributed random values.\n"
384 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
385 "This can be overridden by using the advanced parameter for N and probability. "
386 "The raster data type is set to Integer types (Integer16 by default). "
387 "The binomial distribution random values are defined as positive integer numbers. "
388 "A floating point raster will represent a cast of integer values "
389 "to floating point." );
392 QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
394 return new QgsRandomBinomialRasterAlgorithm();
398 void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams( )
400 QStringList rasterDataTypes = QStringList();
401 rasterDataTypes << QStringLiteral(
"Integer16" )
402 << QStringLiteral(
"Unsigned Integer16" )
403 << QStringLiteral(
"Integer32" )
404 << QStringLiteral(
"Unsigned Integer32" )
405 << QStringLiteral(
"Float32" )
406 << QStringLiteral(
"Float64" );
408 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
410 addParameter( rasterTypeParameter.release() );
412 std::unique_ptr< QgsProcessingParameterNumber > nParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"N" ), QStringLiteral(
"N" ),
QgsProcessingParameterNumber::Integer, 10,
true, 0 );
414 addParameter( nParameter.release() );
416 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0 );
418 addParameter( probabilityParameter.release() );
421 Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
442 bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
444 int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
445 double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
446 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
450 long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
452 return mRandombinomialDistribution( mersenneTwister );
455 double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
457 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
463 QString QgsRandomExponentialRasterAlgorithm::name()
const
465 return QStringLiteral(
"createrandomexponentialrasterlayer" );
468 QString QgsRandomExponentialRasterAlgorithm::displayName()
const
470 return QObject::tr(
"Create random raster layer (exponential distribution)" );
473 QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
475 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
478 QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
480 return QObject::tr(
"Generates a raster layer for given extent and cell size "
481 "filled with exponentially distributed random values.\n"
482 "By default, the values will be chosen given a lambda of 1.0. "
483 "This can be overridden by using the advanced parameter for lambda. "
484 "The raster data type is set to Float32 by default as "
485 "the exponential distribution random values are floating point numbers." );
488 QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
490 return new QgsRandomExponentialRasterAlgorithm();
494 void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
496 QStringList rasterDataTypes = QStringList();
497 rasterDataTypes << QStringLiteral(
"Float32" )
498 << QStringLiteral(
"Float64" );
500 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
502 addParameter( rasterTypeParameter.release() );
504 std::unique_ptr< QgsProcessingParameterNumber > lambdaParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"LAMBDA" ), QStringLiteral(
"Lambda" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
506 addParameter( lambdaParameter.release() );
509 Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
522 bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
524 double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
525 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
529 long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
531 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
534 double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
536 return mRandomExponentialDistribution( mersenneTwister );
542 QString QgsRandomGammaRasterAlgorithm::name()
const
544 return QStringLiteral(
"createrandomgammarasterlayer" );
547 QString QgsRandomGammaRasterAlgorithm::displayName()
const
549 return QObject::tr(
"Create random raster layer (gamma distribution)" );
552 QStringList QgsRandomGammaRasterAlgorithm::tags()
const
554 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
557 QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
559 return QObject::tr(
"Generates a raster layer for given extent and cell size "
560 "filled with gamma distributed random values.\n"
561 "By default, the values will be chosen given an alpha and beta value of 1.0. "
562 "This can be overridden by using the advanced parameter for alpha and beta. "
563 "The raster data type is set to Float32 by default as "
564 "the gamma distribution random values are floating point numbers." );
567 QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
569 return new QgsRandomGammaRasterAlgorithm();
573 void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
575 QStringList rasterDataTypes = QStringList();
576 rasterDataTypes << QStringLiteral(
"Float32" )
577 << QStringLiteral(
"Float64" );
579 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
581 addParameter( rasterTypeParameter.release() );
583 std::unique_ptr< QgsProcessingParameterNumber > alphaParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ALPHA" ), QStringLiteral(
"Alpha" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
585 addParameter( alphaParameter.release() );
587 std::unique_ptr< QgsProcessingParameterNumber > betaParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"BETA" ), QStringLiteral(
"Beta" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
589 addParameter( betaParameter.release() );
592 Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
605 bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
607 double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
608 double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
609 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
613 long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
615 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
618 double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
620 return mRandomGammaDistribution( mersenneTwister );
626 QString QgsRandomGeometricRasterAlgorithm::name()
const
628 return QStringLiteral(
"createrandomgeometricrasterlayer" );
631 QString QgsRandomGeometricRasterAlgorithm::displayName()
const
633 return QObject::tr(
"Create random raster layer (geometric distribution)" );
636 QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
638 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
641 QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
643 return QObject::tr(
"Generates a raster layer for given extent and cell size "
644 "filled with geometrically distributed random values.\n"
645 "By default, the values will be chosen given a probability of 0.5. "
646 "This can be overridden by using the advanced parameter for mean "
647 "value. The raster data type is set to Integer types (Integer16 by default). "
648 "The geometric distribution random values are defined as positive integer numbers. "
649 "A floating point raster will represent a cast of "
650 "integer values to floating point." );
653 QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
655 return new QgsRandomGeometricRasterAlgorithm();
659 void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
661 QStringList rasterDataTypes = QStringList();
662 rasterDataTypes << QStringLiteral(
"Integer16" )
663 << QStringLiteral(
"Unsigned Integer16" )
664 << QStringLiteral(
"Integer32" )
665 << QStringLiteral(
"Unsigned Integer32" )
666 << QStringLiteral(
"Float32" )
667 << QStringLiteral(
"Float64" );
669 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
671 addParameter( rasterTypeParameter.release() );
673 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0.00001 );
675 addParameter( probabilityParameter.release() );
678 Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
699 bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
701 double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
702 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
706 long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
708 return mRandomGeometricDistribution( mersenneTwister );
711 double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
713 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
719 QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
721 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
724 QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
726 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
729 QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
731 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
734 QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
736 return QObject::tr(
"Generates a raster layer for given extent and cell size "
737 "filled with negative binomially distributed random values.\n"
738 "By default, the values will be chosen given a distribution parameter k of 10.0 "
739 "and a probability of 0.5. "
740 "This can be overridden by using the advanced parameters for k and probability. "
741 "The raster data type is set to Integer types (Integer 16 by default). "
742 "The negative binomial distribution random values are defined as positive integer numbers. "
743 "A floating point raster will represent a cast of "
744 "integer values to floating point." );
747 QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
749 return new QgsRandomNegativeBinomialRasterAlgorithm();
753 void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams( )
755 QStringList rasterDataTypes = QStringList();
756 rasterDataTypes << QStringLiteral(
"Integer16" )
757 << QStringLiteral(
"Unsigned Integer16" )
758 << QStringLiteral(
"Integer32" )
759 << QStringLiteral(
"Unsigned Integer32" )
760 << QStringLiteral(
"Float32" )
761 << QStringLiteral(
"Float64" );
763 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
765 addParameter( rasterTypeParameter.release() );
767 std::unique_ptr< QgsProcessingParameterNumber > kParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"K_PARAMETER" ), QStringLiteral(
"Distribution parameter k" ),
QgsProcessingParameterNumber::Integer, 10,
true, 0.00001 );
769 addParameter( kParameter.release() );
771 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0.00001 );
773 addParameter( probabilityParameter.release() );
776 Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
797 bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
799 int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
800 double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
801 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
805 long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
807 return mRandomNegativeBinomialDistribution( mersenneTwister );
810 double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
812 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
818 QString QgsRandomNormalRasterAlgorithm::name()
const
820 return QStringLiteral(
"createrandomnormalrasterlayer" );
823 QString QgsRandomNormalRasterAlgorithm::displayName()
const
825 return QObject::tr(
"Create random raster layer (normal distribution)" );
828 QStringList QgsRandomNormalRasterAlgorithm::tags()
const
830 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
833 QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
835 return QObject::tr(
"Generates a raster layer for given extent and cell size "
836 "filled with normally distributed random values.\n"
837 "By default, the values will be chosen given a mean of 0.0 and "
838 "a standard deviation of 1.0. This can be overridden by "
839 "using the advanced parameters for mean and standard deviation "
840 "value. The raster data type is set to Float32 by default "
841 "as the normal distribution random values are floating point numbers." );
844 QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
846 return new QgsRandomNormalRasterAlgorithm();
849 void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
851 QStringList rasterDataTypes = QStringList();
852 rasterDataTypes << QStringLiteral(
"Float32" )
853 << QStringLiteral(
"Float64" );
855 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
857 addParameter( rasterTypeParameter.release() );
859 std::unique_ptr< QgsProcessingParameterNumber > meanParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean of normal distribution" ),
QgsProcessingParameterNumber::Double, 0,
true );
861 addParameter( meanParameter.release() );
863 std::unique_ptr< QgsProcessingParameterNumber > stdevParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
QgsProcessingParameterNumber::Double, 1,
true, 0 );
865 addParameter( stdevParameter.release() );
868 Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
881 bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
883 double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
884 double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
885 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
889 long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
891 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
894 double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
896 return mRandomNormalDistribution( mersenneTwister );
902 QString QgsRandomPoissonRasterAlgorithm::name()
const
904 return QStringLiteral(
"createrandompoissonrasterlayer" );
907 QString QgsRandomPoissonRasterAlgorithm::displayName()
const
909 return QObject::tr(
"Create random raster layer (poisson distribution)" );
912 QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
914 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
917 QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
919 return QObject::tr(
"Generates a raster layer for given extent and cell size "
920 "filled with poisson distributed random values.\n"
921 "By default, the values will be chosen given a mean of 1.0. "
922 "This can be overridden by using the advanced parameter for mean "
923 "value. The raster data type is set to Integer types (Integer16 by default). "
924 "The poisson distribution random values are positive integer numbers. "
925 "A floating point raster will represent a cast of integer values to floating point." );
928 QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
930 return new QgsRandomPoissonRasterAlgorithm();
934 void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
936 QStringList rasterDataTypes = QStringList();
937 rasterDataTypes << QStringLiteral(
"Integer16" )
938 << QStringLiteral(
"Unsigned Integer16" )
939 << QStringLiteral(
"Integer32" )
940 << QStringLiteral(
"Unsigned Integer32" )
941 << QStringLiteral(
"Float32" )
942 << QStringLiteral(
"Float64" );
944 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
946 addParameter( rasterTypeParameter.release() );
948 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = qgis::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0 );
950 addParameter( upperBoundParameter.release() );
953 Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
974 bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
976 double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
977 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
981 long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
983 return mRandomPoissonDistribution( mersenneTwister );
986 double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
988 return static_cast<double>( mRandomPoissonDistribution( mersenneTwister ) );