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 provider->writeBlock( &block, 1, 0, row );
209 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
216QString QgsRandomUniformRasterAlgorithm::name()
const
218 return QStringLiteral(
"createrandomuniformrasterlayer" );
221QString QgsRandomUniformRasterAlgorithm::displayName()
const
223 return QObject::tr(
"Create random raster layer (uniform distribution)" );
226QStringList QgsRandomUniformRasterAlgorithm::tags()
const
228 return QObject::tr(
"raster,create,random" ).split(
',' );
231QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
233 return QObject::tr(
"Generates a raster layer for given extent and cell size "
234 "filled with random values.\n"
235 "By default, the values will range between the minimum and "
236 "maximum value of the specified output raster type. This can "
237 "be overridden by using the advanced parameters for lower and "
238 "upper bound value. If the bounds have the same value or both "
239 "are zero (default) the algorithm will create random values in "
240 "the full value range of the chosen raster data type. "
241 "Choosing bounds outside the acceptable range of the output "
242 "raster type will abort the algorithm." );
245QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
247 return new QgsRandomUniformRasterAlgorithm();
250void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
252 QStringList rasterDataTypes = QStringList();
253 rasterDataTypes << QStringLiteral(
"Byte" )
254 << QStringLiteral(
"Integer16" )
255 << QStringLiteral(
"Unsigned Integer16" )
256 << QStringLiteral(
"Integer32" )
257 << QStringLiteral(
"Unsigned Integer32" )
258 << QStringLiteral(
"Float32" )
259 << QStringLiteral(
"Float64" );
261 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
263 addParameter( rasterTypeParameter.release() );
265 auto lowerBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
267 addParameter( lowerBoundParameter.release() );
269 auto upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
271 addParameter( upperBoundParameter.release() );
274Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
297bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
299 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
300 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
302 if ( mRandomLowerBound > mRandomUpperBound )
303 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." ) );
305 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
306 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
308 switch ( rasterDataType )
311 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
312 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" ) ) );
316 mRandomUpperBound = std::numeric_limits<quint8>::max();
317 mRandomLowerBound = std::numeric_limits<quint8>::min();
321 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
322 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" ) ) );
326 mRandomUpperBound = std::numeric_limits<qint8>::max();
327 mRandomLowerBound = std::numeric_limits<qint8>::min();
331 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
332 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" ) ) );
335 mRandomUpperBound = std::numeric_limits<qint16>::max();
336 mRandomLowerBound = std::numeric_limits<qint16>::min();
340 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
341 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" ) ) );
344 mRandomUpperBound = std::numeric_limits<quint16>::max();
345 mRandomLowerBound = std::numeric_limits<quint16>::min();
349 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
350 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" ) ) );
353 mRandomUpperBound = std::numeric_limits<qint32>::max();
354 mRandomLowerBound = std::numeric_limits<qint32>::min();
358 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
359 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" ) ) );
362 mRandomUpperBound = std::numeric_limits<quint32>::max();
363 mRandomLowerBound = std::numeric_limits<quint32>::min();
369 mRandomUpperBound = std::numeric_limits<float>::max();
370 mRandomLowerBound = std::numeric_limits<float>::min();
376 mRandomUpperBound = std::numeric_limits<double>::max();
377 mRandomLowerBound = std::numeric_limits<double>::min();
390 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
391 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
396long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
398 return mRandomUniformIntDistribution( mersenneTwister );
401double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
403 return mRandomUniformDoubleDistribution( mersenneTwister );
409QString QgsRandomBinomialRasterAlgorithm::name()
const
411 return QStringLiteral(
"createrandombinomialrasterlayer" );
414QString QgsRandomBinomialRasterAlgorithm::displayName()
const
416 return QObject::tr(
"Create random raster layer (binomial distribution)" );
419QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
421 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
424QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
426 return QObject::tr(
"Generates a raster layer for given extent and cell size "
427 "filled with binomially distributed random values.\n"
428 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
429 "This can be overridden by using the advanced parameter for N and probability. "
430 "The raster data type is set to Integer types (Integer16 by default). "
431 "The binomial distribution random values are defined as positive integer numbers. "
432 "A floating point raster will represent a cast of integer values "
433 "to floating point." );
436QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
438 return new QgsRandomBinomialRasterAlgorithm();
442void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams()
444 QStringList rasterDataTypes = QStringList();
445 rasterDataTypes << QStringLiteral(
"Integer16" )
446 << QStringLiteral(
"Unsigned Integer16" )
447 << QStringLiteral(
"Integer32" )
448 << QStringLiteral(
"Unsigned Integer32" )
449 << QStringLiteral(
"Float32" )
450 << QStringLiteral(
"Float64" );
452 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
454 addParameter( rasterTypeParameter.release() );
458 addParameter( nParameter.release() );
462 addParameter( probabilityParameter.release() );
465Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
486bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
488 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
489 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
490 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
494long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
496 return mRandombinomialDistribution( mersenneTwister );
499double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
501 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
507QString QgsRandomExponentialRasterAlgorithm::name()
const
509 return QStringLiteral(
"createrandomexponentialrasterlayer" );
512QString QgsRandomExponentialRasterAlgorithm::displayName()
const
514 return QObject::tr(
"Create random raster layer (exponential distribution)" );
517QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
519 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
522QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
524 return QObject::tr(
"Generates a raster layer for given extent and cell size "
525 "filled with exponentially distributed random values.\n"
526 "By default, the values will be chosen given a lambda of 1.0. "
527 "This can be overridden by using the advanced parameter for lambda. "
528 "The raster data type is set to Float32 by default as "
529 "the exponential distribution random values are floating point numbers." );
532QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
534 return new QgsRandomExponentialRasterAlgorithm();
538void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
540 QStringList rasterDataTypes = QStringList();
541 rasterDataTypes << QStringLiteral(
"Float32" )
542 << QStringLiteral(
"Float64" );
544 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
546 addParameter( rasterTypeParameter.release() );
550 addParameter( lambdaParameter.release() );
553Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
566bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
568 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
569 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
573long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
575 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
578double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
580 return mRandomExponentialDistribution( mersenneTwister );
586QString QgsRandomGammaRasterAlgorithm::name()
const
588 return QStringLiteral(
"createrandomgammarasterlayer" );
591QString QgsRandomGammaRasterAlgorithm::displayName()
const
593 return QObject::tr(
"Create random raster layer (gamma distribution)" );
596QStringList QgsRandomGammaRasterAlgorithm::tags()
const
598 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
601QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
603 return QObject::tr(
"Generates a raster layer for given extent and cell size "
604 "filled with gamma distributed random values.\n"
605 "By default, the values will be chosen given an alpha and beta value of 1.0. "
606 "This can be overridden by using the advanced parameter for alpha and beta. "
607 "The raster data type is set to Float32 by default as "
608 "the gamma distribution random values are floating point numbers." );
611QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
613 return new QgsRandomGammaRasterAlgorithm();
617void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
619 QStringList rasterDataTypes = QStringList();
620 rasterDataTypes << QStringLiteral(
"Float32" )
621 << QStringLiteral(
"Float64" );
623 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
625 addParameter( rasterTypeParameter.release() );
629 addParameter( alphaParameter.release() );
633 addParameter( betaParameter.release() );
636Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
649bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
651 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
652 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
653 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
657long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
659 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
662double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
664 return mRandomGammaDistribution( mersenneTwister );
670QString QgsRandomGeometricRasterAlgorithm::name()
const
672 return QStringLiteral(
"createrandomgeometricrasterlayer" );
675QString QgsRandomGeometricRasterAlgorithm::displayName()
const
677 return QObject::tr(
"Create random raster layer (geometric distribution)" );
680QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
682 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
685QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
687 return QObject::tr(
"Generates a raster layer for given extent and cell size "
688 "filled with geometrically distributed random values.\n"
689 "By default, the values will be chosen given a probability of 0.5. "
690 "This can be overridden by using the advanced parameter for mean "
691 "value. The raster data type is set to Integer types (Integer16 by default). "
692 "The geometric distribution random values are defined as positive integer numbers. "
693 "A floating point raster will represent a cast of "
694 "integer values to floating point." );
697QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
699 return new QgsRandomGeometricRasterAlgorithm();
703void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
705 QStringList rasterDataTypes = QStringList();
706 rasterDataTypes << QStringLiteral(
"Integer16" )
707 << QStringLiteral(
"Unsigned Integer16" )
708 << QStringLiteral(
"Integer32" )
709 << QStringLiteral(
"Unsigned Integer32" )
710 << QStringLiteral(
"Float32" )
711 << QStringLiteral(
"Float64" );
713 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
715 addParameter( rasterTypeParameter.release() );
719 addParameter( probabilityParameter.release() );
722Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
743bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
745 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
746 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
750long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
752 return mRandomGeometricDistribution( mersenneTwister );
755double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
757 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
763QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
765 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
768QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
770 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
773QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
775 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
778QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
780 return QObject::tr(
"Generates a raster layer for given extent and cell size "
781 "filled with negative binomially distributed random values.\n"
782 "By default, the values will be chosen given a distribution parameter k of 10.0 "
783 "and a probability of 0.5. "
784 "This can be overridden by using the advanced parameters for k and probability. "
785 "The raster data type is set to Integer types (Integer 16 by default). "
786 "The negative binomial distribution random values are defined as positive integer numbers. "
787 "A floating point raster will represent a cast of "
788 "integer values to floating point." );
791QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
793 return new QgsRandomNegativeBinomialRasterAlgorithm();
797void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams()
799 QStringList rasterDataTypes = QStringList();
800 rasterDataTypes << QStringLiteral(
"Integer16" )
801 << QStringLiteral(
"Unsigned Integer16" )
802 << QStringLiteral(
"Integer32" )
803 << QStringLiteral(
"Unsigned Integer32" )
804 << QStringLiteral(
"Float32" )
805 << QStringLiteral(
"Float64" );
807 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
809 addParameter( rasterTypeParameter.release() );
813 addParameter( kParameter.release() );
817 addParameter( probabilityParameter.release() );
820Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
841bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
843 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
844 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
845 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
849long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
851 return mRandomNegativeBinomialDistribution( mersenneTwister );
854double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
856 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
862QString QgsRandomNormalRasterAlgorithm::name()
const
864 return QStringLiteral(
"createrandomnormalrasterlayer" );
867QString QgsRandomNormalRasterAlgorithm::displayName()
const
869 return QObject::tr(
"Create random raster layer (normal distribution)" );
872QStringList QgsRandomNormalRasterAlgorithm::tags()
const
874 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
877QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
879 return QObject::tr(
"Generates a raster layer for given extent and cell size "
880 "filled with normally distributed random values.\n"
881 "By default, the values will be chosen given a mean of 0.0 and "
882 "a standard deviation of 1.0. This can be overridden by "
883 "using the advanced parameters for mean and standard deviation "
884 "value. The raster data type is set to Float32 by default "
885 "as the normal distribution random values are floating point numbers." );
888QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
890 return new QgsRandomNormalRasterAlgorithm();
893void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
895 QStringList rasterDataTypes = QStringList();
896 rasterDataTypes << QStringLiteral(
"Float32" )
897 << QStringLiteral(
"Float64" );
899 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
901 addParameter( rasterTypeParameter.release() );
905 addParameter( meanParameter.release() );
907 auto stdevParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 1,
true, 0 );
909 addParameter( stdevParameter.release() );
912Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
925bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
927 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
928 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
929 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
933long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
935 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
938double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
940 return mRandomNormalDistribution( mersenneTwister );
946QString QgsRandomPoissonRasterAlgorithm::name()
const
948 return QStringLiteral(
"createrandompoissonrasterlayer" );
951QString QgsRandomPoissonRasterAlgorithm::displayName()
const
953 return QObject::tr(
"Create random raster layer (poisson distribution)" );
956QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
958 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
961QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
963 return QObject::tr(
"Generates a raster layer for given extent and cell size "
964 "filled with poisson distributed random values.\n"
965 "By default, the values will be chosen given a mean of 1.0. "
966 "This can be overridden by using the advanced parameter for mean "
967 "value. The raster data type is set to Integer types (Integer16 by default). "
968 "The poisson distribution random values are positive integer numbers. "
969 "A floating point raster will represent a cast of integer values to floating point." );
972QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
974 return new QgsRandomPoissonRasterAlgorithm();
978void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
980 QStringList rasterDataTypes = QStringList();
981 rasterDataTypes << QStringLiteral(
"Integer16" )
982 << QStringLiteral(
"Unsigned Integer16" )
983 << QStringLiteral(
"Integer32" )
984 << QStringLiteral(
"Unsigned Integer32" )
985 << QStringLiteral(
"Float32" )
986 << QStringLiteral(
"Float64" );
988 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
990 addParameter( rasterTypeParameter.release() );
994 addParameter( upperBoundParameter.release() );
997Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1018bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1020 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1021 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1025long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1027 return mRandomPoissonDistribution( mersenneTwister );
1030double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1032 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)