29QString QgsRandomRasterAlgorithmBase::group()
const
31 return QObject::tr(
"Raster creation" );
34QString QgsRandomRasterAlgorithmBase::groupId()
const
36 return QStringLiteral(
"rastercreation" );
39void QgsRandomRasterAlgorithmBase::initAlgorithm(
const QVariantMap & )
42 addParameter(
new QgsProcessingParameterCrs( QStringLiteral(
"TARGET_CRS" ), QObject::tr(
"Target CRS" ), QStringLiteral(
"ProjectCrs" ) ) );
55 mCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
56 mExtent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context, mCrs );
57 mPixelSize = parameterAsDouble( parameters, QStringLiteral(
"PIXEL_SIZE" ), context );
64 const 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 const QFileInfo fi( outputFile );
76 const int rows = std::max( std::ceil( mExtent.height() / mPixelSize ), 1.0 );
77 const int cols = std::max( std::ceil( mExtent.width() / mPixelSize ), 1.0 );
81 const QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
83 std::unique_ptr< QgsRasterFileWriter > writer = std::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 const 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<qint8> int8Row( cols );
117 for (
int col = 0; col < cols; col++ )
119 int8Row[col] =
static_cast<qint8
>( generateRandomLongValue( mersenneTwister ) );
126 std::vector<qint16> int16Row( cols );
127 for (
int col = 0; col < cols; col++ )
129 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
136 std::vector<quint16> uInt16Row( cols );
137 for (
int col = 0; col < cols; col++ )
139 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
146 std::vector<qint32> int32Row( cols );
147 for (
int col = 0; col < cols; col++ )
149 int32Row[col] = generateRandomLongValue( mersenneTwister );
156 std::vector<quint32> uInt32Row( cols );
157 for (
int col = 0; col < cols; col++ )
159 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
166 std::vector<float> float32Row( cols );
167 for (
int col = 0; col < cols; col++ )
169 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
176 std::vector<double> float64Row( cols );
177 for (
int col = 0; col < cols; col++ )
179 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
187 provider->writeBlock( &block, 1, 0, row );
192 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
199QString QgsRandomUniformRasterAlgorithm::name()
const
201 return QStringLiteral(
"createrandomuniformrasterlayer" );
204QString QgsRandomUniformRasterAlgorithm::displayName()
const
206 return QObject::tr(
"Create random raster layer (uniform distribution)" );
209QStringList QgsRandomUniformRasterAlgorithm::tags()
const
211 return QObject::tr(
"raster,create,random" ).split(
',' );
214QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
216 return QObject::tr(
"Generates a raster layer for given extent and cell size "
217 "filled with random values.\n"
218 "By default, the values will range between the minimum and "
219 "maximum value of the specified output raster type. This can "
220 "be overridden by using the advanced parameters for lower and "
221 "upper bound value. If the bounds have the same value or both "
222 "are zero (default) the algorithm will create random values in "
223 "the full value range of the chosen raster data type. "
224 "Choosing bounds outside the acceptable range of the output "
225 "raster type will abort the algorithm." );
228QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
230 return new QgsRandomUniformRasterAlgorithm();
233void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
235 QStringList rasterDataTypes = QStringList();
236 rasterDataTypes << QStringLiteral(
"Byte" )
237 << QStringLiteral(
"Integer16" )
238 << QStringLiteral(
"Unsigned Integer16" )
239 << QStringLiteral(
"Integer32" )
240 << QStringLiteral(
"Unsigned Integer32" )
241 << QStringLiteral(
"Float32" )
242 << QStringLiteral(
"Float64" );
244 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
246 addParameter( rasterTypeParameter.release() );
248 std::unique_ptr< QgsProcessingParameterNumber > lowerBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
QgsProcessingParameterNumber::Double, QVariant(),
true );
250 addParameter( lowerBoundParameter.release() );
252 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
QgsProcessingParameterNumber::Double, QVariant(),
true );
254 addParameter( upperBoundParameter.release() );
257Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
280bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
282 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
283 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
285 if ( mRandomLowerBound > mRandomUpperBound )
286 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." ) );
288 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
289 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
291 switch ( rasterDataType )
294 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
295 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" ) ) );
299 mRandomUpperBound = std::numeric_limits<quint8>::max();
300 mRandomLowerBound = std::numeric_limits<quint8>::min();
304 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
305 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" ) ) );
309 mRandomUpperBound = std::numeric_limits<qint8>::max();
310 mRandomLowerBound = std::numeric_limits<qint8>::min();
314 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
315 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" ) ) );
318 mRandomUpperBound = std::numeric_limits<qint16>::max();
319 mRandomLowerBound = std::numeric_limits<qint16>::min();
323 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
324 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" ) ) );
327 mRandomUpperBound = std::numeric_limits<quint16>::max();
328 mRandomLowerBound = std::numeric_limits<quint16>::min();
332 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
333 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" ) ) );
336 mRandomUpperBound = std::numeric_limits<qint32>::max();
337 mRandomLowerBound = std::numeric_limits<qint32>::min();
341 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
342 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" ) ) );
345 mRandomUpperBound = std::numeric_limits<quint32>::max();
346 mRandomLowerBound = std::numeric_limits<quint32>::min();
352 mRandomUpperBound = std::numeric_limits<float>::max();
353 mRandomLowerBound = std::numeric_limits<float>::min();
359 mRandomUpperBound = std::numeric_limits<double>::max();
360 mRandomLowerBound = std::numeric_limits<double>::min();
373 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
374 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
379long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
381 return mRandomUniformIntDistribution( mersenneTwister );
384double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
386 return mRandomUniformDoubleDistribution( mersenneTwister );
392QString QgsRandomBinomialRasterAlgorithm::name()
const
394 return QStringLiteral(
"createrandombinomialrasterlayer" );
397QString QgsRandomBinomialRasterAlgorithm::displayName()
const
399 return QObject::tr(
"Create random raster layer (binomial distribution)" );
402QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
404 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
407QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
409 return QObject::tr(
"Generates a raster layer for given extent and cell size "
410 "filled with binomially distributed random values.\n"
411 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
412 "This can be overridden by using the advanced parameter for N and probability. "
413 "The raster data type is set to Integer types (Integer16 by default). "
414 "The binomial distribution random values are defined as positive integer numbers. "
415 "A floating point raster will represent a cast of integer values "
416 "to floating point." );
419QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
421 return new QgsRandomBinomialRasterAlgorithm();
425void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams( )
427 QStringList rasterDataTypes = QStringList();
428 rasterDataTypes << QStringLiteral(
"Integer16" )
429 << QStringLiteral(
"Unsigned Integer16" )
430 << QStringLiteral(
"Integer32" )
431 << QStringLiteral(
"Unsigned Integer32" )
432 << QStringLiteral(
"Float32" )
433 << QStringLiteral(
"Float64" );
435 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
437 addParameter( rasterTypeParameter.release() );
439 std::unique_ptr< QgsProcessingParameterNumber > nParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"N" ), QStringLiteral(
"N" ),
QgsProcessingParameterNumber::Integer, 10,
true, 0 );
441 addParameter( nParameter.release() );
443 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0 );
445 addParameter( probabilityParameter.release() );
448Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
469bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
471 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
472 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
473 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
477long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
479 return mRandombinomialDistribution( mersenneTwister );
482double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
484 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
490QString QgsRandomExponentialRasterAlgorithm::name()
const
492 return QStringLiteral(
"createrandomexponentialrasterlayer" );
495QString QgsRandomExponentialRasterAlgorithm::displayName()
const
497 return QObject::tr(
"Create random raster layer (exponential distribution)" );
500QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
502 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
505QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
507 return QObject::tr(
"Generates a raster layer for given extent and cell size "
508 "filled with exponentially distributed random values.\n"
509 "By default, the values will be chosen given a lambda of 1.0. "
510 "This can be overridden by using the advanced parameter for lambda. "
511 "The raster data type is set to Float32 by default as "
512 "the exponential distribution random values are floating point numbers." );
515QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
517 return new QgsRandomExponentialRasterAlgorithm();
521void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
523 QStringList rasterDataTypes = QStringList();
524 rasterDataTypes << QStringLiteral(
"Float32" )
525 << QStringLiteral(
"Float64" );
527 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
529 addParameter( rasterTypeParameter.release() );
531 std::unique_ptr< QgsProcessingParameterNumber > lambdaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"LAMBDA" ), QStringLiteral(
"Lambda" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
533 addParameter( lambdaParameter.release() );
536Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
549bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
551 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
552 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
556long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
558 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
561double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
563 return mRandomExponentialDistribution( mersenneTwister );
569QString QgsRandomGammaRasterAlgorithm::name()
const
571 return QStringLiteral(
"createrandomgammarasterlayer" );
574QString QgsRandomGammaRasterAlgorithm::displayName()
const
576 return QObject::tr(
"Create random raster layer (gamma distribution)" );
579QStringList QgsRandomGammaRasterAlgorithm::tags()
const
581 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
584QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
586 return QObject::tr(
"Generates a raster layer for given extent and cell size "
587 "filled with gamma distributed random values.\n"
588 "By default, the values will be chosen given an alpha and beta value of 1.0. "
589 "This can be overridden by using the advanced parameter for alpha and beta. "
590 "The raster data type is set to Float32 by default as "
591 "the gamma distribution random values are floating point numbers." );
594QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
596 return new QgsRandomGammaRasterAlgorithm();
600void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
602 QStringList rasterDataTypes = QStringList();
603 rasterDataTypes << QStringLiteral(
"Float32" )
604 << QStringLiteral(
"Float64" );
606 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
608 addParameter( rasterTypeParameter.release() );
610 std::unique_ptr< QgsProcessingParameterNumber > alphaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ALPHA" ), QStringLiteral(
"Alpha" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
612 addParameter( alphaParameter.release() );
614 std::unique_ptr< QgsProcessingParameterNumber > betaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"BETA" ), QStringLiteral(
"Beta" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0.000001 );
616 addParameter( betaParameter.release() );
619Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
632bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
634 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
635 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
636 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
640long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
642 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
645double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
647 return mRandomGammaDistribution( mersenneTwister );
653QString QgsRandomGeometricRasterAlgorithm::name()
const
655 return QStringLiteral(
"createrandomgeometricrasterlayer" );
658QString QgsRandomGeometricRasterAlgorithm::displayName()
const
660 return QObject::tr(
"Create random raster layer (geometric distribution)" );
663QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
665 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
668QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
670 return QObject::tr(
"Generates a raster layer for given extent and cell size "
671 "filled with geometrically distributed random values.\n"
672 "By default, the values will be chosen given a probability of 0.5. "
673 "This can be overridden by using the advanced parameter for mean "
674 "value. The raster data type is set to Integer types (Integer16 by default). "
675 "The geometric distribution random values are defined as positive integer numbers. "
676 "A floating point raster will represent a cast of "
677 "integer values to floating point." );
680QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
682 return new QgsRandomGeometricRasterAlgorithm();
686void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
688 QStringList rasterDataTypes = QStringList();
689 rasterDataTypes << QStringLiteral(
"Integer16" )
690 << QStringLiteral(
"Unsigned Integer16" )
691 << QStringLiteral(
"Integer32" )
692 << QStringLiteral(
"Unsigned Integer32" )
693 << QStringLiteral(
"Float32" )
694 << QStringLiteral(
"Float64" );
696 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
698 addParameter( rasterTypeParameter.release() );
700 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0.00001 );
702 addParameter( probabilityParameter.release() );
705Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
726bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
728 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
729 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
733long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
735 return mRandomGeometricDistribution( mersenneTwister );
738double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
740 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
746QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
748 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
751QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
753 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
756QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
758 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
761QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
763 return QObject::tr(
"Generates a raster layer for given extent and cell size "
764 "filled with negative binomially distributed random values.\n"
765 "By default, the values will be chosen given a distribution parameter k of 10.0 "
766 "and a probability of 0.5. "
767 "This can be overridden by using the advanced parameters for k and probability. "
768 "The raster data type is set to Integer types (Integer 16 by default). "
769 "The negative binomial distribution random values are defined as positive integer numbers. "
770 "A floating point raster will represent a cast of "
771 "integer values to floating point." );
774QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
776 return new QgsRandomNegativeBinomialRasterAlgorithm();
780void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams( )
782 QStringList rasterDataTypes = QStringList();
783 rasterDataTypes << QStringLiteral(
"Integer16" )
784 << QStringLiteral(
"Unsigned Integer16" )
785 << QStringLiteral(
"Integer32" )
786 << QStringLiteral(
"Unsigned Integer32" )
787 << QStringLiteral(
"Float32" )
788 << QStringLiteral(
"Float64" );
790 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
792 addParameter( rasterTypeParameter.release() );
794 std::unique_ptr< QgsProcessingParameterNumber > kParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"K_PARAMETER" ), QStringLiteral(
"Distribution parameter k" ),
QgsProcessingParameterNumber::Integer, 10,
true, 0.00001 );
796 addParameter( kParameter.release() );
798 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
QgsProcessingParameterNumber::Double, 0.5,
true, 0.00001 );
800 addParameter( probabilityParameter.release() );
803Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
824bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
826 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
827 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
828 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
832long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
834 return mRandomNegativeBinomialDistribution( mersenneTwister );
837double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
839 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
845QString QgsRandomNormalRasterAlgorithm::name()
const
847 return QStringLiteral(
"createrandomnormalrasterlayer" );
850QString QgsRandomNormalRasterAlgorithm::displayName()
const
852 return QObject::tr(
"Create random raster layer (normal distribution)" );
855QStringList QgsRandomNormalRasterAlgorithm::tags()
const
857 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
860QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
862 return QObject::tr(
"Generates a raster layer for given extent and cell size "
863 "filled with normally distributed random values.\n"
864 "By default, the values will be chosen given a mean of 0.0 and "
865 "a standard deviation of 1.0. This can be overridden by "
866 "using the advanced parameters for mean and standard deviation "
867 "value. The raster data type is set to Float32 by default "
868 "as the normal distribution random values are floating point numbers." );
871QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
873 return new QgsRandomNormalRasterAlgorithm();
876void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
878 QStringList rasterDataTypes = QStringList();
879 rasterDataTypes << QStringLiteral(
"Float32" )
880 << QStringLiteral(
"Float64" );
882 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
884 addParameter( rasterTypeParameter.release() );
886 std::unique_ptr< QgsProcessingParameterNumber > meanParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean of normal distribution" ),
QgsProcessingParameterNumber::Double, 0,
true );
888 addParameter( meanParameter.release() );
890 std::unique_ptr< QgsProcessingParameterNumber > stdevParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
QgsProcessingParameterNumber::Double, 1,
true, 0 );
892 addParameter( stdevParameter.release() );
895Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
908bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
910 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
911 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
912 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
916long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
918 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
921double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
923 return mRandomNormalDistribution( mersenneTwister );
929QString QgsRandomPoissonRasterAlgorithm::name()
const
931 return QStringLiteral(
"createrandompoissonrasterlayer" );
934QString QgsRandomPoissonRasterAlgorithm::displayName()
const
936 return QObject::tr(
"Create random raster layer (poisson distribution)" );
939QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
941 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
944QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
946 return QObject::tr(
"Generates a raster layer for given extent and cell size "
947 "filled with poisson distributed random values.\n"
948 "By default, the values will be chosen given a mean of 1.0. "
949 "This can be overridden by using the advanced parameter for mean "
950 "value. The raster data type is set to Integer types (Integer16 by default). "
951 "The poisson distribution random values are positive integer numbers. "
952 "A floating point raster will represent a cast of integer values to floating point." );
955QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
957 return new QgsRandomPoissonRasterAlgorithm();
961void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
963 QStringList rasterDataTypes = QStringList();
964 rasterDataTypes << QStringLiteral(
"Integer16" )
965 << QStringLiteral(
"Unsigned Integer16" )
966 << QStringLiteral(
"Integer32" )
967 << QStringLiteral(
"Unsigned Integer32" )
968 << QStringLiteral(
"Float32" )
969 << QStringLiteral(
"Float64" );
971 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
973 addParameter( rasterTypeParameter.release() );
975 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean" ),
QgsProcessingParameterNumber::Double, 1.0,
true, 0 );
977 addParameter( upperBoundParameter.release() );
980Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1001bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1003 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1004 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1008long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1010 return mRandomPoissonDistribution( mersenneTwister );
1013double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1015 return static_cast<double>( mRandomPoissonDistribution( mersenneTwister ) );
DataType
Raster data types.
@ Float32
Thirty two bit floating point (float)
@ CFloat64
Complex Float64.
@ Int16
Sixteen bit signed integer (qint16)
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
@ Int8
Eight bit signed integer (qint8) (added in QGIS 3.30)
@ UInt16
Sixteen bit unsigned integer (quint16)
@ Byte
Eight bit unsigned integer (quint8)
@ UnknownDataType
Unknown or unspecified type.
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
@ Int32
Thirty two bit signed integer (qint32)
@ Float64
Sixty four bit floating point (double)
@ CFloat32
Complex Float32.
@ UInt32
Thirty two bit unsigned integer (quint32)
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A coordinate reference system parameter for processing algorithms.
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
A rectangular map extent parameter for processing algorithms.
A numeric parameter for processing algorithms.
@ Double
Double/float values.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
static int typeSize(Qgis::DataType dataType) SIP_HOLDGIL
Returns the size in bytes for the specified dataType.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
A rectangle specified with double values.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)