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 std::unique_ptr<QgsProcessingParameterString> 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 );
86 const int rows = std::max( std::ceil( mExtent.height() / mPixelSize ), 1.0 );
87 const int cols = std::max( std::ceil( mExtent.width() / mPixelSize ), 1.0 );
91 const QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
93 std::unique_ptr<QgsRasterFileWriter> writer = std::make_unique<QgsRasterFileWriter>( outputFile );
94 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
95 if ( !createOptions.isEmpty() )
97 writer->setCreateOptions( createOptions.split(
'|' ) );
100 writer->setOutputFormat( outputFormat );
101 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
104 if ( !provider->isValid() )
107 const double step = rows > 0 ? 100.0 / rows : 1;
109 for (
int row = 0; row < rows; row++ )
117 switch ( mRasterDataType )
121 std::vector<quint8> byteRow( cols );
122 for (
int col = 0; col < cols; col++ )
124 byteRow[col] =
static_cast<quint8
>( generateRandomLongValue( mersenneTwister ) );
131 std::vector<qint8> int8Row( cols );
132 for (
int col = 0; col < cols; col++ )
134 int8Row[col] =
static_cast<qint8
>( generateRandomLongValue( mersenneTwister ) );
141 std::vector<qint16> int16Row( cols );
142 for (
int col = 0; col < cols; col++ )
144 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
151 std::vector<quint16> uInt16Row( cols );
152 for (
int col = 0; col < cols; col++ )
154 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
161 std::vector<qint32> int32Row( cols );
162 for (
int col = 0; col < cols; col++ )
164 int32Row[col] = generateRandomLongValue( mersenneTwister );
171 std::vector<quint32> uInt32Row( cols );
172 for (
int col = 0; col < cols; col++ )
174 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
181 std::vector<float> float32Row( cols );
182 for (
int col = 0; col < cols; col++ )
184 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
191 std::vector<double> float64Row( cols );
192 for (
int col = 0; col < cols; col++ )
194 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
202 provider->writeBlock( &block, 1, 0, row );
207 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
214QString QgsRandomUniformRasterAlgorithm::name()
const
216 return QStringLiteral(
"createrandomuniformrasterlayer" );
219QString QgsRandomUniformRasterAlgorithm::displayName()
const
221 return QObject::tr(
"Create random raster layer (uniform distribution)" );
224QStringList QgsRandomUniformRasterAlgorithm::tags()
const
226 return QObject::tr(
"raster,create,random" ).split(
',' );
229QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
231 return QObject::tr(
"Generates a raster layer for given extent and cell size "
232 "filled with random values.\n"
233 "By default, the values will range between the minimum and "
234 "maximum value of the specified output raster type. This can "
235 "be overridden by using the advanced parameters for lower and "
236 "upper bound value. If the bounds have the same value or both "
237 "are zero (default) the algorithm will create random values in "
238 "the full value range of the chosen raster data type. "
239 "Choosing bounds outside the acceptable range of the output "
240 "raster type will abort the algorithm." );
243QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
245 return new QgsRandomUniformRasterAlgorithm();
248void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
250 QStringList rasterDataTypes = QStringList();
251 rasterDataTypes << QStringLiteral(
"Byte" )
252 << QStringLiteral(
"Integer16" )
253 << QStringLiteral(
"Unsigned Integer16" )
254 << QStringLiteral(
"Integer32" )
255 << QStringLiteral(
"Unsigned Integer32" )
256 << QStringLiteral(
"Float32" )
257 << QStringLiteral(
"Float64" );
259 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
261 addParameter( rasterTypeParameter.release() );
263 std::unique_ptr<QgsProcessingParameterNumber> lowerBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
265 addParameter( lowerBoundParameter.release() );
267 std::unique_ptr<QgsProcessingParameterNumber> upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
269 addParameter( upperBoundParameter.release() );
272Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
295bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
297 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
298 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
300 if ( mRandomLowerBound > mRandomUpperBound )
301 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." ) );
303 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
304 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
306 switch ( rasterDataType )
309 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
310 throw QgsProcessingException( QObject::tr(
"Raster datasets of type %3 only accept positive values between %1 and %2. Please choose other bounds for random values." ).arg( std::numeric_limits<quint8>::min() ).arg( std::numeric_limits<quint8>::max() ).arg( QLatin1String(
"Byte" ) ) );
314 mRandomUpperBound = std::numeric_limits<quint8>::max();
315 mRandomLowerBound = std::numeric_limits<quint8>::min();
319 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
320 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" ) ) );
324 mRandomUpperBound = std::numeric_limits<qint8>::max();
325 mRandomLowerBound = std::numeric_limits<qint8>::min();
329 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
330 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" ) ) );
333 mRandomUpperBound = std::numeric_limits<qint16>::max();
334 mRandomLowerBound = std::numeric_limits<qint16>::min();
338 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
339 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" ) ) );
342 mRandomUpperBound = std::numeric_limits<quint16>::max();
343 mRandomLowerBound = std::numeric_limits<quint16>::min();
347 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
348 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" ) ) );
351 mRandomUpperBound = std::numeric_limits<qint32>::max();
352 mRandomLowerBound = std::numeric_limits<qint32>::min();
356 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
357 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" ) ) );
360 mRandomUpperBound = std::numeric_limits<quint32>::max();
361 mRandomLowerBound = std::numeric_limits<quint32>::min();
367 mRandomUpperBound = std::numeric_limits<float>::max();
368 mRandomLowerBound = std::numeric_limits<float>::min();
374 mRandomUpperBound = std::numeric_limits<double>::max();
375 mRandomLowerBound = std::numeric_limits<double>::min();
388 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
389 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
394long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
396 return mRandomUniformIntDistribution( mersenneTwister );
399double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
401 return mRandomUniformDoubleDistribution( mersenneTwister );
407QString QgsRandomBinomialRasterAlgorithm::name()
const
409 return QStringLiteral(
"createrandombinomialrasterlayer" );
412QString QgsRandomBinomialRasterAlgorithm::displayName()
const
414 return QObject::tr(
"Create random raster layer (binomial distribution)" );
417QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
419 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
422QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
424 return QObject::tr(
"Generates a raster layer for given extent and cell size "
425 "filled with binomially distributed random values.\n"
426 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
427 "This can be overridden by using the advanced parameter for N and probability. "
428 "The raster data type is set to Integer types (Integer16 by default). "
429 "The binomial distribution random values are defined as positive integer numbers. "
430 "A floating point raster will represent a cast of integer values "
431 "to floating point." );
434QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
436 return new QgsRandomBinomialRasterAlgorithm();
440void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams()
442 QStringList rasterDataTypes = QStringList();
443 rasterDataTypes << QStringLiteral(
"Integer16" )
444 << QStringLiteral(
"Unsigned Integer16" )
445 << QStringLiteral(
"Integer32" )
446 << QStringLiteral(
"Unsigned Integer32" )
447 << QStringLiteral(
"Float32" )
448 << QStringLiteral(
"Float64" );
450 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
452 addParameter( rasterTypeParameter.release() );
456 addParameter( nParameter.release() );
458 std::unique_ptr<QgsProcessingParameterNumber> probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
Qgis::ProcessingNumberParameterType::Double, 0.5,
true, 0 );
460 addParameter( probabilityParameter.release() );
463Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
484bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
486 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
487 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
488 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
492long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
494 return mRandombinomialDistribution( mersenneTwister );
497double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
499 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
505QString QgsRandomExponentialRasterAlgorithm::name()
const
507 return QStringLiteral(
"createrandomexponentialrasterlayer" );
510QString QgsRandomExponentialRasterAlgorithm::displayName()
const
512 return QObject::tr(
"Create random raster layer (exponential distribution)" );
515QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
517 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
520QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
522 return QObject::tr(
"Generates a raster layer for given extent and cell size "
523 "filled with exponentially distributed random values.\n"
524 "By default, the values will be chosen given a lambda of 1.0. "
525 "This can be overridden by using the advanced parameter for lambda. "
526 "The raster data type is set to Float32 by default as "
527 "the exponential distribution random values are floating point numbers." );
530QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
532 return new QgsRandomExponentialRasterAlgorithm();
536void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
538 QStringList rasterDataTypes = QStringList();
539 rasterDataTypes << QStringLiteral(
"Float32" )
540 << QStringLiteral(
"Float64" );
542 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
544 addParameter( rasterTypeParameter.release() );
546 std::unique_ptr<QgsProcessingParameterNumber> lambdaParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"LAMBDA" ), QStringLiteral(
"Lambda" ),
Qgis::ProcessingNumberParameterType::Double, 1.0,
true, 0.000001 );
548 addParameter( lambdaParameter.release() );
551Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
564bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
566 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
567 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
571long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
573 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
576double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
578 return mRandomExponentialDistribution( mersenneTwister );
584QString QgsRandomGammaRasterAlgorithm::name()
const
586 return QStringLiteral(
"createrandomgammarasterlayer" );
589QString QgsRandomGammaRasterAlgorithm::displayName()
const
591 return QObject::tr(
"Create random raster layer (gamma distribution)" );
594QStringList QgsRandomGammaRasterAlgorithm::tags()
const
596 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
599QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
601 return QObject::tr(
"Generates a raster layer for given extent and cell size "
602 "filled with gamma distributed random values.\n"
603 "By default, the values will be chosen given an alpha and beta value of 1.0. "
604 "This can be overridden by using the advanced parameter for alpha and beta. "
605 "The raster data type is set to Float32 by default as "
606 "the gamma distribution random values are floating point numbers." );
609QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
611 return new QgsRandomGammaRasterAlgorithm();
615void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
617 QStringList rasterDataTypes = QStringList();
618 rasterDataTypes << QStringLiteral(
"Float32" )
619 << QStringLiteral(
"Float64" );
621 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
623 addParameter( rasterTypeParameter.release() );
625 std::unique_ptr<QgsProcessingParameterNumber> alphaParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"ALPHA" ), QStringLiteral(
"Alpha" ),
Qgis::ProcessingNumberParameterType::Double, 1.0,
true, 0.000001 );
627 addParameter( alphaParameter.release() );
629 std::unique_ptr<QgsProcessingParameterNumber> betaParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"BETA" ), QStringLiteral(
"Beta" ),
Qgis::ProcessingNumberParameterType::Double, 1.0,
true, 0.000001 );
631 addParameter( betaParameter.release() );
634Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
647bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
649 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
650 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
651 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
655long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
657 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
660double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
662 return mRandomGammaDistribution( mersenneTwister );
668QString QgsRandomGeometricRasterAlgorithm::name()
const
670 return QStringLiteral(
"createrandomgeometricrasterlayer" );
673QString QgsRandomGeometricRasterAlgorithm::displayName()
const
675 return QObject::tr(
"Create random raster layer (geometric distribution)" );
678QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
680 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
683QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
685 return QObject::tr(
"Generates a raster layer for given extent and cell size "
686 "filled with geometrically distributed random values.\n"
687 "By default, the values will be chosen given a probability of 0.5. "
688 "This can be overridden by using the advanced parameter for mean "
689 "value. The raster data type is set to Integer types (Integer16 by default). "
690 "The geometric distribution random values are defined as positive integer numbers. "
691 "A floating point raster will represent a cast of "
692 "integer values to floating point." );
695QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
697 return new QgsRandomGeometricRasterAlgorithm();
701void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
703 QStringList rasterDataTypes = QStringList();
704 rasterDataTypes << QStringLiteral(
"Integer16" )
705 << QStringLiteral(
"Unsigned Integer16" )
706 << QStringLiteral(
"Integer32" )
707 << QStringLiteral(
"Unsigned Integer32" )
708 << QStringLiteral(
"Float32" )
709 << QStringLiteral(
"Float64" );
711 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
713 addParameter( rasterTypeParameter.release() );
715 std::unique_ptr<QgsProcessingParameterNumber> probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
Qgis::ProcessingNumberParameterType::Double, 0.5,
true, 0.00001 );
717 addParameter( probabilityParameter.release() );
720Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
741bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
743 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
744 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
748long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
750 return mRandomGeometricDistribution( mersenneTwister );
753double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
755 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
761QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
763 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
766QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
768 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
771QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
773 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
776QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
778 return QObject::tr(
"Generates a raster layer for given extent and cell size "
779 "filled with negative binomially distributed random values.\n"
780 "By default, the values will be chosen given a distribution parameter k of 10.0 "
781 "and a probability of 0.5. "
782 "This can be overridden by using the advanced parameters for k and probability. "
783 "The raster data type is set to Integer types (Integer 16 by default). "
784 "The negative binomial distribution random values are defined as positive integer numbers. "
785 "A floating point raster will represent a cast of "
786 "integer values to floating point." );
789QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
791 return new QgsRandomNegativeBinomialRasterAlgorithm();
795void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams()
797 QStringList rasterDataTypes = QStringList();
798 rasterDataTypes << QStringLiteral(
"Integer16" )
799 << QStringLiteral(
"Unsigned Integer16" )
800 << QStringLiteral(
"Integer32" )
801 << QStringLiteral(
"Unsigned Integer32" )
802 << QStringLiteral(
"Float32" )
803 << QStringLiteral(
"Float64" );
805 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
807 addParameter( rasterTypeParameter.release() );
809 std::unique_ptr<QgsProcessingParameterNumber> kParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"K_PARAMETER" ), QStringLiteral(
"Distribution parameter k" ),
Qgis::ProcessingNumberParameterType::Integer, 10,
true, 0.00001 );
811 addParameter( kParameter.release() );
813 std::unique_ptr<QgsProcessingParameterNumber> probabilityParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
Qgis::ProcessingNumberParameterType::Double, 0.5,
true, 0.00001 );
815 addParameter( probabilityParameter.release() );
818Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
839bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
841 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
842 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
843 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
847long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
849 return mRandomNegativeBinomialDistribution( mersenneTwister );
852double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
854 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
860QString QgsRandomNormalRasterAlgorithm::name()
const
862 return QStringLiteral(
"createrandomnormalrasterlayer" );
865QString QgsRandomNormalRasterAlgorithm::displayName()
const
867 return QObject::tr(
"Create random raster layer (normal distribution)" );
870QStringList QgsRandomNormalRasterAlgorithm::tags()
const
872 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
875QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
877 return QObject::tr(
"Generates a raster layer for given extent and cell size "
878 "filled with normally distributed random values.\n"
879 "By default, the values will be chosen given a mean of 0.0 and "
880 "a standard deviation of 1.0. This can be overridden by "
881 "using the advanced parameters for mean and standard deviation "
882 "value. The raster data type is set to Float32 by default "
883 "as the normal distribution random values are floating point numbers." );
886QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
888 return new QgsRandomNormalRasterAlgorithm();
891void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
893 QStringList rasterDataTypes = QStringList();
894 rasterDataTypes << QStringLiteral(
"Float32" )
895 << QStringLiteral(
"Float64" );
897 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
899 addParameter( rasterTypeParameter.release() );
901 std::unique_ptr<QgsProcessingParameterNumber> meanParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 0,
true );
903 addParameter( meanParameter.release() );
905 std::unique_ptr<QgsProcessingParameterNumber> stdevParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 1,
true, 0 );
907 addParameter( stdevParameter.release() );
910Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
923bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
925 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
926 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
927 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
931long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
933 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
936double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
938 return mRandomNormalDistribution( mersenneTwister );
944QString QgsRandomPoissonRasterAlgorithm::name()
const
946 return QStringLiteral(
"createrandompoissonrasterlayer" );
949QString QgsRandomPoissonRasterAlgorithm::displayName()
const
951 return QObject::tr(
"Create random raster layer (poisson distribution)" );
954QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
956 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
959QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
961 return QObject::tr(
"Generates a raster layer for given extent and cell size "
962 "filled with poisson distributed random values.\n"
963 "By default, the values will be chosen given a mean of 1.0. "
964 "This can be overridden by using the advanced parameter for mean "
965 "value. The raster data type is set to Integer types (Integer16 by default). "
966 "The poisson distribution random values are positive integer numbers. "
967 "A floating point raster will represent a cast of integer values to floating point." );
970QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
972 return new QgsRandomPoissonRasterAlgorithm();
976void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
978 QStringList rasterDataTypes = QStringList();
979 rasterDataTypes << QStringLiteral(
"Integer16" )
980 << QStringLiteral(
"Unsigned Integer16" )
981 << QStringLiteral(
"Integer32" )
982 << QStringLiteral(
"Unsigned Integer32" )
983 << QStringLiteral(
"Float32" )
984 << QStringLiteral(
"Float64" );
986 std::unique_ptr<QgsProcessingParameterDefinition> rasterTypeParameter = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
988 addParameter( rasterTypeParameter.release() );
990 std::unique_ptr<QgsProcessingParameterNumber> upperBoundParameter = std::make_unique<QgsProcessingParameterNumber>( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean" ),
Qgis::ProcessingNumberParameterType::Double, 1.0,
true, 0 );
992 addParameter( upperBoundParameter.release() );
995Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1016bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1018 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1019 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1023long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1025 return mRandomPoissonDistribution( mersenneTwister );
1028double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1030 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)