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" ) ) );
49 std::unique_ptr< QgsProcessingParameterString > createOptsParam = std::make_unique< QgsProcessingParameterString >( QStringLiteral(
"CREATE_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
50 createOptsParam->setMetadata( QVariantMap( {{QStringLiteral(
"widget_wrapper" ), QVariantMap( {{QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) }} ) }} ) );
52 addParameter( createOptsParam.release() );
60 mCrs = parameterAsCrs( parameters, QStringLiteral(
"TARGET_CRS" ), context );
61 mExtent = parameterAsExtent( parameters, QStringLiteral(
"EXTENT" ), context, mCrs );
62 mPixelSize = parameterAsDouble( parameters, QStringLiteral(
"PIXEL_SIZE" ), context );
64 if ( mPixelSize <= 0 )
74 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
76 mRasterDataType = getRasterDataType( typeId );
77 prepareRandomParameters( parameters, context );
79 std::random_device rd {};
80 std::mt19937 mersenneTwister{rd()};
82 const QString createOptions = parameterAsString( parameters, QStringLiteral(
"CREATE_OPTIONS" ), context ).trimmed();
83 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
84 const QFileInfo fi( outputFile );
87 const int rows = std::max( std::ceil( mExtent.height() / mPixelSize ), 1.0 );
88 const int cols = std::max( std::ceil( mExtent.width() / mPixelSize ), 1.0 );
92 const QgsRectangle rasterExtent =
QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
94 std::unique_ptr< QgsRasterFileWriter > writer = std::make_unique< QgsRasterFileWriter >( outputFile );
95 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
96 if ( !createOptions.isEmpty() )
98 writer->setCreateOptions( createOptions.split(
'|' ) );
101 writer->setOutputFormat( outputFormat );
102 std::unique_ptr<QgsRasterDataProvider > provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
105 if ( !provider->isValid() )
108 const double step = rows > 0 ? 100.0 / rows : 1;
110 for (
int row = 0; row < rows ; row++ )
118 switch ( mRasterDataType )
122 std::vector<quint8> byteRow( cols );
123 for (
int col = 0; col < cols; col++ )
125 byteRow[col] =
static_cast<quint8
>( generateRandomLongValue( mersenneTwister ) );
132 std::vector<qint8> int8Row( cols );
133 for (
int col = 0; col < cols; col++ )
135 int8Row[col] =
static_cast<qint8
>( generateRandomLongValue( mersenneTwister ) );
142 std::vector<qint16> int16Row( cols );
143 for (
int col = 0; col < cols; col++ )
145 int16Row[col] =
static_cast<qint16
>( generateRandomLongValue( mersenneTwister ) );
152 std::vector<quint16> uInt16Row( cols );
153 for (
int col = 0; col < cols; col++ )
155 uInt16Row[col] =
static_cast<quint16
>( generateRandomLongValue( mersenneTwister ) );
162 std::vector<qint32> int32Row( cols );
163 for (
int col = 0; col < cols; col++ )
165 int32Row[col] = generateRandomLongValue( mersenneTwister );
172 std::vector<quint32> uInt32Row( cols );
173 for (
int col = 0; col < cols; col++ )
175 uInt32Row[col] =
static_cast<quint32
>( generateRandomLongValue( mersenneTwister ) );
182 std::vector<float> float32Row( cols );
183 for (
int col = 0; col < cols; col++ )
185 float32Row[col] =
static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
192 std::vector<double> float64Row( cols );
193 for (
int col = 0; col < cols; col++ )
195 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
203 provider->writeBlock( &block, 1, 0, row );
208 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
215QString QgsRandomUniformRasterAlgorithm::name()
const
217 return QStringLiteral(
"createrandomuniformrasterlayer" );
220QString QgsRandomUniformRasterAlgorithm::displayName()
const
222 return QObject::tr(
"Create random raster layer (uniform distribution)" );
225QStringList QgsRandomUniformRasterAlgorithm::tags()
const
227 return QObject::tr(
"raster,create,random" ).split(
',' );
230QString QgsRandomUniformRasterAlgorithm::shortHelpString()
const
232 return QObject::tr(
"Generates a raster layer for given extent and cell size "
233 "filled with random values.\n"
234 "By default, the values will range between the minimum and "
235 "maximum value of the specified output raster type. This can "
236 "be overridden by using the advanced parameters for lower and "
237 "upper bound value. If the bounds have the same value or both "
238 "are zero (default) the algorithm will create random values in "
239 "the full value range of the chosen raster data type. "
240 "Choosing bounds outside the acceptable range of the output "
241 "raster type will abort the algorithm." );
244QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance()
const
246 return new QgsRandomUniformRasterAlgorithm();
249void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
251 QStringList rasterDataTypes = QStringList();
252 rasterDataTypes << QStringLiteral(
"Byte" )
253 << QStringLiteral(
"Integer16" )
254 << QStringLiteral(
"Unsigned Integer16" )
255 << QStringLiteral(
"Integer32" )
256 << QStringLiteral(
"Unsigned Integer32" )
257 << QStringLiteral(
"Float32" )
258 << QStringLiteral(
"Float64" );
260 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 5,
false );
262 addParameter( rasterTypeParameter.release() );
264 std::unique_ptr< QgsProcessingParameterNumber > lowerBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"LOWER_BOUND" ), QStringLiteral(
"Lower bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
266 addParameter( lowerBoundParameter.release() );
268 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"UPPER_BOUND" ), QStringLiteral(
"Upper bound for random number range" ),
Qgis::ProcessingNumberParameterType::Double, QVariant(),
true );
270 addParameter( upperBoundParameter.release() );
273Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType(
int typeId )
296bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
298 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral(
"UPPER_BOUND" ), context );
299 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral(
"LOWER_BOUND" ), context );
301 if ( mRandomLowerBound > mRandomUpperBound )
302 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." ) );
304 const int typeId = parameterAsInt( parameters, QStringLiteral(
"OUTPUT_TYPE" ), context );
305 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
307 switch ( rasterDataType )
310 if ( mRandomLowerBound < std::numeric_limits<quint8>::min() || mRandomUpperBound > std::numeric_limits<quint8>::max() )
311 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" ) ) );
315 mRandomUpperBound = std::numeric_limits<quint8>::max();
316 mRandomLowerBound = std::numeric_limits<quint8>::min();
320 if ( mRandomLowerBound < std::numeric_limits<qint8>::min() || mRandomUpperBound > std::numeric_limits<qint8>::max() )
321 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" ) ) );
325 mRandomUpperBound = std::numeric_limits<qint8>::max();
326 mRandomLowerBound = std::numeric_limits<qint8>::min();
330 if ( mRandomLowerBound < std::numeric_limits<qint16>::min() || mRandomUpperBound > std::numeric_limits<qint16>::max() )
331 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" ) ) );
334 mRandomUpperBound = std::numeric_limits<qint16>::max();
335 mRandomLowerBound = std::numeric_limits<qint16>::min();
339 if ( mRandomLowerBound < std::numeric_limits<quint16>::min() || mRandomUpperBound > std::numeric_limits<quint16>::max() )
340 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" ) ) );
343 mRandomUpperBound = std::numeric_limits<quint16>::max();
344 mRandomLowerBound = std::numeric_limits<quint16>::min();
348 if ( mRandomLowerBound < std::numeric_limits<qint32>::min() || mRandomUpperBound > std::numeric_limits<qint32>::max() )
349 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" ) ) );
352 mRandomUpperBound = std::numeric_limits<qint32>::max();
353 mRandomLowerBound = std::numeric_limits<qint32>::min();
357 if ( mRandomLowerBound < std::numeric_limits<quint32>::min() || mRandomUpperBound > std::numeric_limits<quint32>::max() )
358 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" ) ) );
361 mRandomUpperBound = std::numeric_limits<quint32>::max();
362 mRandomLowerBound = std::numeric_limits<quint32>::min();
368 mRandomUpperBound = std::numeric_limits<float>::max();
369 mRandomLowerBound = std::numeric_limits<float>::min();
375 mRandomUpperBound = std::numeric_limits<double>::max();
376 mRandomLowerBound = std::numeric_limits<double>::min();
389 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
390 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
395long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
397 return mRandomUniformIntDistribution( mersenneTwister );
400double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
402 return mRandomUniformDoubleDistribution( mersenneTwister );
408QString QgsRandomBinomialRasterAlgorithm::name()
const
410 return QStringLiteral(
"createrandombinomialrasterlayer" );
413QString QgsRandomBinomialRasterAlgorithm::displayName()
const
415 return QObject::tr(
"Create random raster layer (binomial distribution)" );
418QStringList QgsRandomBinomialRasterAlgorithm::tags()
const
420 return QObject::tr(
"raster,create,binomial,random" ).split(
',' );
423QString QgsRandomBinomialRasterAlgorithm::shortHelpString()
const
425 return QObject::tr(
"Generates a raster layer for given extent and cell size "
426 "filled with binomially distributed random values.\n"
427 "By default, the values will be chosen given an N of 10 and a probability of 0.5. "
428 "This can be overridden by using the advanced parameter for N and probability. "
429 "The raster data type is set to Integer types (Integer16 by default). "
430 "The binomial distribution random values are defined as positive integer numbers. "
431 "A floating point raster will represent a cast of integer values "
432 "to floating point." );
435QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance()
const
437 return new QgsRandomBinomialRasterAlgorithm();
441void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams( )
443 QStringList rasterDataTypes = QStringList();
444 rasterDataTypes << QStringLiteral(
"Integer16" )
445 << QStringLiteral(
"Unsigned Integer16" )
446 << QStringLiteral(
"Integer32" )
447 << QStringLiteral(
"Unsigned Integer32" )
448 << QStringLiteral(
"Float32" )
449 << QStringLiteral(
"Float64" );
451 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
453 addParameter( rasterTypeParameter.release() );
455 std::unique_ptr< QgsProcessingParameterNumber > nParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"N" ), QStringLiteral(
"N" ),
Qgis::ProcessingNumberParameterType::Integer, 10,
true, 0 );
457 addParameter( nParameter.release() );
459 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
Qgis::ProcessingNumberParameterType::Double, 0.5,
true, 0 );
461 addParameter( probabilityParameter.release() );
464Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType(
int typeId )
485bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
487 const int n = parameterAsInt( parameters, QStringLiteral(
"N" ), context );
488 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
489 mRandombinomialDistribution = std::binomial_distribution<long>( n, probability );
493long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
495 return mRandombinomialDistribution( mersenneTwister );
498double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
500 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
506QString QgsRandomExponentialRasterAlgorithm::name()
const
508 return QStringLiteral(
"createrandomexponentialrasterlayer" );
511QString QgsRandomExponentialRasterAlgorithm::displayName()
const
513 return QObject::tr(
"Create random raster layer (exponential distribution)" );
516QStringList QgsRandomExponentialRasterAlgorithm::tags()
const
518 return QObject::tr(
"raster,create,random,exponential" ).split(
',' );
521QString QgsRandomExponentialRasterAlgorithm::shortHelpString()
const
523 return QObject::tr(
"Generates a raster layer for given extent and cell size "
524 "filled with exponentially distributed random values.\n"
525 "By default, the values will be chosen given a lambda of 1.0. "
526 "This can be overridden by using the advanced parameter for lambda. "
527 "The raster data type is set to Float32 by default as "
528 "the exponential distribution random values are floating point numbers." );
531QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance()
const
533 return new QgsRandomExponentialRasterAlgorithm();
537void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
539 QStringList rasterDataTypes = QStringList();
540 rasterDataTypes << QStringLiteral(
"Float32" )
541 << QStringLiteral(
"Float64" );
543 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
545 addParameter( rasterTypeParameter.release() );
547 std::unique_ptr< QgsProcessingParameterNumber > lambdaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"LAMBDA" ), QStringLiteral(
"Lambda" ),
Qgis::ProcessingNumberParameterType::Double, 1.0,
true, 0.000001 );
549 addParameter( lambdaParameter.release() );
552Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType(
int typeId )
565bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
567 const double lambda = parameterAsDouble( parameters, QStringLiteral(
"LAMBDA" ), context );
568 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
572long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
574 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
577double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
579 return mRandomExponentialDistribution( mersenneTwister );
585QString QgsRandomGammaRasterAlgorithm::name()
const
587 return QStringLiteral(
"createrandomgammarasterlayer" );
590QString QgsRandomGammaRasterAlgorithm::displayName()
const
592 return QObject::tr(
"Create random raster layer (gamma distribution)" );
595QStringList QgsRandomGammaRasterAlgorithm::tags()
const
597 return QObject::tr(
"raster,create,random,gamma" ).split(
',' );
600QString QgsRandomGammaRasterAlgorithm::shortHelpString()
const
602 return QObject::tr(
"Generates a raster layer for given extent and cell size "
603 "filled with gamma distributed random values.\n"
604 "By default, the values will be chosen given an alpha and beta value of 1.0. "
605 "This can be overridden by using the advanced parameter for alpha and beta. "
606 "The raster data type is set to Float32 by default as "
607 "the gamma distribution random values are floating point numbers." );
610QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance()
const
612 return new QgsRandomGammaRasterAlgorithm();
616void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
618 QStringList rasterDataTypes = QStringList();
619 rasterDataTypes << QStringLiteral(
"Float32" )
620 << QStringLiteral(
"Float64" );
622 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
624 addParameter( rasterTypeParameter.release() );
626 std::unique_ptr< QgsProcessingParameterNumber > alphaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"ALPHA" ), QStringLiteral(
"Alpha" ),
Qgis::ProcessingNumberParameterType::Double, 1.0,
true, 0.000001 );
628 addParameter( alphaParameter.release() );
630 std::unique_ptr< QgsProcessingParameterNumber > betaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"BETA" ), QStringLiteral(
"Beta" ),
Qgis::ProcessingNumberParameterType::Double, 1.0,
true, 0.000001 );
632 addParameter( betaParameter.release() );
635Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType(
int typeId )
648bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
650 const double alpha = parameterAsDouble( parameters, QStringLiteral(
"ALPHA" ), context );
651 const double beta = parameterAsDouble( parameters, QStringLiteral(
"BETA" ), context );
652 mRandomGammaDistribution = std::gamma_distribution<double>( alpha, beta );
656long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
658 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
661double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
663 return mRandomGammaDistribution( mersenneTwister );
669QString QgsRandomGeometricRasterAlgorithm::name()
const
671 return QStringLiteral(
"createrandomgeometricrasterlayer" );
674QString QgsRandomGeometricRasterAlgorithm::displayName()
const
676 return QObject::tr(
"Create random raster layer (geometric distribution)" );
679QStringList QgsRandomGeometricRasterAlgorithm::tags()
const
681 return QObject::tr(
"raster,create,random,geometric" ).split(
',' );
684QString QgsRandomGeometricRasterAlgorithm::shortHelpString()
const
686 return QObject::tr(
"Generates a raster layer for given extent and cell size "
687 "filled with geometrically distributed random values.\n"
688 "By default, the values will be chosen given a probability of 0.5. "
689 "This can be overridden by using the advanced parameter for mean "
690 "value. The raster data type is set to Integer types (Integer16 by default). "
691 "The geometric distribution random values are defined as positive integer numbers. "
692 "A floating point raster will represent a cast of "
693 "integer values to floating point." );
696QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance()
const
698 return new QgsRandomGeometricRasterAlgorithm();
702void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
704 QStringList rasterDataTypes = QStringList();
705 rasterDataTypes << QStringLiteral(
"Integer16" )
706 << QStringLiteral(
"Unsigned Integer16" )
707 << QStringLiteral(
"Integer32" )
708 << QStringLiteral(
"Unsigned Integer32" )
709 << QStringLiteral(
"Float32" )
710 << QStringLiteral(
"Float64" );
712 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
714 addParameter( rasterTypeParameter.release() );
716 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
Qgis::ProcessingNumberParameterType::Double, 0.5,
true, 0.00001 );
718 addParameter( probabilityParameter.release() );
721Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType(
int typeId )
742bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
744 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
745 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
749long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
751 return mRandomGeometricDistribution( mersenneTwister );
754double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
756 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
762QString QgsRandomNegativeBinomialRasterAlgorithm::name()
const
764 return QStringLiteral(
"createrandomnegativebinomialrasterlayer" );
767QString QgsRandomNegativeBinomialRasterAlgorithm::displayName()
const
769 return QObject::tr(
"Create random raster layer (negative binomial distribution)" );
772QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags()
const
774 return QObject::tr(
"raster,create,random,negative,binomial,negative-binomial" ).split(
',' );
777QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString()
const
779 return QObject::tr(
"Generates a raster layer for given extent and cell size "
780 "filled with negative binomially distributed random values.\n"
781 "By default, the values will be chosen given a distribution parameter k of 10.0 "
782 "and a probability of 0.5. "
783 "This can be overridden by using the advanced parameters for k and probability. "
784 "The raster data type is set to Integer types (Integer 16 by default). "
785 "The negative binomial distribution random values are defined as positive integer numbers. "
786 "A floating point raster will represent a cast of "
787 "integer values to floating point." );
790QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance()
const
792 return new QgsRandomNegativeBinomialRasterAlgorithm();
796void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams( )
798 QStringList rasterDataTypes = QStringList();
799 rasterDataTypes << QStringLiteral(
"Integer16" )
800 << QStringLiteral(
"Unsigned Integer16" )
801 << QStringLiteral(
"Integer32" )
802 << QStringLiteral(
"Unsigned Integer32" )
803 << QStringLiteral(
"Float32" )
804 << QStringLiteral(
"Float64" );
806 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
808 addParameter( rasterTypeParameter.release() );
810 std::unique_ptr< QgsProcessingParameterNumber > kParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"K_PARAMETER" ), QStringLiteral(
"Distribution parameter k" ),
Qgis::ProcessingNumberParameterType::Integer, 10,
true, 0.00001 );
812 addParameter( kParameter.release() );
814 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"PROBABILITY" ), QStringLiteral(
"Probability" ),
Qgis::ProcessingNumberParameterType::Double, 0.5,
true, 0.00001 );
816 addParameter( probabilityParameter.release() );
819Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType(
int typeId )
840bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
842 const int k = parameterAsInt( parameters, QStringLiteral(
"K_PARAMETER" ), context );
843 const double probability = parameterAsDouble( parameters, QStringLiteral(
"PROBABILITY" ), context );
844 mRandomNegativeBinomialDistribution = std::negative_binomial_distribution<long>( k, probability );
848long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
850 return mRandomNegativeBinomialDistribution( mersenneTwister );
853double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
855 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
861QString QgsRandomNormalRasterAlgorithm::name()
const
863 return QStringLiteral(
"createrandomnormalrasterlayer" );
866QString QgsRandomNormalRasterAlgorithm::displayName()
const
868 return QObject::tr(
"Create random raster layer (normal distribution)" );
871QStringList QgsRandomNormalRasterAlgorithm::tags()
const
873 return QObject::tr(
"raster,create,normal,distribution,random" ).split(
',' );
876QString QgsRandomNormalRasterAlgorithm::shortHelpString()
const
878 return QObject::tr(
"Generates a raster layer for given extent and cell size "
879 "filled with normally distributed random values.\n"
880 "By default, the values will be chosen given a mean of 0.0 and "
881 "a standard deviation of 1.0. This can be overridden by "
882 "using the advanced parameters for mean and standard deviation "
883 "value. The raster data type is set to Float32 by default "
884 "as the normal distribution random values are floating point numbers." );
887QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance()
const
889 return new QgsRandomNormalRasterAlgorithm();
892void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
894 QStringList rasterDataTypes = QStringList();
895 rasterDataTypes << QStringLiteral(
"Float32" )
896 << QStringLiteral(
"Float64" );
898 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
900 addParameter( rasterTypeParameter.release() );
902 std::unique_ptr< QgsProcessingParameterNumber > meanParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 0,
true );
904 addParameter( meanParameter.release() );
906 std::unique_ptr< QgsProcessingParameterNumber > stdevParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"STDDEV" ), QStringLiteral(
"Standard deviation of normal distribution" ),
Qgis::ProcessingNumberParameterType::Double, 1,
true, 0 );
908 addParameter( stdevParameter.release() );
911Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType(
int typeId )
924bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
926 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
927 const double stddev = parameterAsDouble( parameters, QStringLiteral(
"STDDEV" ), context );
928 mRandomNormalDistribution = std::normal_distribution<double>( mean, stddev );
932long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
934 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
937double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
939 return mRandomNormalDistribution( mersenneTwister );
945QString QgsRandomPoissonRasterAlgorithm::name()
const
947 return QStringLiteral(
"createrandompoissonrasterlayer" );
950QString QgsRandomPoissonRasterAlgorithm::displayName()
const
952 return QObject::tr(
"Create random raster layer (poisson distribution)" );
955QStringList QgsRandomPoissonRasterAlgorithm::tags()
const
957 return QObject::tr(
"raster,create,random,poisson" ).split(
',' );
960QString QgsRandomPoissonRasterAlgorithm::shortHelpString()
const
962 return QObject::tr(
"Generates a raster layer for given extent and cell size "
963 "filled with poisson distributed random values.\n"
964 "By default, the values will be chosen given a mean of 1.0. "
965 "This can be overridden by using the advanced parameter for mean "
966 "value. The raster data type is set to Integer types (Integer16 by default). "
967 "The poisson distribution random values are positive integer numbers. "
968 "A floating point raster will represent a cast of integer values to floating point." );
971QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance()
const
973 return new QgsRandomPoissonRasterAlgorithm();
977void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
979 QStringList rasterDataTypes = QStringList();
980 rasterDataTypes << QStringLiteral(
"Integer16" )
981 << QStringLiteral(
"Unsigned Integer16" )
982 << QStringLiteral(
"Integer32" )
983 << QStringLiteral(
"Unsigned Integer32" )
984 << QStringLiteral(
"Float32" )
985 << QStringLiteral(
"Float64" );
987 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"OUTPUT_TYPE" ), QObject::tr(
"Output raster data type" ), rasterDataTypes,
false, 0,
false );
989 addParameter( rasterTypeParameter.release() );
991 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral(
"MEAN" ), QStringLiteral(
"Mean" ),
Qgis::ProcessingNumberParameterType::Double, 1.0,
true, 0 );
993 addParameter( upperBoundParameter.release() );
996Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType(
int typeId )
1017bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters(
const QVariantMap ¶meters,
QgsProcessingContext &context )
1019 const double mean = parameterAsDouble( parameters, QStringLiteral(
"MEAN" ), context );
1020 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1024long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1026 return mRandomPoissonDistribution( mersenneTwister );
1029double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1031 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)