28QString QgsFuzzifyRasterAlgorithmBase::group()
const
30 return QObject::tr(
"Raster analysis" );
33QString QgsFuzzifyRasterAlgorithmBase::groupId()
const
35 return QStringLiteral(
"rasteranalysis" );
38void QgsFuzzifyRasterAlgorithmBase::initAlgorithm(
const QVariantMap & )
41 addParameter(
new QgsProcessingParameterBand( QStringLiteral(
"BAND" ), QObject::tr(
"Band Number" ), 1, QStringLiteral(
"INPUT" ) ) );
52 std::unique_ptr<QgsProcessingParameterString> createOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATE_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
53 createOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
55 addParameter( createOptsParam.release() );
62 mInputRaster = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT" ), context );
67 mBand = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
68 if ( mBand < 1 || mBand > mInputRaster->bandCount() )
69 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand ).arg( mInputRaster->bandCount() ) );
71 mInterface.reset( mInputRaster->dataProvider()->clone() );
72 mExtent = mInputRaster->extent();
73 mLayerWidth = mInputRaster->width();
74 mLayerHeight = mInputRaster->height();
75 mCrs = mInputRaster->crs();
76 mNbCellsXProvider = mInterface->xSize();
77 mNbCellsYProvider = mInterface->ySize();
80 prepareAlgorithmFuzzificationParameters( parameters, context, feedback );
87 const QString createOptions = parameterAsString( parameters, QStringLiteral(
"CREATE_OPTIONS" ), context ).trimmed();
88 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
89 const QFileInfo fi( outputFile );
92 std::unique_ptr<QgsRasterFileWriter> writer = std::make_unique<QgsRasterFileWriter>( outputFile );
93 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
94 if ( !createOptions.isEmpty() )
96 writer->setCreateOptions( createOptions.split(
'|' ) );
98 writer->setOutputFormat( outputFormat );
99 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mDataType, mNbCellsXProvider, mNbCellsYProvider, mExtent, mCrs ) );
102 if ( !provider->isValid() )
105 provider->setNoDataValue( 1, mNoDataValue );
106 provider->setEditable(
true );
107 const qgssize layerSize =
static_cast<qgssize>( mLayerWidth ) *
static_cast<qgssize>( mLayerHeight );
109 fuzzify( provider.get(), feedback );
111 provider->setEditable(
false );
114 outputs.insert( QStringLiteral(
"EXTENT" ), mExtent.toString() );
115 outputs.insert( QStringLiteral(
"CRS_AUTHID" ), mCrs.authid() );
116 outputs.insert( QStringLiteral(
"WIDTH_IN_PIXELS" ), mLayerWidth );
117 outputs.insert( QStringLiteral(
"HEIGHT_IN_PIXELS" ), mLayerHeight );
118 outputs.insert( QStringLiteral(
"TOTAL_PIXEL_COUNT" ), layerSize );
119 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
128QString QgsFuzzifyRasterLinearMembershipAlgorithm::name()
const
130 return QStringLiteral(
"fuzzifyrasterlinearmembership" );
133QString QgsFuzzifyRasterLinearMembershipAlgorithm::displayName()
const
135 return QObject::tr(
"Fuzzify raster (linear membership)" );
138QStringList QgsFuzzifyRasterLinearMembershipAlgorithm::tags()
const
140 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,linear,membership" ).split(
',' );
144QString QgsFuzzifyRasterLinearMembershipAlgorithm::shortHelpString()
const
146 return QObject::tr(
"The Fuzzify raster (linear membership) algorithm transforms an input raster "
147 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
148 "linear fuzzy membership function. The value of 0 implies no membership with the "
149 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
150 "of membership of raster values follows a linear membership function.\n\n"
151 "The linear function is constructed using two user-defined input raster values "
152 "which set the point of full membership (high bound, results to 1) and no membership "
153 "(low bound, results to 0) respectively. The fuzzy set in between those values is defined as a "
154 "linear function.\n\n"
155 "Both increasing and decreasing fuzzy sets can be modeled by "
156 "swapping the high and low bound parameters." );
159QgsFuzzifyRasterLinearMembershipAlgorithm *QgsFuzzifyRasterLinearMembershipAlgorithm::createInstance()
const
161 return new QgsFuzzifyRasterLinearMembershipAlgorithm();
164void QgsFuzzifyRasterLinearMembershipAlgorithm::addAlgorithmParams()
173 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
174 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
182 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
183 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
184 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
187 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
192 bool isNoData =
false;
193 std::unique_ptr<QgsRasterBlock> rasterBlock;
194 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
197 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
198 std::unique_ptr<QgsRasterBlock> fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
200 for (
int row = 0; row < iterRows; row++ )
204 for (
int column = 0; column < iterCols; column++ )
209 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
210 double fuzzifiedValue;
214 fuzzifiedValue = mNoDataValue;
216 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
218 if ( value <= mFuzzifyLowBound )
220 else if ( value >= mFuzzifyHighBound )
223 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
225 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
227 if ( value >= mFuzzifyLowBound )
229 else if ( value <= mFuzzifyHighBound )
232 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
236 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
239 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
242 destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
251QString QgsFuzzifyRasterPowerMembershipAlgorithm::name()
const
253 return QStringLiteral(
"fuzzifyrasterpowermembership" );
256QString QgsFuzzifyRasterPowerMembershipAlgorithm::displayName()
const
258 return QObject::tr(
"Fuzzify raster (power membership)" );
261QStringList QgsFuzzifyRasterPowerMembershipAlgorithm::tags()
const
263 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,power,non-linear,membership,exponent" ).split(
',' );
267QString QgsFuzzifyRasterPowerMembershipAlgorithm::shortHelpString()
const
269 return QObject::tr(
"The Fuzzify raster (power membership) algorithm transforms an input raster "
270 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
271 "power function. The value of 0 implies no membership with the "
272 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
273 "of membership of raster values follows a power function.\n\n"
274 "The power function is constructed using three user-defined input raster values "
275 "which set the point of full membership (high bound, results to 1), no membership "
276 "(low bound, results to 0) and function exponent (only positive) respectively. "
277 "The fuzzy set in between those the upper and lower bounds values is then defined as "
278 "a power function.\n\n"
279 "Both increasing and decreasing fuzzy sets can be modeled by "
280 "swapping the high and low bound parameters." );
283QgsFuzzifyRasterPowerMembershipAlgorithm *QgsFuzzifyRasterPowerMembershipAlgorithm::createInstance()
const
285 return new QgsFuzzifyRasterPowerMembershipAlgorithm();
288void QgsFuzzifyRasterPowerMembershipAlgorithm::addAlgorithmParams()
298 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
299 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
300 mFuzzifyExponent = parameterAsDouble( parameters, QStringLiteral(
"FUZZYEXPONENT" ), context );
308 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
309 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
310 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
313 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
318 bool isNoData =
false;
319 std::unique_ptr<QgsRasterBlock> rasterBlock;
320 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
323 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
324 std::unique_ptr<QgsRasterBlock> fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
326 for (
int row = 0; row < iterRows; row++ )
330 for (
int column = 0; column < iterCols; column++ )
335 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
336 double fuzzifiedValue;
340 fuzzifiedValue = mNoDataValue;
342 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
344 if ( value <= mFuzzifyLowBound )
346 else if ( value >= mFuzzifyHighBound )
349 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
351 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
353 if ( value >= mFuzzifyLowBound )
355 else if ( value <= mFuzzifyHighBound )
358 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
362 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
365 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
368 destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
376QString QgsFuzzifyRasterLargeMembershipAlgorithm::name()
const
378 return QStringLiteral(
"fuzzifyrasterlargemembership" );
381QString QgsFuzzifyRasterLargeMembershipAlgorithm::displayName()
const
383 return QObject::tr(
"Fuzzify raster (large membership)" );
386QStringList QgsFuzzifyRasterLargeMembershipAlgorithm::tags()
const
388 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,large,membership" ).split(
',' );
392QString QgsFuzzifyRasterLargeMembershipAlgorithm::shortHelpString()
const
394 return QObject::tr(
"The Fuzzify raster (large membership) algorithm transforms an input raster "
395 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
396 "'large' fuzzy membership function. The value of 0 implies no membership with the "
397 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
398 "of membership of raster values follows the 'large' membership function.\n\n"
399 "The 'large' function is constructed using two user-defined input raster values "
400 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
401 "function spread which controls the function uptake.\n\n"
402 "This function is typically used when larger input raster values should become members "
403 "of the fuzzy set more easily than smaller values." );
406QgsFuzzifyRasterLargeMembershipAlgorithm *QgsFuzzifyRasterLargeMembershipAlgorithm::createInstance()
const
408 return new QgsFuzzifyRasterLargeMembershipAlgorithm();
411void QgsFuzzifyRasterLargeMembershipAlgorithm::addAlgorithmParams()
420 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
421 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
429 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
430 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
431 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
434 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
439 bool isNoData =
false;
440 std::unique_ptr<QgsRasterBlock> rasterBlock;
441 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
444 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
445 std::unique_ptr<QgsRasterBlock> fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
447 for (
int row = 0; row < iterRows; row++ )
451 for (
int column = 0; column < iterCols; column++ )
456 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
457 double fuzzifiedValue;
461 fuzzifiedValue = mNoDataValue;
465 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, -mFuzzifySpread ) );
468 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
471 destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
480QString QgsFuzzifyRasterSmallMembershipAlgorithm::name()
const
482 return QStringLiteral(
"fuzzifyrastersmallmembership" );
485QString QgsFuzzifyRasterSmallMembershipAlgorithm::displayName()
const
487 return QObject::tr(
"Fuzzify raster (small membership)" );
490QStringList QgsFuzzifyRasterSmallMembershipAlgorithm::tags()
const
492 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,small,membership" ).split(
',' );
496QString QgsFuzzifyRasterSmallMembershipAlgorithm::shortHelpString()
const
498 return QObject::tr(
"The Fuzzify raster (small membership) algorithm transforms an input raster "
499 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
500 "'small' fuzzy membership function. The value of 0 implies no membership with the "
501 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
502 "of membership of raster values follows the 'small' membership function.\n\n"
503 "The 'small' function is constructed using two user-defined input raster values "
504 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
505 "function spread which controls the function uptake.\n\n"
506 "This function is typically used when smaller input raster values should become members "
507 "of the fuzzy set more easily than higher values." );
510QgsFuzzifyRasterSmallMembershipAlgorithm *QgsFuzzifyRasterSmallMembershipAlgorithm::createInstance()
const
512 return new QgsFuzzifyRasterSmallMembershipAlgorithm();
515void QgsFuzzifyRasterSmallMembershipAlgorithm::addAlgorithmParams()
524 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
525 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
533 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
534 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
535 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
538 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
543 bool isNoData =
false;
544 std::unique_ptr<QgsRasterBlock> rasterBlock;
545 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
548 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
549 std::unique_ptr<QgsRasterBlock> fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
551 for (
int row = 0; row < iterRows; row++ )
555 for (
int column = 0; column < iterCols; column++ )
560 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
561 double fuzzifiedValue;
565 fuzzifiedValue = mNoDataValue;
569 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, mFuzzifySpread ) );
572 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
575 destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
584QString QgsFuzzifyRasterGaussianMembershipAlgorithm::name()
const
586 return QStringLiteral(
"fuzzifyrastergaussianmembership" );
589QString QgsFuzzifyRasterGaussianMembershipAlgorithm::displayName()
const
591 return QObject::tr(
"Fuzzify raster (gaussian membership)" );
594QStringList QgsFuzzifyRasterGaussianMembershipAlgorithm::tags()
const
596 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,gaussian,membership" ).split(
',' );
600QString QgsFuzzifyRasterGaussianMembershipAlgorithm::shortHelpString()
const
602 return QObject::tr(
"The Fuzzify raster (gaussian membership) algorithm transforms an input raster "
603 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
604 "gaussian fuzzy membership function. The value of 0 implies no membership with the "
605 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
606 "of membership of raster values follows a gaussian membership function.\n\n"
607 "The gaussian function is constructed using two user-defined input values "
608 "which set the midpoint of the gaussian function (midpoint, results to 1) and a "
609 "predefined function spread which controls the function spread.\n\n"
610 "This function is typically used when a certain range of raster values around a "
611 "predefined function midpoint should become members of the fuzzy set." );
614QgsFuzzifyRasterGaussianMembershipAlgorithm *QgsFuzzifyRasterGaussianMembershipAlgorithm::createInstance()
const
616 return new QgsFuzzifyRasterGaussianMembershipAlgorithm();
619void QgsFuzzifyRasterGaussianMembershipAlgorithm::addAlgorithmParams()
628 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
629 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
637 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
638 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
639 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
642 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
647 bool isNoData =
false;
648 std::unique_ptr<QgsRasterBlock> rasterBlock;
649 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
652 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
653 std::unique_ptr<QgsRasterBlock> fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
655 for (
int row = 0; row < iterRows; row++ )
659 for (
int column = 0; column < iterCols; column++ )
664 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
665 double fuzzifiedValue;
669 fuzzifiedValue = mNoDataValue;
673 fuzzifiedValue = std::exp( -mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
676 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
679 destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
688QString QgsFuzzifyRasterNearMembershipAlgorithm::name()
const
690 return QStringLiteral(
"fuzzifyrasternearmembership" );
693QString QgsFuzzifyRasterNearMembershipAlgorithm::displayName()
const
695 return QObject::tr(
"Fuzzify raster (near membership)" );
698QStringList QgsFuzzifyRasterNearMembershipAlgorithm::tags()
const
700 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,near,membership" ).split(
',' );
704QString QgsFuzzifyRasterNearMembershipAlgorithm::shortHelpString()
const
706 return QObject::tr(
"The Fuzzify raster (near membership) algorithm transforms an input raster "
707 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
708 "'near' fuzzy membership function. The value of 0 implies no membership with the "
709 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
710 "of membership of raster values follows the 'near' membership function.\n\n"
711 "The 'near' function is constructed using two user-defined input values "
712 "which set the midpoint of the 'near' function (midpoint, results to 1) and a "
713 "predefined function spread which controls the function spread.\n\n"
714 "This function is typically used when a certain range of raster values near a "
715 "predefined function midpoint should become members of the fuzzy set. The function"
716 " generally shows a higher rate of decay than the gaussian membership function." );
719QgsFuzzifyRasterNearMembershipAlgorithm *QgsFuzzifyRasterNearMembershipAlgorithm::createInstance()
const
721 return new QgsFuzzifyRasterNearMembershipAlgorithm();
724void QgsFuzzifyRasterNearMembershipAlgorithm::addAlgorithmParams()
733 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
734 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
742 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
743 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
744 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
747 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
752 bool isNoData =
false;
753 std::unique_ptr<QgsRasterBlock> rasterBlock;
754 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
757 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
758 std::unique_ptr<QgsRasterBlock> fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
760 for (
int row = 0; row < iterRows; row++ )
764 for (
int column = 0; column < iterCols; column++ )
769 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
770 double fuzzifiedValue;
774 fuzzifiedValue = mNoDataValue;
778 fuzzifiedValue = 1 / ( 1 + mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
781 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
784 destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
@ 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 numeric output for processing algorithms.
A string output for processing algorithms.
A raster band 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 ...
A raster layer parameter for processing algorithms.
Base class for raster data providers.
bool writeBlock(QgsRasterBlock *block, int band, int xOffset=0, int yOffset=0)
Writes pixel data from a raster block into the provider data source.
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
Iterator for sequentially processing raster cells.
static const int DEFAULT_MAXIMUM_TILE_WIDTH
Default maximum tile width.
static const int DEFAULT_MAXIMUM_TILE_HEIGHT
Default maximum tile height.
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...