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" ) ) );
48 auto createOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATE_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
49 createOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
51 addParameter( createOptsParam.release() );
59 mCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
60 mExtent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context, mCrs );
61 mPixelSize = parameterAsDouble( parameters, QStringLiteral(
"PIXEL_SIZE" ), context );
63 if ( mPixelSize <= 0 )
73 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
75 mRasterDataType = getRasterDataType( typeId );
76 prepareRandomParameters( parameters, context );
78 std::random_device rd {};
79 std::mt19937 mersenneTwister { rd() };
81 const QString createOptions = parameterAsString( parameters, QStringLiteral(
"CREATE_OPTIONS" ), context ).trimmed();
82 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
83 const QFileInfo fi( outputFile );
88 const int rows =
static_cast<int>( 0.5 + mExtent.height() / mPixelSize );
89 const int cols =
static_cast<int>( 0.5 + mExtent.width() / mPixelSize );
93 const QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
95 auto writer = std::make_unique<QgsRasterFileWriter>( outputFile );
96 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
97 if ( !createOptions.isEmpty() )
99 writer->setCreateOptions( createOptions.split(
'|' ) );
102 writer->setOutputFormat( outputFormat );
103 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
106 if ( !provider->isValid() )
109 const double step = rows > 0 ? 100.0 / rows : 1;
111 for (
int row = 0; row < rows; row++ )
119 switch ( mRasterDataType )
123 std::vector<quint8> byteRow( cols );
124 for (
int col = 0; col < cols; col++ )
126 byteRow[col] =
static_cast<quint8
>( generateRandomLongValue( mersenneTwister ) );
133 std::vector<qint8> int8Row( cols );
134 for (
int col = 0; col < cols; col++ )
136 int8Row[col] =
static_cast<qint8
>( generateRandomLongValue( mersenneTwister ) );
143 std::vector<qint16> int16Row( cols );
144 for (
int col = 0; col < cols; col++ )
146 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
153 std::vector<quint16> uInt16Row( cols );
154 for (
int col = 0; col < cols; col++ )
156 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
163 std::vector<qint32> int32Row( cols );
164 for (
int col = 0; col < cols; col++ )
166 int32Row[col] = generateRandomLongValue( mersenneTwister );
173 std::vector<quint32> uInt32Row( cols );
174 for (
int col = 0; col < cols; col++ )
176 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
183 std::vector<float> float32Row( cols );
184 for (
int col = 0; col < cols; col++ )
186 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
193 std::vector<double> float64Row( cols );
194 for (
int col = 0; col < cols; col++ )
196 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
204 if ( !provider->writeBlock( &block, 1, 0, row ) )
206 throw QgsProcessingException( QObject::tr(
"Could not write raster block: %1" ).arg( provider->error().summary() ) );
212 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
219QString QgsRandomUniformRasterAlgorithm::name()
const
221 return QStringLiteral(
"createrandomuniformrasterlayer" );
224QString QgsRandomUniformRasterAlgorithm::displayName()
const
226 return QObject::tr(
"Create random raster layer (uniform distribution)" );
229QStringList QgsRandomUniformRasterAlgorithm::tags()
const
231 return QObject::tr(
"raster,create,random" ).split(
',' );
234QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
236 return QObject::tr(
"Generates a raster layer for given extent and cell size "
237 "filled with random values.\n"
238 "By default, the values will range between the minimum and "
239 "maximum value of the specified output raster type. This can "
240 "be overridden by using the advanced parameters for lower and "
241 "upper bound value. If the bounds have the same value or both "
242 "are zero (default) the algorithm will create random values in "
243 "the full value range of the chosen raster data type. "
244 "Choosing bounds outside the acceptable range of the output "
245 "raster type will abort the algorithm." );
248QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
250 return new QgsRandomUniformRasterAlgorithm();
253void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
255 QStringList rasterDataTypes = QStringList();
256 rasterDataTypes << QStringLiteral(
"Byte" )
257 << QStringLiteral(
"Integer16" )
258 << QStringLiteral(
"Unsigned Integer16" )
259 << QStringLiteral(
"Integer32" )
260 << QStringLiteral(
"Unsigned Integer32" )
261 << QStringLiteral(
"Float32" )
262 << QStringLiteral(
"Float64" );
264 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
266 addParameter( rasterTypeParameter.release() );
268 auto lowerBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
270 addParameter( lowerBoundParameter.release() );
272 auto upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
274 addParameter( upperBoundParameter.release() );
277Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
300bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
302 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
303 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
305 if ( mRandomLowerBound > mRandomUpperBound )
306 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." ) );
308 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
309 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
311 switch ( rasterDataType )
314 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
315 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" ) ) );
319 mRandomUpperBound = std::numeric_limits<quint8>::max();
320 mRandomLowerBound = std::numeric_limits<quint8>::min();
324 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::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<qint8>::min() ).arg( std::numeric_limits<qint8>::max() ).arg( QLatin1String(
"Int8" ) ) );
329 mRandomUpperBound = std::numeric_limits<qint8>::max();
330 mRandomLowerBound = std::numeric_limits<qint8>::min();
334 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
335 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" ) ) );
338 mRandomUpperBound = std::numeric_limits<qint16>::max();
339 mRandomLowerBound = std::numeric_limits<qint16>::min();
343 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
344 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint16>::min() ).arg( std::numeric_limits<quint16>::max() ).arg( QLatin1String(
"Unsigned Integer16" ) ) );
347 mRandomUpperBound = std::numeric_limits<quint16>::max();
348 mRandomLowerBound = std::numeric_limits<quint16>::min();
352 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
353 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<qint32>::min() ).arg( std::numeric_limits<qint32>::max() ).arg( QLatin1String(
"Integer32" ) ) );
356 mRandomUpperBound = std::numeric_limits<qint32>::max();
357 mRandomLowerBound = std::numeric_limits<qint32>::min();
361 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
362 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint32>::min() ).arg( std::numeric_limits<quint32>::max() ).arg( QLatin1String(
"Unsigned Integer32" ) ) );
365 mRandomUpperBound = std::numeric_limits<quint32>::max();
366 mRandomLowerBound = std::numeric_limits<quint32>::min();
372 mRandomUpperBound = std::numeric_limits<float>::max();
373 mRandomLowerBound = std::numeric_limits<float>::min();
379 mRandomUpperBound = std::numeric_limits<double>::max();
380 mRandomLowerBound = std::numeric_limits<double>::min();
393 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
394 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
399long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
401 return mRandomUniformIntDistribution( mersenneTwister );
404double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
406 return mRandomUniformDoubleDistribution( mersenneTwister );
412QString QgsRandomBinomialRasterAlgorithm::name()
const
414 return QStringLiteral(
"createrandombinomialrasterlayer" );
417QString QgsRandomBinomialRasterAlgorithm::displayName()
const
419 return QObject::tr(
"Create random raster layer (binomial distribution)" );
422QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
424 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
427QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
429 return QObject::tr(
"Generates a raster layer for given extent and cell size "
430 "filled with binomially distributed random values.\n"
431 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
432 "This can be overridden by using the advanced parameter for N and probability. "
433 "The raster data type is set to Integer types (Integer16 by default). "
434 "The binomial distribution random values are defined as positive integer numbers. "
435 "A floating point raster will represent a cast of integer values "
436 "to floating point." );
439QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
441 return new QgsRandomBinomialRasterAlgorithm();
445void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams()
447 QStringList rasterDataTypes = QStringList();
448 rasterDataTypes << QStringLiteral(
"Integer16" )
449 << QStringLiteral(
"Unsigned Integer16" )
450 << QStringLiteral(
"Integer32" )
451 << QStringLiteral(
"Unsigned Integer32" )
452 << QStringLiteral(
"Float32" )
453 << QStringLiteral(
"Float64" );
455 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
457 addParameter( rasterTypeParameter.release() );
461 addParameter( nParameter.release() );
465 addParameter( probabilityParameter.release() );
468Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
489bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
491 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
492 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
493 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
497long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
499 return mRandombinomialDistribution( mersenneTwister );
502double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
504 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
510QString QgsRandomExponentialRasterAlgorithm::name()
const
512 return QStringLiteral(
"createrandomexponentialrasterlayer" );
515QString QgsRandomExponentialRasterAlgorithm::displayName()
const
517 return QObject::tr(
"Create random raster layer (exponential distribution)" );
520QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
522 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
525QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
527 return QObject::tr(
"Generates a raster layer for given extent and cell size "
528 "filled with exponentially distributed random values.\n"
529 "By default, the values will be chosen given a lambda of 1.0. "
530 "This can be overridden by using the advanced parameter for lambda. "
531 "The raster data type is set to Float32 by default as "
532 "the exponential distribution random values are floating point numbers." );
535QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
537 return new QgsRandomExponentialRasterAlgorithm();
541void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
543 QStringList rasterDataTypes = QStringList();
544 rasterDataTypes << QStringLiteral(
"Float32" )
545 << QStringLiteral(
"Float64" );
547 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
549 addParameter( rasterTypeParameter.release() );
553 addParameter( lambdaParameter.release() );
556Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
569bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
571 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
572 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
576long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
578 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
581double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
583 return mRandomExponentialDistribution( mersenneTwister );
589QString QgsRandomGammaRasterAlgorithm::name()
const
591 return QStringLiteral(
"createrandomgammarasterlayer" );
594QString QgsRandomGammaRasterAlgorithm::displayName()
const
596 return QObject::tr(
"Create random raster layer (gamma distribution)" );
599QStringList QgsRandomGammaRasterAlgorithm::tags()
const
601 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
604QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
606 return QObject::tr(
"Generates a raster layer for given extent and cell size "
607 "filled with gamma distributed random values.\n"
608 "By default, the values will be chosen given an alpha and beta value of 1.0. "
609 "This can be overridden by using the advanced parameter for alpha and beta. "
610 "The raster data type is set to Float32 by default as "
611 "the gamma distribution random values are floating point numbers." );
614QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
616 return new QgsRandomGammaRasterAlgorithm();
620void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
622 QStringList rasterDataTypes = QStringList();
623 rasterDataTypes << QStringLiteral(
"Float32" )
624 << QStringLiteral(
"Float64" );
626 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
628 addParameter( rasterTypeParameter.release() );
632 addParameter( alphaParameter.release() );
636 addParameter( betaParameter.release() );
639Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
652bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
654 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
655 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
656 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
660long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
662 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
665double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
667 return mRandomGammaDistribution( mersenneTwister );
673QString QgsRandomGeometricRasterAlgorithm::name()
const
675 return QStringLiteral(
"createrandomgeometricrasterlayer" );
678QString QgsRandomGeometricRasterAlgorithm::displayName()
const
680 return QObject::tr(
"Create random raster layer (geometric distribution)" );
683QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
685 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
688QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
690 return QObject::tr(
"Generates a raster layer for given extent and cell size "
691 "filled with geometrically distributed random values.\n"
692 "By default, the values will be chosen given a probability of 0.5. "
693 "This can be overridden by using the advanced parameter for mean "
694 "value. The raster data type is set to Integer types (Integer16 by default). "
695 "The geometric distribution random values are defined as positive integer numbers. "
696 "A floating point raster will represent a cast of "
697 "integer values to floating point." );
700QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
702 return new QgsRandomGeometricRasterAlgorithm();
706void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
708 QStringList rasterDataTypes = QStringList();
709 rasterDataTypes << QStringLiteral(
"Integer16" )
710 << QStringLiteral(
"Unsigned Integer16" )
711 << QStringLiteral(
"Integer32" )
712 << QStringLiteral(
"Unsigned Integer32" )
713 << QStringLiteral(
"Float32" )
714 << QStringLiteral(
"Float64" );
716 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
718 addParameter( rasterTypeParameter.release() );
722 addParameter( probabilityParameter.release() );
725Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
746bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
748 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
749 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
753long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
755 return mRandomGeometricDistribution( mersenneTwister );
758double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
760 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
766QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
768 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
771QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
773 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
776QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
778 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
781QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
783 return QObject::tr(
"Generates a raster layer for given extent and cell size "
784 "filled with negative binomially distributed random values.\n"
785 "By default, the values will be chosen given a distribution parameter k of 10.0 "
786 "and a probability of 0.5. "
787 "This can be overridden by using the advanced parameters for k and probability. "
788 "The raster data type is set to Integer types (Integer 16 by default). "
789 "The negative binomial distribution random values are defined as positive integer numbers. "
790 "A floating point raster will represent a cast of "
791 "integer values to floating point." );
794QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
796 return new QgsRandomNegativeBinomialRasterAlgorithm();
800void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams()
802 QStringList rasterDataTypes = QStringList();
803 rasterDataTypes << QStringLiteral(
"Integer16" )
804 << QStringLiteral(
"Unsigned Integer16" )
805 << QStringLiteral(
"Integer32" )
806 << QStringLiteral(
"Unsigned Integer32" )
807 << QStringLiteral(
"Float32" )
808 << QStringLiteral(
"Float64" );
810 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
812 addParameter( rasterTypeParameter.release() );
816 addParameter( kParameter.release() );
820 addParameter( probabilityParameter.release() );
823Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
844bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
846 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
847 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
848 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
852long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
854 return mRandomNegativeBinomialDistribution( mersenneTwister );
857double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
859 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
865QString QgsRandomNormalRasterAlgorithm::name()
const
867 return QStringLiteral(
"createrandomnormalrasterlayer" );
870QString QgsRandomNormalRasterAlgorithm::displayName()
const
872 return QObject::tr(
"Create random raster layer (normal distribution)" );
875QStringList QgsRandomNormalRasterAlgorithm::tags()
const
877 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
880QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
882 return QObject::tr(
"Generates a raster layer for given extent and cell size "
883 "filled with normally distributed random values.\n"
884 "By default, the values will be chosen given a mean of 0.0 and "
885 "a standard deviation of 1.0. This can be overridden by "
886 "using the advanced parameters for mean and standard deviation "
887 "value. The raster data type is set to Float32 by default "
888 "as the normal distribution random values are floating point numbers." );
891QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
893 return new QgsRandomNormalRasterAlgorithm();
896void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
898 QStringList rasterDataTypes = QStringList();
899 rasterDataTypes << QStringLiteral(
"Float32" )
900 << QStringLiteral(
"Float64" );
902 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
904 addParameter( rasterTypeParameter.release() );
908 addParameter( meanParameter.release() );
910 auto stdevParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 1,
true, 0 );
912 addParameter( stdevParameter.release() );
915Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
928bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
930 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
931 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
932 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
936long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
938 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
941double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
943 return mRandomNormalDistribution( mersenneTwister );
949QString QgsRandomPoissonRasterAlgorithm::name()
const
951 return QStringLiteral(
"createrandompoissonrasterlayer" );
954QString QgsRandomPoissonRasterAlgorithm::displayName()
const
956 return QObject::tr(
"Create random raster layer (poisson distribution)" );
959QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
961 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
964QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
966 return QObject::tr(
"Generates a raster layer for given extent and cell size "
967 "filled with poisson distributed random values.\n"
968 "By default, the values will be chosen given a mean of 1.0. "
969 "This can be overridden by using the advanced parameter for mean "
970 "value. The raster data type is set to Integer types (Integer16 by default). "
971 "The poisson distribution random values are positive integer numbers. "
972 "A floating point raster will represent a cast of integer values to floating point." );
975QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
977 return new QgsRandomPoissonRasterAlgorithm();
981void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
983 QStringList rasterDataTypes = QStringList();
984 rasterDataTypes << QStringLiteral(
"Integer16" )
985 << QStringLiteral(
"Unsigned Integer16" )
986 << QStringLiteral(
"Integer32" )
987 << QStringLiteral(
"Unsigned Integer32" )
988 << QStringLiteral(
"Float32" )
989 << QStringLiteral(
"Float64" );
991 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
993 addParameter( rasterTypeParameter.release() );
997 addParameter( upperBoundParameter.release() );
1000Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1021bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1023 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1024 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1028long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1030 return mRandomPoissonDistribution( mersenneTwister );
1033double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1035 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)
@ 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)