QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsalgorithmrandomraster.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmrandomraster.cpp
3 ---------------------
4 begin : May 2020
5 copyright : (C) 2020 by Clemens Raffler
6 email : clemens dot raffler at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "qgsrasterfilewriter.h"
20#include "qgsstringutils.h"
21#include "random"
22#include "limits"
23
25
26//
27// QgsRandomRasterAlgorithmBase
28//
29QString QgsRandomRasterAlgorithmBase::group() const
30{
31 return QObject::tr( "Raster creation" );
32}
33
34QString QgsRandomRasterAlgorithmBase::groupId() const
35{
36 return QStringLiteral( "rastercreation" );
37}
38
39void QgsRandomRasterAlgorithmBase::initAlgorithm( const QVariantMap & )
40{
41 addParameter( new QgsProcessingParameterExtent( QStringLiteral( "EXTENT" ), QObject::tr( "Desired extent" ) ) );
42 addParameter( new QgsProcessingParameterCrs( QStringLiteral( "TARGET_CRS" ), QObject::tr( "Target CRS" ), QStringLiteral( "ProjectCrs" ) ) );
43 addParameter( new QgsProcessingParameterNumber( QStringLiteral( "PIXEL_SIZE" ), QObject::tr( "Pixel size" ),
45
46 //add specific parameters
47 addAlgorithmParams();
48
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" ) }} ) }} ) );
51 createOptsParam->setFlags( createOptsParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
52 addParameter( createOptsParam.release() );
53
54 addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Output raster" ) ) );
55}
56
57bool QgsRandomRasterAlgorithmBase::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
58{
59 Q_UNUSED( feedback );
60 mCrs = parameterAsCrs( parameters, QStringLiteral( "TARGET_CRS" ), context );
61 mExtent = parameterAsExtent( parameters, QStringLiteral( "EXTENT" ), context, mCrs );
62 mPixelSize = parameterAsDouble( parameters, QStringLiteral( "PIXEL_SIZE" ), context );
63
64 if ( mPixelSize <= 0 )
65 {
66 throw QgsProcessingException( QObject::tr( "Pixel size must be greater than 0." ) );
67 }
68
69 return true;
70}
71
72QVariantMap QgsRandomRasterAlgorithmBase::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
73{
74 const int typeId = parameterAsInt( parameters, QStringLiteral( "OUTPUT_TYPE" ), context );
75 //prepare specific parameters
76 mRasterDataType = getRasterDataType( typeId );
77 prepareRandomParameters( parameters, context );
78
79 std::random_device rd {};
80 std::mt19937 mersenneTwister{rd()};
81
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 );
85 const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
86
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 );
89
90 //build new raster extent based on number of columns and cellsize
91 //this prevents output cellsize being calculated too small
92 const QgsRectangle rasterExtent = QgsRectangle( mExtent.xMinimum(), mExtent.yMaximum() - ( rows * mPixelSize ), mExtent.xMinimum() + ( cols * mPixelSize ), mExtent.yMaximum() );
93
94 std::unique_ptr< QgsRasterFileWriter > writer = std::make_unique< QgsRasterFileWriter >( outputFile );
95 writer->setOutputProviderKey( QStringLiteral( "gdal" ) );
96 if ( !createOptions.isEmpty() )
97 {
98 writer->setCreateOptions( createOptions.split( '|' ) );
99 }
100
101 writer->setOutputFormat( outputFormat );
102 std::unique_ptr<QgsRasterDataProvider > provider( writer->createOneBandRaster( mRasterDataType, cols, rows, rasterExtent, mCrs ) );
103 if ( !provider )
104 throw QgsProcessingException( QObject::tr( "Could not create raster output: %1" ).arg( outputFile ) );
105 if ( !provider->isValid() )
106 throw QgsProcessingException( QObject::tr( "Could not create raster output %1: %2" ).arg( outputFile, provider->error().message( QgsErrorMessage::Text ) ) );
107
108 const double step = rows > 0 ? 100.0 / rows : 1;
109
110 for ( int row = 0; row < rows ; row++ )
111 {
112 if ( feedback->isCanceled() )
113 {
114 break;
115 }
116 //prepare raw data depending on raster data type
117 QgsRasterBlock block( mRasterDataType, cols, 1 );
118 switch ( mRasterDataType )
119 {
121 {
122 std::vector<quint8> byteRow( cols );
123 for ( int col = 0; col < cols; col++ )
124 {
125 byteRow[col] = static_cast<quint8>( generateRandomLongValue( mersenneTwister ) );
126 }
127 block.setData( QByteArray( reinterpret_cast<const char *>( byteRow.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Byte ) * cols ) );
128 break;
129 }
131 {
132 std::vector<qint8> int8Row( cols );
133 for ( int col = 0; col < cols; col++ )
134 {
135 int8Row[col] = static_cast<qint8>( generateRandomLongValue( mersenneTwister ) );
136 }
137 block.setData( QByteArray( reinterpret_cast<const char *>( int8Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Int8 ) * cols ) );
138 break;
139 }
141 {
142 std::vector<qint16> int16Row( cols );
143 for ( int col = 0; col < cols; col++ )
144 {
145 int16Row[col] = static_cast<qint16>( generateRandomLongValue( mersenneTwister ) );
146 }
147 block.setData( QByteArray( reinterpret_cast<const char *>( int16Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Int16 ) * cols ) );
148 break;
149 }
151 {
152 std::vector<quint16> uInt16Row( cols );
153 for ( int col = 0; col < cols; col++ )
154 {
155 uInt16Row[col] = static_cast<quint16>( generateRandomLongValue( mersenneTwister ) );
156 }
157 block.setData( QByteArray( reinterpret_cast<const char *>( uInt16Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::UInt16 ) * cols ) );
158 break;
159 }
161 {
162 std::vector<qint32> int32Row( cols );
163 for ( int col = 0; col < cols; col++ )
164 {
165 int32Row[col] = generateRandomLongValue( mersenneTwister );
166 }
167 block.setData( QByteArray( reinterpret_cast<const char *>( int32Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Int32 ) * cols ) );
168 break;
169 }
171 {
172 std::vector<quint32> uInt32Row( cols );
173 for ( int col = 0; col < cols; col++ )
174 {
175 uInt32Row[col] = static_cast<quint32>( generateRandomLongValue( mersenneTwister ) );
176 }
177 block.setData( QByteArray( reinterpret_cast<const char *>( uInt32Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::UInt32 ) * cols ) );
178 break;
179 }
181 {
182 std::vector<float> float32Row( cols );
183 for ( int col = 0; col < cols; col++ )
184 {
185 float32Row[col] = static_cast<float>( generateRandomDoubleValue( mersenneTwister ) );
186 }
187 block.setData( QByteArray( reinterpret_cast<const char *>( float32Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Float32 ) * cols ) );
188 break;
189 }
191 {
192 std::vector<double> float64Row( cols );
193 for ( int col = 0; col < cols; col++ )
194 {
195 float64Row[col] = generateRandomDoubleValue( mersenneTwister );
196 }
197 block.setData( QByteArray( reinterpret_cast<const char *>( float64Row.data() ), QgsRasterBlock::typeSize( Qgis::DataType::Float64 ) * cols ) );
198 break;
199 }
200 default:
201 break;
202 }
203 provider->writeBlock( &block, 1, 0, row );
204 feedback->setProgress( row * step );
205 }
206
207 QVariantMap outputs;
208 outputs.insert( QStringLiteral( "OUTPUT" ), outputFile );
209 return outputs;
210}
211
212//
213//QgsRandomUniformRasterAlgorithm
214//
215QString QgsRandomUniformRasterAlgorithm::name() const
216{
217 return QStringLiteral( "createrandomuniformrasterlayer" );
218}
219
220QString QgsRandomUniformRasterAlgorithm::displayName() const
221{
222 return QObject::tr( "Create random raster layer (uniform distribution)" );
223}
224
225QStringList QgsRandomUniformRasterAlgorithm::tags() const
226{
227 return QObject::tr( "raster,create,random" ).split( ',' );
228}
229
230QString QgsRandomUniformRasterAlgorithm::shortHelpString() const
231{
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." );
242}
243
244QgsRandomUniformRasterAlgorithm *QgsRandomUniformRasterAlgorithm::createInstance() const
245{
246 return new QgsRandomUniformRasterAlgorithm();
247}
248
249void QgsRandomUniformRasterAlgorithm::addAlgorithmParams()
250{
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" );
259
260 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 5, false );
261 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
262 addParameter( rasterTypeParameter.release() );
263
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 );
265 lowerBoundParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
266 addParameter( lowerBoundParameter.release() );
267
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 );
269 upperBoundParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
270 addParameter( upperBoundParameter.release() );
271}
272
273Qgis::DataType QgsRandomUniformRasterAlgorithm::getRasterDataType( int typeId )
274{
275 switch ( typeId )
276 {
277 case 0:
279 case 1:
281 case 2:
283 case 3:
285 case 4:
287 case 5:
289 case 6:
291 default:
293 }
294}
295
296bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
297{
298 mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral( "UPPER_BOUND" ), context );
299 mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral( "LOWER_BOUND" ), context );
300
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." ) );
303
304 const int typeId = parameterAsInt( parameters, QStringLiteral( "OUTPUT_TYPE" ), context );
305 const Qgis::DataType rasterDataType = getRasterDataType( typeId );
306
307 switch ( rasterDataType )
308 {
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" ) ) );
312 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
313 {
314 //if parameters unset (=both are 0 or equal) --> use the whole value range
315 mRandomUpperBound = std::numeric_limits<quint8>::max();
316 mRandomLowerBound = std::numeric_limits<quint8>::min();
317 }
318 break;
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" ) ) );
322 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
323 {
324 //if parameters unset (=both are 0 or equal) --> use the whole value range
325 mRandomUpperBound = std::numeric_limits<qint8>::max();
326 mRandomLowerBound = std::numeric_limits<qint8>::min();
327 }
328 break;
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" ) ) );
332 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
333 {
334 mRandomUpperBound = std::numeric_limits<qint16>::max();
335 mRandomLowerBound = std::numeric_limits<qint16>::min();
336 }
337 break;
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" ) ) );
341 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
342 {
343 mRandomUpperBound = std::numeric_limits<quint16>::max();
344 mRandomLowerBound = std::numeric_limits<quint16>::min();
345 }
346 break;
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" ) ) );
350 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
351 {
352 mRandomUpperBound = std::numeric_limits<qint32>::max();
353 mRandomLowerBound = std::numeric_limits<qint32>::min();
354 }
355 break;
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" ) ) );
359 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
360 {
361 mRandomUpperBound = std::numeric_limits<quint32>::max();
362 mRandomLowerBound = std::numeric_limits<quint32>::min();
363 }
364 break;
366 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
367 {
368 mRandomUpperBound = std::numeric_limits<float>::max();
369 mRandomLowerBound = std::numeric_limits<float>::min();
370 }
371 break;
373 if ( ( qgsDoubleNear( mRandomLowerBound, 0.0 ) && qgsDoubleNear( mRandomUpperBound, 0.0 ) ) || qgsDoubleNear( mRandomUpperBound, mRandomLowerBound ) )
374 {
375 mRandomUpperBound = std::numeric_limits<double>::max();
376 mRandomLowerBound = std::numeric_limits<double>::min();
377 }
378 break;
386 break;
387 }
388
389 mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
390 mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );
391
392 return true;
393}
394
395long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
396{
397 return mRandomUniformIntDistribution( mersenneTwister );
398}
399
400double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
401{
402 return mRandomUniformDoubleDistribution( mersenneTwister );
403}
404
405//
406// QgsRandomBinomialRasterAlgorithm
407//
408QString QgsRandomBinomialRasterAlgorithm::name() const
409{
410 return QStringLiteral( "createrandombinomialrasterlayer" );
411}
412
413QString QgsRandomBinomialRasterAlgorithm::displayName() const
414{
415 return QObject::tr( "Create random raster layer (binomial distribution)" );
416}
417
418QStringList QgsRandomBinomialRasterAlgorithm::tags() const
419{
420 return QObject::tr( "raster,create,binomial,random" ).split( ',' );
421}
422
423QString QgsRandomBinomialRasterAlgorithm::shortHelpString() const
424{
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." );
433}
434
435QgsRandomBinomialRasterAlgorithm *QgsRandomBinomialRasterAlgorithm::createInstance() const
436{
437 return new QgsRandomBinomialRasterAlgorithm();
438}
439
440
441void QgsRandomBinomialRasterAlgorithm::addAlgorithmParams( )
442{
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" );
450
451 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
452 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
453 addParameter( rasterTypeParameter.release() );
454
455 std::unique_ptr< QgsProcessingParameterNumber > nParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "N" ), QStringLiteral( "N" ), Qgis::ProcessingNumberParameterType::Integer, 10, true, 0 );
456 nParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
457 addParameter( nParameter.release() );
458
459 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "PROBABILITY" ), QStringLiteral( "Probability" ), Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0 );
460 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
461 addParameter( probabilityParameter.release() );
462}
463
464Qgis::DataType QgsRandomBinomialRasterAlgorithm::getRasterDataType( int typeId )
465{
466 switch ( typeId )
467 {
468 case 0:
470 case 1:
472 case 2:
474 case 3:
476 case 4:
478 case 5:
480 default:
482 }
483}
484
485bool QgsRandomBinomialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
486{
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 );
490 return true;
491}
492
493long QgsRandomBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
494{
495 return mRandombinomialDistribution( mersenneTwister );
496}
497
498double QgsRandomBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
499{
500 return static_cast<double>( mRandombinomialDistribution( mersenneTwister ) );
501}
502
503//
504// QgsRandomExponentialRasterAlgorithm
505//
506QString QgsRandomExponentialRasterAlgorithm::name() const
507{
508 return QStringLiteral( "createrandomexponentialrasterlayer" );
509}
510
511QString QgsRandomExponentialRasterAlgorithm::displayName() const
512{
513 return QObject::tr( "Create random raster layer (exponential distribution)" );
514}
515
516QStringList QgsRandomExponentialRasterAlgorithm::tags() const
517{
518 return QObject::tr( "raster,create,random,exponential" ).split( ',' );
519}
520
521QString QgsRandomExponentialRasterAlgorithm::shortHelpString() const
522{
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." );
529}
530
531QgsRandomExponentialRasterAlgorithm *QgsRandomExponentialRasterAlgorithm::createInstance() const
532{
533 return new QgsRandomExponentialRasterAlgorithm();
534}
535
536
537void QgsRandomExponentialRasterAlgorithm::addAlgorithmParams()
538{
539 QStringList rasterDataTypes = QStringList();
540 rasterDataTypes << QStringLiteral( "Float32" )
541 << QStringLiteral( "Float64" );
542
543 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
544 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
545 addParameter( rasterTypeParameter.release() );
546
547 std::unique_ptr< QgsProcessingParameterNumber > lambdaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "LAMBDA" ), QStringLiteral( "Lambda" ), Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
548 lambdaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
549 addParameter( lambdaParameter.release() );
550}
551
552Qgis::DataType QgsRandomExponentialRasterAlgorithm::getRasterDataType( int typeId )
553{
554 switch ( typeId )
555 {
556 case 0:
558 case 1:
560 default:
562 }
563}
564
565bool QgsRandomExponentialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
566{
567 const double lambda = parameterAsDouble( parameters, QStringLiteral( "LAMBDA" ), context );
568 mRandomExponentialDistribution = std::exponential_distribution<double>( lambda );
569 return true;
570}
571
572long QgsRandomExponentialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
573{
574 return static_cast<long>( mRandomExponentialDistribution( mersenneTwister ) );
575}
576
577double QgsRandomExponentialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
578{
579 return mRandomExponentialDistribution( mersenneTwister );
580}
581
582//
583// QgsRandomGammaRasterAlgorithm
584//
585QString QgsRandomGammaRasterAlgorithm::name() const
586{
587 return QStringLiteral( "createrandomgammarasterlayer" );
588}
589
590QString QgsRandomGammaRasterAlgorithm::displayName() const
591{
592 return QObject::tr( "Create random raster layer (gamma distribution)" );
593}
594
595QStringList QgsRandomGammaRasterAlgorithm::tags() const
596{
597 return QObject::tr( "raster,create,random,gamma" ).split( ',' );
598}
599
600QString QgsRandomGammaRasterAlgorithm::shortHelpString() const
601{
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." );
608}
609
610QgsRandomGammaRasterAlgorithm *QgsRandomGammaRasterAlgorithm::createInstance() const
611{
612 return new QgsRandomGammaRasterAlgorithm();
613}
614
615
616void QgsRandomGammaRasterAlgorithm::addAlgorithmParams()
617{
618 QStringList rasterDataTypes = QStringList();
619 rasterDataTypes << QStringLiteral( "Float32" )
620 << QStringLiteral( "Float64" );
621
622 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
623 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
624 addParameter( rasterTypeParameter.release() );
625
626 std::unique_ptr< QgsProcessingParameterNumber > alphaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ALPHA" ), QStringLiteral( "Alpha" ), Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
627 alphaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
628 addParameter( alphaParameter.release() );
629
630 std::unique_ptr< QgsProcessingParameterNumber > betaParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "BETA" ), QStringLiteral( "Beta" ), Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0.000001 );
631 betaParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
632 addParameter( betaParameter.release() );
633}
634
635Qgis::DataType QgsRandomGammaRasterAlgorithm::getRasterDataType( int typeId )
636{
637 switch ( typeId )
638 {
639 case 0:
641 case 1:
643 default:
645 }
646}
647
648bool QgsRandomGammaRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
649{
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 );
653 return true;
654}
655
656long QgsRandomGammaRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
657{
658 return static_cast<long>( mRandomGammaDistribution( mersenneTwister ) );
659}
660
661double QgsRandomGammaRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
662{
663 return mRandomGammaDistribution( mersenneTwister );
664}
665
666//
667// QgsRandomGeometricRasterAlgorithm
668//
669QString QgsRandomGeometricRasterAlgorithm::name() const
670{
671 return QStringLiteral( "createrandomgeometricrasterlayer" );
672}
673
674QString QgsRandomGeometricRasterAlgorithm::displayName() const
675{
676 return QObject::tr( "Create random raster layer (geometric distribution)" );
677}
678
679QStringList QgsRandomGeometricRasterAlgorithm::tags() const
680{
681 return QObject::tr( "raster,create,random,geometric" ).split( ',' );
682}
683
684QString QgsRandomGeometricRasterAlgorithm::shortHelpString() const
685{
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." );
694}
695
696QgsRandomGeometricRasterAlgorithm *QgsRandomGeometricRasterAlgorithm::createInstance() const
697{
698 return new QgsRandomGeometricRasterAlgorithm();
699}
700
701
702void QgsRandomGeometricRasterAlgorithm::addAlgorithmParams()
703{
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" );
711
712 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
713 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
714 addParameter( rasterTypeParameter.release() );
715
716 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "PROBABILITY" ), QStringLiteral( "Probability" ), Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0.00001 );
717 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
718 addParameter( probabilityParameter.release() );
719}
720
721Qgis::DataType QgsRandomGeometricRasterAlgorithm::getRasterDataType( int typeId )
722{
723 switch ( typeId )
724 {
725 case 0:
727 case 1:
729 case 2:
731 case 3:
733 case 4:
735 case 5:
737 default:
739 }
740}
741
742bool QgsRandomGeometricRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
743{
744 const double probability = parameterAsDouble( parameters, QStringLiteral( "PROBABILITY" ), context );
745 mRandomGeometricDistribution = std::geometric_distribution<long>( probability );
746 return true;
747}
748
749long QgsRandomGeometricRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
750{
751 return mRandomGeometricDistribution( mersenneTwister );
752}
753
754double QgsRandomGeometricRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
755{
756 return static_cast<double>( mRandomGeometricDistribution( mersenneTwister ) );
757}
758
759//
760// QgsRandomNegativeBinomialRasterAlgorithm
761//
762QString QgsRandomNegativeBinomialRasterAlgorithm::name() const
763{
764 return QStringLiteral( "createrandomnegativebinomialrasterlayer" );
765}
766
767QString QgsRandomNegativeBinomialRasterAlgorithm::displayName() const
768{
769 return QObject::tr( "Create random raster layer (negative binomial distribution)" );
770}
771
772QStringList QgsRandomNegativeBinomialRasterAlgorithm::tags() const
773{
774 return QObject::tr( "raster,create,random,negative,binomial,negative-binomial" ).split( ',' );
775}
776
777QString QgsRandomNegativeBinomialRasterAlgorithm::shortHelpString() const
778{
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." );
788}
789
790QgsRandomNegativeBinomialRasterAlgorithm *QgsRandomNegativeBinomialRasterAlgorithm::createInstance() const
791{
792 return new QgsRandomNegativeBinomialRasterAlgorithm();
793}
794
795
796void QgsRandomNegativeBinomialRasterAlgorithm::addAlgorithmParams( )
797{
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" );
805
806 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
807 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
808 addParameter( rasterTypeParameter.release() );
809
810 std::unique_ptr< QgsProcessingParameterNumber > kParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "K_PARAMETER" ), QStringLiteral( "Distribution parameter k" ), Qgis::ProcessingNumberParameterType::Integer, 10, true, 0.00001 );
811 kParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
812 addParameter( kParameter.release() );
813
814 std::unique_ptr< QgsProcessingParameterNumber > probabilityParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "PROBABILITY" ), QStringLiteral( "Probability" ), Qgis::ProcessingNumberParameterType::Double, 0.5, true, 0.00001 );
815 probabilityParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
816 addParameter( probabilityParameter.release() );
817}
818
819Qgis::DataType QgsRandomNegativeBinomialRasterAlgorithm::getRasterDataType( int typeId )
820{
821 switch ( typeId )
822 {
823 case 0:
825 case 1:
827 case 2:
829 case 3:
831 case 4:
833 case 5:
835 default:
837 }
838}
839
840bool QgsRandomNegativeBinomialRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
841{
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 );
845 return true;
846}
847
848long QgsRandomNegativeBinomialRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
849{
850 return mRandomNegativeBinomialDistribution( mersenneTwister );
851}
852
853double QgsRandomNegativeBinomialRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
854{
855 return static_cast<double>( mRandomNegativeBinomialDistribution( mersenneTwister ) );
856}
857
858//
859// QgsRandomNormalRasterAlgorithm
860//
861QString QgsRandomNormalRasterAlgorithm::name() const
862{
863 return QStringLiteral( "createrandomnormalrasterlayer" );
864}
865
866QString QgsRandomNormalRasterAlgorithm::displayName() const
867{
868 return QObject::tr( "Create random raster layer (normal distribution)" );
869}
870
871QStringList QgsRandomNormalRasterAlgorithm::tags() const
872{
873 return QObject::tr( "raster,create,normal,distribution,random" ).split( ',' );
874}
875
876QString QgsRandomNormalRasterAlgorithm::shortHelpString() const
877{
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." );
885}
886
887QgsRandomNormalRasterAlgorithm *QgsRandomNormalRasterAlgorithm::createInstance() const
888{
889 return new QgsRandomNormalRasterAlgorithm();
890}
891
892void QgsRandomNormalRasterAlgorithm::addAlgorithmParams()
893{
894 QStringList rasterDataTypes = QStringList();
895 rasterDataTypes << QStringLiteral( "Float32" )
896 << QStringLiteral( "Float64" );
897
898 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
899 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
900 addParameter( rasterTypeParameter.release() );
901
902 std::unique_ptr< QgsProcessingParameterNumber > meanParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "MEAN" ), QStringLiteral( "Mean of normal distribution" ), Qgis::ProcessingNumberParameterType::Double, 0, true );
903 meanParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
904 addParameter( meanParameter.release() );
905
906 std::unique_ptr< QgsProcessingParameterNumber > stdevParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "STDDEV" ), QStringLiteral( "Standard deviation of normal distribution" ), Qgis::ProcessingNumberParameterType::Double, 1, true, 0 );
907 stdevParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
908 addParameter( stdevParameter.release() );
909}
910
911Qgis::DataType QgsRandomNormalRasterAlgorithm::getRasterDataType( int typeId )
912{
913 switch ( typeId )
914 {
915 case 0:
917 case 1:
919 default:
921 }
922}
923
924bool QgsRandomNormalRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
925{
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 );
929 return true;
930}
931
932long QgsRandomNormalRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
933{
934 return static_cast<long>( mRandomNormalDistribution( mersenneTwister ) );
935}
936
937double QgsRandomNormalRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
938{
939 return mRandomNormalDistribution( mersenneTwister );
940}
941
942//
943// QgsRandomPoissonRasterAlgorithm
944//
945QString QgsRandomPoissonRasterAlgorithm::name() const
946{
947 return QStringLiteral( "createrandompoissonrasterlayer" );
948}
949
950QString QgsRandomPoissonRasterAlgorithm::displayName() const
951{
952 return QObject::tr( "Create random raster layer (poisson distribution)" );
953}
954
955QStringList QgsRandomPoissonRasterAlgorithm::tags() const
956{
957 return QObject::tr( "raster,create,random,poisson" ).split( ',' );
958}
959
960QString QgsRandomPoissonRasterAlgorithm::shortHelpString() const
961{
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." );
969}
970
971QgsRandomPoissonRasterAlgorithm *QgsRandomPoissonRasterAlgorithm::createInstance() const
972{
973 return new QgsRandomPoissonRasterAlgorithm();
974}
975
976
977void QgsRandomPoissonRasterAlgorithm::addAlgorithmParams()
978{
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" );
986
987 std::unique_ptr< QgsProcessingParameterDefinition > rasterTypeParameter = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( "OUTPUT_TYPE" ), QObject::tr( "Output raster data type" ), rasterDataTypes, false, 0, false );
988 rasterTypeParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
989 addParameter( rasterTypeParameter.release() );
990
991 std::unique_ptr< QgsProcessingParameterNumber > upperBoundParameter = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "MEAN" ), QStringLiteral( "Mean" ), Qgis::ProcessingNumberParameterType::Double, 1.0, true, 0 );
992 upperBoundParameter->setFlags( Qgis::ProcessingParameterFlag::Advanced );
993 addParameter( upperBoundParameter.release() );
994}
995
996Qgis::DataType QgsRandomPoissonRasterAlgorithm::getRasterDataType( int typeId )
997{
998 switch ( typeId )
999 {
1000 case 0:
1001 return Qgis::DataType::Int16;
1002 case 1:
1004 case 2:
1005 return Qgis::DataType::Int32;
1006 case 3:
1008 case 4:
1010 case 5:
1012 default:
1014 }
1015}
1016
1017bool QgsRandomPoissonRasterAlgorithm::prepareRandomParameters( const QVariantMap &parameters, QgsProcessingContext &context )
1018{
1019 const double mean = parameterAsDouble( parameters, QStringLiteral( "MEAN" ), context );
1020 mRandomPoissonDistribution = std::poisson_distribution<long>( mean );
1021 return true;
1022}
1023
1024long QgsRandomPoissonRasterAlgorithm::generateRandomLongValue( std::mt19937 &mersenneTwister )
1025{
1026 return mRandomPoissonDistribution( mersenneTwister );
1027}
1028
1029double QgsRandomPoissonRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
1030{
1031 return static_cast<double>( mRandomPoissonDistribution( mersenneTwister ) );
1032}
1033
DataType
Raster data types.
Definition qgis.h:351
@ CInt32
Complex Int32.
@ 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.
@ CInt16
Complex Int16.
@ UInt32
Thirty two bit unsigned integer (quint32)
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:61
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 ...
Raster data container.
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)
Definition qgis.h:5958