28 QString QgsFuzzifyRasterAlgorithmBase::group()
const
30 return QObject::tr(
"Raster analysis" );
33 QString QgsFuzzifyRasterAlgorithmBase::groupId()
const
35 return QStringLiteral(
"rasteranalysis" );
38 void QgsFuzzifyRasterAlgorithmBase::initAlgorithm(
const QVariantMap & )
41 addParameter(
new QgsProcessingParameterBand( QStringLiteral(
"BAND" ), QObject::tr(
"Band Number" ), 1, QStringLiteral(
"INPUT" ) ) );
57 mInputRaster = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT" ), context );
62 mBand = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
63 if ( mBand < 1 || mBand > mInputRaster->bandCount() )
64 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand ).arg( mInputRaster->bandCount() ) );
66 mInterface.reset( mInputRaster->dataProvider()->clone() );
67 mExtent = mInputRaster->extent();
68 mLayerWidth = mInputRaster->width();
69 mLayerHeight = mInputRaster->height();
70 mCrs = mInputRaster->crs();
71 mNbCellsXProvider = mInterface->xSize();
72 mNbCellsYProvider = mInterface->ySize();
75 prepareAlgorithmFuzzificationParameters( parameters, context, feedback );
83 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
84 const QFileInfo fi( outputFile );
87 std::unique_ptr< QgsRasterFileWriter > writer = std::make_unique< QgsRasterFileWriter >( outputFile );
88 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
89 writer->setOutputFormat( outputFormat );
90 std::unique_ptr<QgsRasterDataProvider > provider( writer->createOneBandRaster( mDataType, mNbCellsXProvider, mNbCellsYProvider, mExtent, mCrs ) );
93 if ( !provider->isValid() )
96 provider->setNoDataValue( 1, mNoDataValue );
97 mDestinationRasterProvider = provider.get();
98 mDestinationRasterProvider->setEditable(
true );
99 const qgssize layerSize =
static_cast< qgssize >( mLayerWidth ) *
static_cast< qgssize >( mLayerHeight );
104 outputs.insert( QStringLiteral(
"EXTENT" ), mExtent.toString() );
105 outputs.insert( QStringLiteral(
"CRS_AUTHID" ), mCrs.authid() );
106 outputs.insert( QStringLiteral(
"WIDTH_IN_PIXELS" ), mLayerWidth );
107 outputs.insert( QStringLiteral(
"HEIGHT_IN_PIXELS" ), mLayerHeight );
108 outputs.insert( QStringLiteral(
"TOTAL_PIXEL_COUNT" ), layerSize );
109 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
118 QString QgsFuzzifyRasterLinearMembershipAlgorithm::name()
const
120 return QStringLiteral(
"fuzzifyrasterlinearmembership" );
123 QString QgsFuzzifyRasterLinearMembershipAlgorithm::displayName()
const
125 return QObject::tr(
"Fuzzify raster (linear membership)" );
128 QStringList QgsFuzzifyRasterLinearMembershipAlgorithm::tags()
const
130 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,linear,membership" ).split(
',' );
134 QString QgsFuzzifyRasterLinearMembershipAlgorithm::shortHelpString()
const
136 return QObject::tr(
"The Fuzzify raster (linear membership) algorithm transforms an input raster "
137 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
138 "linear fuzzy membership function. The value of 0 implies no membership with the "
139 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
140 "of membership of raster values follows a linear membership function.\n\n"
141 "The linear function is constructed using two user-defined input raster values "
142 "which set the point of full membership (high bound, results to 1) and no membership "
143 "(low bound, results to 0) respectively. The fuzzy set in between those values is defined as a "
144 "linear function.\n\n"
145 "Both increasing and decreasing fuzzy sets can be modeled by "
146 "swapping the high and low bound parameters." );
149 QgsFuzzifyRasterLinearMembershipAlgorithm *QgsFuzzifyRasterLinearMembershipAlgorithm::createInstance()
const
151 return new QgsFuzzifyRasterLinearMembershipAlgorithm();
154 void QgsFuzzifyRasterLinearMembershipAlgorithm::addAlgorithmParams( )
163 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
164 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
172 const int nbBlocksWidth =
static_cast< int >( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
173 const int nbBlocksHeight =
static_cast< int >( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
174 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
177 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
182 bool isNoData =
false;
183 std::unique_ptr< QgsRasterBlock > rasterBlock;
184 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
187 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
188 std::unique_ptr< QgsRasterBlock > fuzzifiedBlock = std::make_unique< QgsRasterBlock >( mDestinationRasterProvider->dataType( 1 ), iterCols, iterRows );
190 for (
int row = 0; row < iterRows; row++ )
194 for (
int column = 0; column < iterCols; column++ )
199 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
200 double fuzzifiedValue;
204 fuzzifiedValue = mNoDataValue;
206 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
208 if ( value <= mFuzzifyLowBound )
210 else if ( value >= mFuzzifyHighBound )
213 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
215 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
217 if ( value >= mFuzzifyLowBound )
219 else if ( value <= mFuzzifyHighBound )
222 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
226 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
229 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
232 mDestinationRasterProvider->writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
234 mDestinationRasterProvider->setEditable(
false );
242 QString QgsFuzzifyRasterPowerMembershipAlgorithm::name()
const
244 return QStringLiteral(
"fuzzifyrasterpowermembership" );
247 QString QgsFuzzifyRasterPowerMembershipAlgorithm::displayName()
const
249 return QObject::tr(
"Fuzzify raster (power membership)" );
252 QStringList QgsFuzzifyRasterPowerMembershipAlgorithm::tags()
const
254 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,power,non-linear,membership,exponent" ).split(
',' );
258 QString QgsFuzzifyRasterPowerMembershipAlgorithm::shortHelpString()
const
260 return QObject::tr(
"The Fuzzify raster (power membership) algorithm transforms an input raster "
261 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
262 "power function. The value of 0 implies no membership with the "
263 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
264 "of membership of raster values follows a power function.\n\n"
265 "The power function is constructed using three user-defined input raster values "
266 "which set the point of full membership (high bound, results to 1), no membership "
267 "(low bound, results to 0) and function exponent (only positive) respectively. "
268 "The fuzzy set in between those the upper and lower bounds values is then defined as "
269 "a power function.\n\n"
270 "Both increasing and decreasing fuzzy sets can be modeled by "
271 "swapping the high and low bound parameters." );
274 QgsFuzzifyRasterPowerMembershipAlgorithm *QgsFuzzifyRasterPowerMembershipAlgorithm::createInstance()
const
276 return new QgsFuzzifyRasterPowerMembershipAlgorithm();
279 void QgsFuzzifyRasterPowerMembershipAlgorithm::addAlgorithmParams( )
289 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
290 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
291 mFuzzifyExponent = parameterAsDouble( parameters, QStringLiteral(
"FUZZYEXPONENT" ), context );
299 const int nbBlocksWidth =
static_cast< int >( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
300 const int nbBlocksHeight =
static_cast< int >( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
301 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
304 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
309 bool isNoData =
false;
310 std::unique_ptr< QgsRasterBlock > rasterBlock;
311 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
314 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
315 std::unique_ptr< QgsRasterBlock > fuzzifiedBlock = std::make_unique< QgsRasterBlock >( mDestinationRasterProvider->dataType( 1 ), iterCols, iterRows );
317 for (
int row = 0; row < iterRows; row++ )
321 for (
int column = 0; column < iterCols; column++ )
326 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
327 double fuzzifiedValue;
331 fuzzifiedValue = mNoDataValue;
333 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
335 if ( value <= mFuzzifyLowBound )
337 else if ( value >= mFuzzifyHighBound )
340 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
342 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
344 if ( value >= mFuzzifyLowBound )
346 else if ( value <= mFuzzifyHighBound )
349 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
353 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
356 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
359 mDestinationRasterProvider->writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
361 mDestinationRasterProvider->setEditable(
false );
368 QString QgsFuzzifyRasterLargeMembershipAlgorithm::name()
const
370 return QStringLiteral(
"fuzzifyrasterlargemembership" );
373 QString QgsFuzzifyRasterLargeMembershipAlgorithm::displayName()
const
375 return QObject::tr(
"Fuzzify raster (large membership)" );
378 QStringList QgsFuzzifyRasterLargeMembershipAlgorithm::tags()
const
380 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,large,membership" ).split(
',' );
384 QString QgsFuzzifyRasterLargeMembershipAlgorithm::shortHelpString()
const
386 return QObject::tr(
"The Fuzzify raster (large membership) algorithm transforms an input raster "
387 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
388 "'large' fuzzy membership function. The value of 0 implies no membership with the "
389 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
390 "of membership of raster values follows the 'large' membership function.\n\n"
391 "The 'large' function is constructed using two user-defined input raster values "
392 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
393 "function spread which controls the function uptake.\n\n"
394 "This function is typically used when larger input raster values should become members "
395 "of the fuzzy set more easily than smaller values." );
398 QgsFuzzifyRasterLargeMembershipAlgorithm *QgsFuzzifyRasterLargeMembershipAlgorithm::createInstance()
const
400 return new QgsFuzzifyRasterLargeMembershipAlgorithm();
403 void QgsFuzzifyRasterLargeMembershipAlgorithm::addAlgorithmParams( )
412 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
413 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
421 const int nbBlocksWidth =
static_cast< int >( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
422 const int nbBlocksHeight =
static_cast< int >( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
423 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
426 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
431 bool isNoData =
false;
432 std::unique_ptr< QgsRasterBlock > rasterBlock;
433 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
436 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
437 std::unique_ptr< QgsRasterBlock > fuzzifiedBlock = std::make_unique< QgsRasterBlock >( mDestinationRasterProvider->dataType( 1 ), iterCols, iterRows );
439 for (
int row = 0; row < iterRows; row++ )
443 for (
int column = 0; column < iterCols; column++ )
448 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
449 double fuzzifiedValue;
453 fuzzifiedValue = mNoDataValue;
457 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, -mFuzzifySpread ) );
460 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
463 mDestinationRasterProvider->writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
465 mDestinationRasterProvider->setEditable(
false );
473 QString QgsFuzzifyRasterSmallMembershipAlgorithm::name()
const
475 return QStringLiteral(
"fuzzifyrastersmallmembership" );
478 QString QgsFuzzifyRasterSmallMembershipAlgorithm::displayName()
const
480 return QObject::tr(
"Fuzzify raster (small membership)" );
483 QStringList QgsFuzzifyRasterSmallMembershipAlgorithm::tags()
const
485 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,small,membership" ).split(
',' );
489 QString QgsFuzzifyRasterSmallMembershipAlgorithm::shortHelpString()
const
491 return QObject::tr(
"The Fuzzify raster (small membership) algorithm transforms an input raster "
492 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
493 "'small' fuzzy membership function. The value of 0 implies no membership with the "
494 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
495 "of membership of raster values follows the 'small' membership function.\n\n"
496 "The 'small' function is constructed using two user-defined input raster values "
497 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
498 "function spread which controls the function uptake.\n\n"
499 "This function is typically used when smaller input raster values should become members "
500 "of the fuzzy set more easily than higher values." );
503 QgsFuzzifyRasterSmallMembershipAlgorithm *QgsFuzzifyRasterSmallMembershipAlgorithm::createInstance()
const
505 return new QgsFuzzifyRasterSmallMembershipAlgorithm();
508 void QgsFuzzifyRasterSmallMembershipAlgorithm::addAlgorithmParams( )
517 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
518 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
526 const int nbBlocksWidth =
static_cast< int >( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
527 const int nbBlocksHeight =
static_cast< int >( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
528 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
531 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
536 bool isNoData =
false;
537 std::unique_ptr< QgsRasterBlock > rasterBlock;
538 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
541 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
542 std::unique_ptr< QgsRasterBlock > fuzzifiedBlock = std::make_unique< QgsRasterBlock >( mDestinationRasterProvider->dataType( 1 ), iterCols, iterRows );
544 for (
int row = 0; row < iterRows; row++ )
548 for (
int column = 0; column < iterCols; column++ )
553 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
554 double fuzzifiedValue;
558 fuzzifiedValue = mNoDataValue;
562 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, mFuzzifySpread ) );
565 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
568 mDestinationRasterProvider->writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
570 mDestinationRasterProvider->setEditable(
false );
578 QString QgsFuzzifyRasterGaussianMembershipAlgorithm::name()
const
580 return QStringLiteral(
"fuzzifyrastergaussianmembership" );
583 QString QgsFuzzifyRasterGaussianMembershipAlgorithm::displayName()
const
585 return QObject::tr(
"Fuzzify raster (gaussian membership)" );
588 QStringList QgsFuzzifyRasterGaussianMembershipAlgorithm::tags()
const
590 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,gaussian,membership" ).split(
',' );
594 QString QgsFuzzifyRasterGaussianMembershipAlgorithm::shortHelpString()
const
596 return QObject::tr(
"The Fuzzify raster (gaussian membership) algorithm transforms an input raster "
597 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
598 "gaussian fuzzy membership function. The value of 0 implies no membership with the "
599 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
600 "of membership of raster values follows a gaussian membership function.\n\n"
601 "The gaussian function is constructed using two user-defined input values "
602 "which set the midpoint of the gaussian function (midpoint, results to 1) and a "
603 "predefined function spread which controls the function spread.\n\n"
604 "This function is typically used when a certain range of raster values around a "
605 "predefined function midpoint should become members of the fuzzy set." );
608 QgsFuzzifyRasterGaussianMembershipAlgorithm *QgsFuzzifyRasterGaussianMembershipAlgorithm::createInstance()
const
610 return new QgsFuzzifyRasterGaussianMembershipAlgorithm();
613 void QgsFuzzifyRasterGaussianMembershipAlgorithm::addAlgorithmParams( )
622 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
623 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
631 const int nbBlocksWidth =
static_cast< int >( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
632 const int nbBlocksHeight =
static_cast< int >( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
633 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
636 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
641 bool isNoData =
false;
642 std::unique_ptr< QgsRasterBlock > rasterBlock;
643 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
646 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
647 std::unique_ptr< QgsRasterBlock > fuzzifiedBlock = std::make_unique< QgsRasterBlock >( mDestinationRasterProvider->dataType( 1 ), iterCols, iterRows );
649 for (
int row = 0; row < iterRows; row++ )
653 for (
int column = 0; column < iterCols; column++ )
658 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
659 double fuzzifiedValue;
663 fuzzifiedValue = mNoDataValue;
667 fuzzifiedValue = std::exp( -mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
670 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
673 mDestinationRasterProvider->writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
675 mDestinationRasterProvider->setEditable(
false );
683 QString QgsFuzzifyRasterNearMembershipAlgorithm::name()
const
685 return QStringLiteral(
"fuzzifyrasternearmembership" );
688 QString QgsFuzzifyRasterNearMembershipAlgorithm::displayName()
const
690 return QObject::tr(
"Fuzzify raster (near membership)" );
693 QStringList QgsFuzzifyRasterNearMembershipAlgorithm::tags()
const
695 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,near,membership" ).split(
',' );
699 QString QgsFuzzifyRasterNearMembershipAlgorithm::shortHelpString()
const
701 return QObject::tr(
"The Fuzzify raster (near membership) algorithm transforms an input raster "
702 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
703 "'near' fuzzy membership function. The value of 0 implies no membership with the "
704 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
705 "of membership of raster values follows the 'near' membership function.\n\n"
706 "The 'near' function is constructed using two user-defined input values "
707 "which set the midpoint of the 'near' function (midpoint, results to 1) and a "
708 "predefined function spread which controls the function spread.\n\n"
709 "This function is typically used when a certain range of raster values near a "
710 "predefined function midpoint should become members of the fuzzy set. The function"
711 " generally shows a higher rate of decay than the gaussian membership function." );
714 QgsFuzzifyRasterNearMembershipAlgorithm *QgsFuzzifyRasterNearMembershipAlgorithm::createInstance()
const
716 return new QgsFuzzifyRasterNearMembershipAlgorithm();
719 void QgsFuzzifyRasterNearMembershipAlgorithm::addAlgorithmParams( )
728 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
729 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
737 const int nbBlocksWidth =
static_cast< int >( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
738 const int nbBlocksHeight =
static_cast< int >( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
739 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
742 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
747 bool isNoData =
false;
748 std::unique_ptr< QgsRasterBlock > rasterBlock;
749 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
752 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
753 std::unique_ptr< QgsRasterBlock > fuzzifiedBlock = std::make_unique< QgsRasterBlock >( mDestinationRasterProvider->dataType( 1 ), iterCols, iterRows );
755 for (
int row = 0; row < iterRows; row++ )
759 for (
int column = 0; column < iterCols; column++ )
764 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
765 double fuzzifiedValue;
769 fuzzifiedValue = mNoDataValue;
773 fuzzifiedValue = 1 / ( 1 + mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
776 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
779 mDestinationRasterProvider->writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop );
781 mDestinationRasterProvider->setEditable(
false );
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A numeric output for processing algorithms.
A string output for processing algorithms.
A raster band parameter for Processing algorithms.
A numeric parameter for processing algorithms.
@ Double
Double/float values.
A raster layer destination parameter, for specifying the destination path for a raster layer created ...
A raster layer parameter for processing algorithms.
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...