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 auto 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 auto 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 auto 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 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
254QString QgsFuzzifyRasterPowerMembershipAlgorithm::name()
const
256 return QStringLiteral(
"fuzzifyrasterpowermembership" );
259QString QgsFuzzifyRasterPowerMembershipAlgorithm::displayName()
const
261 return QObject::tr(
"Fuzzify raster (power membership)" );
264QStringList QgsFuzzifyRasterPowerMembershipAlgorithm::tags()
const
266 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,power,non-linear,membership,exponent" ).split(
',' );
270QString QgsFuzzifyRasterPowerMembershipAlgorithm::shortHelpString()
const
272 return QObject::tr(
"The Fuzzify raster (power membership) algorithm transforms an input raster "
273 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
274 "power function. The value of 0 implies no membership with the "
275 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
276 "of membership of raster values follows a power function.\n\n"
277 "The power function is constructed using three user-defined input raster values "
278 "which set the point of full membership (high bound, results to 1), no membership "
279 "(low bound, results to 0) and function exponent (only positive) respectively. "
280 "The fuzzy set in between those the upper and lower bounds values is then defined as "
281 "a power function.\n\n"
282 "Both increasing and decreasing fuzzy sets can be modeled by "
283 "swapping the high and low bound parameters." );
286QgsFuzzifyRasterPowerMembershipAlgorithm *QgsFuzzifyRasterPowerMembershipAlgorithm::createInstance()
const
288 return new QgsFuzzifyRasterPowerMembershipAlgorithm();
291void QgsFuzzifyRasterPowerMembershipAlgorithm::addAlgorithmParams()
301 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
302 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
303 mFuzzifyExponent = parameterAsDouble( parameters, QStringLiteral(
"FUZZYEXPONENT" ), context );
311 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
312 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
313 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
316 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
321 bool isNoData =
false;
322 std::unique_ptr<QgsRasterBlock> rasterBlock;
323 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
326 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
327 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
329 for (
int row = 0; row < iterRows; row++ )
333 for (
int column = 0; column < iterCols; column++ )
338 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
339 double fuzzifiedValue;
343 fuzzifiedValue = mNoDataValue;
345 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
347 if ( value <= mFuzzifyLowBound )
349 else if ( value >= mFuzzifyHighBound )
352 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
354 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
356 if ( value >= mFuzzifyLowBound )
358 else if ( value <= mFuzzifyHighBound )
361 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
365 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
368 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
371 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
382QString QgsFuzzifyRasterLargeMembershipAlgorithm::name()
const
384 return QStringLiteral(
"fuzzifyrasterlargemembership" );
387QString QgsFuzzifyRasterLargeMembershipAlgorithm::displayName()
const
389 return QObject::tr(
"Fuzzify raster (large membership)" );
392QStringList QgsFuzzifyRasterLargeMembershipAlgorithm::tags()
const
394 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,large,membership" ).split(
',' );
398QString QgsFuzzifyRasterLargeMembershipAlgorithm::shortHelpString()
const
400 return QObject::tr(
"The Fuzzify raster (large membership) algorithm transforms an input raster "
401 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
402 "'large' fuzzy membership function. The value of 0 implies no membership with the "
403 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
404 "of membership of raster values follows the 'large' membership function.\n\n"
405 "The 'large' function is constructed using two user-defined input raster values "
406 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
407 "function spread which controls the function uptake.\n\n"
408 "This function is typically used when larger input raster values should become members "
409 "of the fuzzy set more easily than smaller values." );
412QgsFuzzifyRasterLargeMembershipAlgorithm *QgsFuzzifyRasterLargeMembershipAlgorithm::createInstance()
const
414 return new QgsFuzzifyRasterLargeMembershipAlgorithm();
417void QgsFuzzifyRasterLargeMembershipAlgorithm::addAlgorithmParams()
426 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
427 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
435 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
436 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
437 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
440 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
445 bool isNoData =
false;
446 std::unique_ptr<QgsRasterBlock> rasterBlock;
447 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
450 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
451 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
453 for (
int row = 0; row < iterRows; row++ )
457 for (
int column = 0; column < iterCols; column++ )
462 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
463 double fuzzifiedValue;
467 fuzzifiedValue = mNoDataValue;
471 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, -mFuzzifySpread ) );
474 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
477 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
489QString QgsFuzzifyRasterSmallMembershipAlgorithm::name()
const
491 return QStringLiteral(
"fuzzifyrastersmallmembership" );
494QString QgsFuzzifyRasterSmallMembershipAlgorithm::displayName()
const
496 return QObject::tr(
"Fuzzify raster (small membership)" );
499QStringList QgsFuzzifyRasterSmallMembershipAlgorithm::tags()
const
501 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,small,membership" ).split(
',' );
505QString QgsFuzzifyRasterSmallMembershipAlgorithm::shortHelpString()
const
507 return QObject::tr(
"The Fuzzify raster (small membership) algorithm transforms an input raster "
508 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
509 "'small' fuzzy membership function. The value of 0 implies no membership with the "
510 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
511 "of membership of raster values follows the 'small' membership function.\n\n"
512 "The 'small' function is constructed using two user-defined input raster values "
513 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
514 "function spread which controls the function uptake.\n\n"
515 "This function is typically used when smaller input raster values should become members "
516 "of the fuzzy set more easily than higher values." );
519QgsFuzzifyRasterSmallMembershipAlgorithm *QgsFuzzifyRasterSmallMembershipAlgorithm::createInstance()
const
521 return new QgsFuzzifyRasterSmallMembershipAlgorithm();
524void QgsFuzzifyRasterSmallMembershipAlgorithm::addAlgorithmParams()
533 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
534 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
542 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
543 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
544 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
547 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
552 bool isNoData =
false;
553 std::unique_ptr<QgsRasterBlock> rasterBlock;
554 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
557 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
558 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
560 for (
int row = 0; row < iterRows; row++ )
564 for (
int column = 0; column < iterCols; column++ )
569 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
570 double fuzzifiedValue;
574 fuzzifiedValue = mNoDataValue;
578 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, mFuzzifySpread ) );
581 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
584 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
596QString QgsFuzzifyRasterGaussianMembershipAlgorithm::name()
const
598 return QStringLiteral(
"fuzzifyrastergaussianmembership" );
601QString QgsFuzzifyRasterGaussianMembershipAlgorithm::displayName()
const
603 return QObject::tr(
"Fuzzify raster (gaussian membership)" );
606QStringList QgsFuzzifyRasterGaussianMembershipAlgorithm::tags()
const
608 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,gaussian,membership" ).split(
',' );
612QString QgsFuzzifyRasterGaussianMembershipAlgorithm::shortHelpString()
const
614 return QObject::tr(
"The Fuzzify raster (gaussian membership) algorithm transforms an input raster "
615 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
616 "gaussian fuzzy membership function. The value of 0 implies no membership with the "
617 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
618 "of membership of raster values follows a gaussian membership function.\n\n"
619 "The gaussian function is constructed using two user-defined input values "
620 "which set the midpoint of the gaussian function (midpoint, results to 1) and a "
621 "predefined function spread which controls the function spread.\n\n"
622 "This function is typically used when a certain range of raster values around a "
623 "predefined function midpoint should become members of the fuzzy set." );
626QgsFuzzifyRasterGaussianMembershipAlgorithm *QgsFuzzifyRasterGaussianMembershipAlgorithm::createInstance()
const
628 return new QgsFuzzifyRasterGaussianMembershipAlgorithm();
631void QgsFuzzifyRasterGaussianMembershipAlgorithm::addAlgorithmParams()
640 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
641 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
649 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
650 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
651 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
654 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
659 bool isNoData =
false;
660 std::unique_ptr<QgsRasterBlock> rasterBlock;
661 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
664 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
665 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
667 for (
int row = 0; row < iterRows; row++ )
671 for (
int column = 0; column < iterCols; column++ )
676 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
677 double fuzzifiedValue;
681 fuzzifiedValue = mNoDataValue;
685 fuzzifiedValue = std::exp( -mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
688 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
691 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
703QString QgsFuzzifyRasterNearMembershipAlgorithm::name()
const
705 return QStringLiteral(
"fuzzifyrasternearmembership" );
708QString QgsFuzzifyRasterNearMembershipAlgorithm::displayName()
const
710 return QObject::tr(
"Fuzzify raster (near membership)" );
713QStringList QgsFuzzifyRasterNearMembershipAlgorithm::tags()
const
715 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,near,membership" ).split(
',' );
719QString QgsFuzzifyRasterNearMembershipAlgorithm::shortHelpString()
const
721 return QObject::tr(
"The Fuzzify raster (near membership) algorithm transforms an input raster "
722 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
723 "'near' fuzzy membership function. The value of 0 implies no membership with the "
724 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
725 "of membership of raster values follows the 'near' membership function.\n\n"
726 "The 'near' function is constructed using two user-defined input values "
727 "which set the midpoint of the 'near' function (midpoint, results to 1) and a "
728 "predefined function spread which controls the function spread.\n\n"
729 "This function is typically used when a certain range of raster values near a "
730 "predefined function midpoint should become members of the fuzzy set. The function"
731 " generally shows a higher rate of decay than the gaussian membership function." );
734QgsFuzzifyRasterNearMembershipAlgorithm *QgsFuzzifyRasterNearMembershipAlgorithm::createInstance()
const
736 return new QgsFuzzifyRasterNearMembershipAlgorithm();
739void QgsFuzzifyRasterNearMembershipAlgorithm::addAlgorithmParams()
748 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
749 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
757 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
758 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
759 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
762 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
767 bool isNoData =
false;
768 std::unique_ptr<QgsRasterBlock> rasterBlock;
769 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
772 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
773 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
775 for (
int row = 0; row < iterRows; row++ )
779 for (
int column = 0; column < iterCols; column++ )
784 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
785 double fuzzifiedValue;
789 fuzzifiedValue = mNoDataValue;
793 fuzzifiedValue = 1 / ( 1 + mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
796 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
799 if ( !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.
virtual QgsError error() const
Gets current status error.
QString summary() const
Short error description, usually the first error in chain, the real error.
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...