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" ) ) );
54 auto createOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATE_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
55 createOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
57 addParameter( createOptsParam.release() );
59 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATION_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
60 creationOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
62 addParameter( creationOptsParam.release() );
69 mInputRaster = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT" ), context );
74 mBand = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
75 if ( mBand < 1 || mBand > mInputRaster->bandCount() )
76 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand ).arg( mInputRaster->bandCount() ) );
78 mInterface.reset( mInputRaster->dataProvider()->clone() );
79 mExtent = mInputRaster->extent();
80 mLayerWidth = mInputRaster->width();
81 mLayerHeight = mInputRaster->height();
82 mCrs = mInputRaster->crs();
83 mNbCellsXProvider = mInterface->xSize();
84 mNbCellsYProvider = mInterface->ySize();
87 prepareAlgorithmFuzzificationParameters( parameters, context, feedback );
94 QString creationOptions = parameterAsString( parameters, QStringLiteral(
"CREATION_OPTIONS" ), context ).trimmed();
96 const QString optionsString = parameterAsString( parameters, QStringLiteral(
"CREATE_OPTIONS" ), context );
97 if ( !optionsString.isEmpty() )
98 creationOptions = optionsString;
100 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
101 const QFileInfo fi( outputFile );
104 auto writer = std::make_unique<QgsRasterFileWriter>( outputFile );
105 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
106 if ( !creationOptions.isEmpty() )
108 writer->setCreationOptions( creationOptions.split(
'|' ) );
110 writer->setOutputFormat( outputFormat );
111 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mDataType, mNbCellsXProvider, mNbCellsYProvider, mExtent, mCrs ) );
114 if ( !provider->isValid() )
117 provider->setNoDataValue( 1, mNoDataValue );
118 provider->setEditable(
true );
119 const qgssize layerSize =
static_cast<qgssize>( mLayerWidth ) *
static_cast<qgssize>( mLayerHeight );
121 fuzzify( provider.get(), feedback );
123 provider->setEditable(
false );
126 outputs.insert( QStringLiteral(
"EXTENT" ), mExtent.toString() );
127 outputs.insert( QStringLiteral(
"CRS_AUTHID" ), mCrs.authid() );
128 outputs.insert( QStringLiteral(
"WIDTH_IN_PIXELS" ), mLayerWidth );
129 outputs.insert( QStringLiteral(
"HEIGHT_IN_PIXELS" ), mLayerHeight );
130 outputs.insert( QStringLiteral(
"TOTAL_PIXEL_COUNT" ), layerSize );
131 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
140QString QgsFuzzifyRasterLinearMembershipAlgorithm::name()
const
142 return QStringLiteral(
"fuzzifyrasterlinearmembership" );
145QString QgsFuzzifyRasterLinearMembershipAlgorithm::displayName()
const
147 return QObject::tr(
"Fuzzify raster (linear membership)" );
150QStringList QgsFuzzifyRasterLinearMembershipAlgorithm::tags()
const
152 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,linear,membership" ).split(
',' );
156QString QgsFuzzifyRasterLinearMembershipAlgorithm::shortHelpString()
const
158 return QObject::tr(
"The Fuzzify raster (linear membership) algorithm transforms an input raster "
159 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
160 "linear fuzzy membership function. The value of 0 implies no membership with the "
161 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
162 "of membership of raster values follows a linear membership function.\n\n"
163 "The linear function is constructed using two user-defined input raster values "
164 "which set the point of full membership (high bound, results to 1) and no membership "
165 "(low bound, results to 0) respectively. The fuzzy set in between those values is defined as a "
166 "linear function.\n\n"
167 "Both increasing and decreasing fuzzy sets can be modeled by "
168 "swapping the high and low bound parameters." );
171QgsFuzzifyRasterLinearMembershipAlgorithm *QgsFuzzifyRasterLinearMembershipAlgorithm::createInstance()
const
173 return new QgsFuzzifyRasterLinearMembershipAlgorithm();
176void QgsFuzzifyRasterLinearMembershipAlgorithm::addAlgorithmParams()
185 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
186 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
194 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
195 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
196 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
199 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
204 bool isNoData =
false;
205 std::unique_ptr<QgsRasterBlock> rasterBlock;
206 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
209 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
210 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
212 for (
int row = 0; row < iterRows; row++ )
216 for (
int column = 0; column < iterCols; column++ )
221 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
222 double fuzzifiedValue;
226 fuzzifiedValue = mNoDataValue;
228 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
230 if ( value <= mFuzzifyLowBound )
232 else if ( value >= mFuzzifyHighBound )
235 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
237 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
239 if ( value >= mFuzzifyLowBound )
241 else if ( value <= mFuzzifyHighBound )
244 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
248 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
251 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
254 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
266QString QgsFuzzifyRasterPowerMembershipAlgorithm::name()
const
268 return QStringLiteral(
"fuzzifyrasterpowermembership" );
271QString QgsFuzzifyRasterPowerMembershipAlgorithm::displayName()
const
273 return QObject::tr(
"Fuzzify raster (power membership)" );
276QStringList QgsFuzzifyRasterPowerMembershipAlgorithm::tags()
const
278 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,power,non-linear,membership,exponent" ).split(
',' );
282QString QgsFuzzifyRasterPowerMembershipAlgorithm::shortHelpString()
const
284 return QObject::tr(
"The Fuzzify raster (power membership) algorithm transforms an input raster "
285 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
286 "power function. The value of 0 implies no membership with the "
287 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
288 "of membership of raster values follows a power function.\n\n"
289 "The power function is constructed using three user-defined input raster values "
290 "which set the point of full membership (high bound, results to 1), no membership "
291 "(low bound, results to 0) and function exponent (only positive) respectively. "
292 "The fuzzy set in between those the upper and lower bounds values is then defined as "
293 "a power function.\n\n"
294 "Both increasing and decreasing fuzzy sets can be modeled by "
295 "swapping the high and low bound parameters." );
298QgsFuzzifyRasterPowerMembershipAlgorithm *QgsFuzzifyRasterPowerMembershipAlgorithm::createInstance()
const
300 return new QgsFuzzifyRasterPowerMembershipAlgorithm();
303void QgsFuzzifyRasterPowerMembershipAlgorithm::addAlgorithmParams()
313 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
314 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
315 mFuzzifyExponent = parameterAsDouble( parameters, QStringLiteral(
"FUZZYEXPONENT" ), context );
323 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
324 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
325 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
328 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
333 bool isNoData =
false;
334 std::unique_ptr<QgsRasterBlock> rasterBlock;
335 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
338 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
339 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
341 for (
int row = 0; row < iterRows; row++ )
345 for (
int column = 0; column < iterCols; column++ )
350 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
351 double fuzzifiedValue;
355 fuzzifiedValue = mNoDataValue;
357 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
359 if ( value <= mFuzzifyLowBound )
361 else if ( value >= mFuzzifyHighBound )
364 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
366 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
368 if ( value >= mFuzzifyLowBound )
370 else if ( value <= mFuzzifyHighBound )
373 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
377 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
380 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
383 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
394QString QgsFuzzifyRasterLargeMembershipAlgorithm::name()
const
396 return QStringLiteral(
"fuzzifyrasterlargemembership" );
399QString QgsFuzzifyRasterLargeMembershipAlgorithm::displayName()
const
401 return QObject::tr(
"Fuzzify raster (large membership)" );
404QStringList QgsFuzzifyRasterLargeMembershipAlgorithm::tags()
const
406 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,large,membership" ).split(
',' );
410QString QgsFuzzifyRasterLargeMembershipAlgorithm::shortHelpString()
const
412 return QObject::tr(
"The Fuzzify raster (large membership) algorithm transforms an input raster "
413 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
414 "'large' fuzzy membership function. The value of 0 implies no membership with the "
415 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
416 "of membership of raster values follows the 'large' membership function.\n\n"
417 "The 'large' function is constructed using two user-defined input raster values "
418 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
419 "function spread which controls the function uptake.\n\n"
420 "This function is typically used when larger input raster values should become members "
421 "of the fuzzy set more easily than smaller values." );
424QgsFuzzifyRasterLargeMembershipAlgorithm *QgsFuzzifyRasterLargeMembershipAlgorithm::createInstance()
const
426 return new QgsFuzzifyRasterLargeMembershipAlgorithm();
429void QgsFuzzifyRasterLargeMembershipAlgorithm::addAlgorithmParams()
438 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
439 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
447 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
448 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
449 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
452 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
457 bool isNoData =
false;
458 std::unique_ptr<QgsRasterBlock> rasterBlock;
459 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
462 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
463 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
465 for (
int row = 0; row < iterRows; row++ )
469 for (
int column = 0; column < iterCols; column++ )
474 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
475 double fuzzifiedValue;
479 fuzzifiedValue = mNoDataValue;
483 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, -mFuzzifySpread ) );
486 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
489 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
501QString QgsFuzzifyRasterSmallMembershipAlgorithm::name()
const
503 return QStringLiteral(
"fuzzifyrastersmallmembership" );
506QString QgsFuzzifyRasterSmallMembershipAlgorithm::displayName()
const
508 return QObject::tr(
"Fuzzify raster (small membership)" );
511QStringList QgsFuzzifyRasterSmallMembershipAlgorithm::tags()
const
513 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,small,membership" ).split(
',' );
517QString QgsFuzzifyRasterSmallMembershipAlgorithm::shortHelpString()
const
519 return QObject::tr(
"The Fuzzify raster (small membership) algorithm transforms an input raster "
520 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
521 "'small' fuzzy membership function. The value of 0 implies no membership with the "
522 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
523 "of membership of raster values follows the 'small' membership function.\n\n"
524 "The 'small' function is constructed using two user-defined input raster values "
525 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
526 "function spread which controls the function uptake.\n\n"
527 "This function is typically used when smaller input raster values should become members "
528 "of the fuzzy set more easily than higher values." );
531QgsFuzzifyRasterSmallMembershipAlgorithm *QgsFuzzifyRasterSmallMembershipAlgorithm::createInstance()
const
533 return new QgsFuzzifyRasterSmallMembershipAlgorithm();
536void QgsFuzzifyRasterSmallMembershipAlgorithm::addAlgorithmParams()
545 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
546 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
554 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
555 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
556 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
559 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
564 bool isNoData =
false;
565 std::unique_ptr<QgsRasterBlock> rasterBlock;
566 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
569 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
570 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
572 for (
int row = 0; row < iterRows; row++ )
576 for (
int column = 0; column < iterCols; column++ )
581 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
582 double fuzzifiedValue;
586 fuzzifiedValue = mNoDataValue;
590 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, mFuzzifySpread ) );
593 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
596 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
608QString QgsFuzzifyRasterGaussianMembershipAlgorithm::name()
const
610 return QStringLiteral(
"fuzzifyrastergaussianmembership" );
613QString QgsFuzzifyRasterGaussianMembershipAlgorithm::displayName()
const
615 return QObject::tr(
"Fuzzify raster (gaussian membership)" );
618QStringList QgsFuzzifyRasterGaussianMembershipAlgorithm::tags()
const
620 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,gaussian,membership" ).split(
',' );
624QString QgsFuzzifyRasterGaussianMembershipAlgorithm::shortHelpString()
const
626 return QObject::tr(
"The Fuzzify raster (gaussian membership) algorithm transforms an input raster "
627 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
628 "gaussian fuzzy membership function. The value of 0 implies no membership with the "
629 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
630 "of membership of raster values follows a gaussian membership function.\n\n"
631 "The gaussian function is constructed using two user-defined input values "
632 "which set the midpoint of the gaussian function (midpoint, results to 1) and a "
633 "predefined function spread which controls the function spread.\n\n"
634 "This function is typically used when a certain range of raster values around a "
635 "predefined function midpoint should become members of the fuzzy set." );
638QgsFuzzifyRasterGaussianMembershipAlgorithm *QgsFuzzifyRasterGaussianMembershipAlgorithm::createInstance()
const
640 return new QgsFuzzifyRasterGaussianMembershipAlgorithm();
643void QgsFuzzifyRasterGaussianMembershipAlgorithm::addAlgorithmParams()
652 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
653 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
661 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
662 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
663 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
666 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
671 bool isNoData =
false;
672 std::unique_ptr<QgsRasterBlock> rasterBlock;
673 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
676 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
677 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
679 for (
int row = 0; row < iterRows; row++ )
683 for (
int column = 0; column < iterCols; column++ )
688 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
689 double fuzzifiedValue;
693 fuzzifiedValue = mNoDataValue;
697 fuzzifiedValue = std::exp( -mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
700 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
703 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
715QString QgsFuzzifyRasterNearMembershipAlgorithm::name()
const
717 return QStringLiteral(
"fuzzifyrasternearmembership" );
720QString QgsFuzzifyRasterNearMembershipAlgorithm::displayName()
const
722 return QObject::tr(
"Fuzzify raster (near membership)" );
725QStringList QgsFuzzifyRasterNearMembershipAlgorithm::tags()
const
727 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,near,membership" ).split(
',' );
731QString QgsFuzzifyRasterNearMembershipAlgorithm::shortHelpString()
const
733 return QObject::tr(
"The Fuzzify raster (near membership) algorithm transforms an input raster "
734 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
735 "'near' fuzzy membership function. The value of 0 implies no membership with the "
736 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
737 "of membership of raster values follows the 'near' membership function.\n\n"
738 "The 'near' function is constructed using two user-defined input values "
739 "which set the midpoint of the 'near' function (midpoint, results to 1) and a "
740 "predefined function spread which controls the function spread.\n\n"
741 "This function is typically used when a certain range of raster values near a "
742 "predefined function midpoint should become members of the fuzzy set. The function"
743 " generally shows a higher rate of decay than the gaussian membership function." );
746QgsFuzzifyRasterNearMembershipAlgorithm *QgsFuzzifyRasterNearMembershipAlgorithm::createInstance()
const
748 return new QgsFuzzifyRasterNearMembershipAlgorithm();
751void QgsFuzzifyRasterNearMembershipAlgorithm::addAlgorithmParams()
760 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
761 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
769 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
770 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
771 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
774 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
779 bool isNoData =
false;
780 std::unique_ptr<QgsRasterBlock> rasterBlock;
781 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
784 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
785 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
787 for (
int row = 0; row < iterRows; row++ )
791 for (
int column = 0; column < iterCols; column++ )
796 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
797 double fuzzifiedValue;
801 fuzzifiedValue = mNoDataValue;
805 fuzzifiedValue = 1 / ( 1 + mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
808 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
811 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
@ Hidden
Parameter is hidden and should not be shown to users.
@ 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...