29QString QgsFuzzifyRasterAlgorithmBase::group()
const
31 return QObject::tr(
"Raster analysis" );
34QString QgsFuzzifyRasterAlgorithmBase::groupId()
const
36 return QStringLiteral(
"rasteranalysis" );
39void QgsFuzzifyRasterAlgorithmBase::initAlgorithm(
const QVariantMap & )
42 addParameter(
new QgsProcessingParameterBand( QStringLiteral(
"BAND" ), QObject::tr(
"Band Number" ), 1, QStringLiteral(
"INPUT" ) ) );
55 auto createOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATE_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
56 createOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
58 addParameter( createOptsParam.release() );
60 auto creationOptsParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral(
"CREATION_OPTIONS" ), QObject::tr(
"Creation options" ), QVariant(),
false,
true );
61 creationOptsParam->setMetadata( QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"widget_type" ), QStringLiteral(
"rasteroptions" ) } } ) } } ) );
63 addParameter( creationOptsParam.release() );
70 mInputRaster = parameterAsRasterLayer( parameters, QStringLiteral(
"INPUT" ), context );
75 mBand = parameterAsInt( parameters, QStringLiteral(
"BAND" ), context );
76 if ( mBand < 1 || mBand > mInputRaster->bandCount() )
77 throw QgsProcessingException( QObject::tr(
"Invalid band number for BAND (%1): Valid values for input raster are 1 to %2" ).arg( mBand ).arg( mInputRaster->bandCount() ) );
79 mInterface.reset( mInputRaster->dataProvider()->clone() );
80 mExtent = mInputRaster->extent();
81 mLayerWidth = mInputRaster->width();
82 mLayerHeight = mInputRaster->height();
83 mCrs = mInputRaster->crs();
84 mNbCellsXProvider = mInterface->xSize();
85 mNbCellsYProvider = mInterface->ySize();
88 prepareAlgorithmFuzzificationParameters( parameters, context, feedback );
95 QString creationOptions = parameterAsString( parameters, QStringLiteral(
"CREATION_OPTIONS" ), context ).trimmed();
97 const QString optionsString = parameterAsString( parameters, QStringLiteral(
"CREATE_OPTIONS" ), context );
98 if ( !optionsString.isEmpty() )
99 creationOptions = optionsString;
101 const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral(
"OUTPUT" ), context );
102 const QFileInfo fi( outputFile );
105 auto writer = std::make_unique<QgsRasterFileWriter>( outputFile );
106 writer->setOutputProviderKey( QStringLiteral(
"gdal" ) );
107 if ( !creationOptions.isEmpty() )
109 writer->setCreationOptions( creationOptions.split(
'|' ) );
111 writer->setOutputFormat( outputFormat );
112 std::unique_ptr<QgsRasterDataProvider> provider( writer->createOneBandRaster( mDataType, mNbCellsXProvider, mNbCellsYProvider, mExtent, mCrs ) );
115 if ( !provider->isValid() )
118 provider->setNoDataValue( 1, mNoDataValue );
119 provider->setEditable(
true );
120 const qgssize layerSize =
static_cast<qgssize>( mLayerWidth ) *
static_cast<qgssize>( mLayerHeight );
122 fuzzify( provider.get(), feedback );
124 provider->setEditable(
false );
127 outputs.insert( QStringLiteral(
"EXTENT" ), mExtent.toString() );
128 outputs.insert( QStringLiteral(
"CRS_AUTHID" ), mCrs.authid() );
129 outputs.insert( QStringLiteral(
"WIDTH_IN_PIXELS" ), mLayerWidth );
130 outputs.insert( QStringLiteral(
"HEIGHT_IN_PIXELS" ), mLayerHeight );
131 outputs.insert( QStringLiteral(
"TOTAL_PIXEL_COUNT" ), layerSize );
132 outputs.insert( QStringLiteral(
"OUTPUT" ), outputFile );
141QString QgsFuzzifyRasterLinearMembershipAlgorithm::name()
const
143 return QStringLiteral(
"fuzzifyrasterlinearmembership" );
146QString QgsFuzzifyRasterLinearMembershipAlgorithm::displayName()
const
148 return QObject::tr(
"Fuzzify raster (linear membership)" );
151QStringList QgsFuzzifyRasterLinearMembershipAlgorithm::tags()
const
153 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,linear,membership" ).split(
',' );
156QString QgsFuzzifyRasterLinearMembershipAlgorithm::shortDescription()
const
158 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following a "
159 "linear fuzzy membership function." );
162QString QgsFuzzifyRasterLinearMembershipAlgorithm::shortHelpString()
const
164 return QObject::tr(
"This algorithm transforms an input raster "
165 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
166 "linear fuzzy membership function. The value of 0 implies no membership with the "
167 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
168 "of membership of raster values follows a linear membership function.\n\n"
169 "The linear function is constructed using two user-defined input raster values "
170 "which set the point of full membership (high bound, results to 1) and no membership "
171 "(low bound, results to 0) respectively. The fuzzy set in between those values is defined as a "
172 "linear function.\n\n"
173 "Both increasing and decreasing fuzzy sets can be modeled by "
174 "swapping the high and low bound parameters." );
177QgsFuzzifyRasterLinearMembershipAlgorithm *QgsFuzzifyRasterLinearMembershipAlgorithm::createInstance()
const
179 return new QgsFuzzifyRasterLinearMembershipAlgorithm();
182void QgsFuzzifyRasterLinearMembershipAlgorithm::addAlgorithmParams()
191 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
192 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
200 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
201 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
202 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
205 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
210 bool isNoData =
false;
211 std::unique_ptr<QgsRasterBlock> rasterBlock;
212 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
215 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
216 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
218 for (
int row = 0; row < iterRows; row++ )
222 for (
int column = 0; column < iterCols; column++ )
227 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
228 double fuzzifiedValue;
232 fuzzifiedValue = mNoDataValue;
234 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
236 if ( value <= mFuzzifyLowBound )
238 else if ( value >= mFuzzifyHighBound )
241 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
243 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
245 if ( value >= mFuzzifyLowBound )
247 else if ( value <= mFuzzifyHighBound )
250 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
254 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
257 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
260 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
272QString QgsFuzzifyRasterPowerMembershipAlgorithm::name()
const
274 return QStringLiteral(
"fuzzifyrasterpowermembership" );
277QString QgsFuzzifyRasterPowerMembershipAlgorithm::displayName()
const
279 return QObject::tr(
"Fuzzify raster (power membership)" );
282QStringList QgsFuzzifyRasterPowerMembershipAlgorithm::tags()
const
284 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,power,non-linear,membership,exponent" ).split(
',' );
287QString QgsFuzzifyRasterPowerMembershipAlgorithm::shortDescription()
const
289 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following a "
293QString QgsFuzzifyRasterPowerMembershipAlgorithm::shortHelpString()
const
295 return QObject::tr(
"This algorithm transforms an input raster "
296 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
297 "power function. The value of 0 implies no membership with the "
298 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
299 "of membership of raster values follows a power function.\n\n"
300 "The power function is constructed using three user-defined input raster values "
301 "which set the point of full membership (high bound, results to 1), no membership "
302 "(low bound, results to 0) and function exponent (only positive) respectively. "
303 "The fuzzy set in between those the upper and lower bounds values is then defined as "
304 "a power function.\n\n"
305 "Both increasing and decreasing fuzzy sets can be modeled by "
306 "swapping the high and low bound parameters." );
309QgsFuzzifyRasterPowerMembershipAlgorithm *QgsFuzzifyRasterPowerMembershipAlgorithm::createInstance()
const
311 return new QgsFuzzifyRasterPowerMembershipAlgorithm();
314void QgsFuzzifyRasterPowerMembershipAlgorithm::addAlgorithmParams()
324 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
325 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
326 mFuzzifyExponent = parameterAsDouble( parameters, QStringLiteral(
"FUZZYEXPONENT" ), context );
334 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
335 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
336 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
339 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
344 bool isNoData =
false;
345 std::unique_ptr<QgsRasterBlock> rasterBlock;
346 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
349 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
350 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
352 for (
int row = 0; row < iterRows; row++ )
356 for (
int column = 0; column < iterCols; column++ )
361 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
362 double fuzzifiedValue;
366 fuzzifiedValue = mNoDataValue;
368 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
370 if ( value <= mFuzzifyLowBound )
372 else if ( value >= mFuzzifyHighBound )
375 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
377 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
379 if ( value >= mFuzzifyLowBound )
381 else if ( value <= mFuzzifyHighBound )
384 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
388 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
391 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
394 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
405QString QgsFuzzifyRasterLargeMembershipAlgorithm::name()
const
407 return QStringLiteral(
"fuzzifyrasterlargemembership" );
410QString QgsFuzzifyRasterLargeMembershipAlgorithm::displayName()
const
412 return QObject::tr(
"Fuzzify raster (large membership)" );
415QStringList QgsFuzzifyRasterLargeMembershipAlgorithm::tags()
const
417 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,large,membership" ).split(
',' );
420QString QgsFuzzifyRasterLargeMembershipAlgorithm::shortDescription()
const
422 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following the "
423 "'large' fuzzy membership function." );
426QString QgsFuzzifyRasterLargeMembershipAlgorithm::shortHelpString()
const
428 return QObject::tr(
"This algorithm transforms an input raster "
429 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
430 "'large' fuzzy membership function. The value of 0 implies no membership with the "
431 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
432 "of membership of raster values follows the 'large' membership function.\n\n"
433 "The 'large' function is constructed using two user-defined input raster values "
434 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
435 "function spread which controls the function uptake.\n\n"
436 "This function is typically used when larger input raster values should become members "
437 "of the fuzzy set more easily than smaller values." );
440QgsFuzzifyRasterLargeMembershipAlgorithm *QgsFuzzifyRasterLargeMembershipAlgorithm::createInstance()
const
442 return new QgsFuzzifyRasterLargeMembershipAlgorithm();
445void QgsFuzzifyRasterLargeMembershipAlgorithm::addAlgorithmParams()
454 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
455 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
463 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
464 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
465 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
468 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
473 bool isNoData =
false;
474 std::unique_ptr<QgsRasterBlock> rasterBlock;
475 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
478 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
479 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
481 for (
int row = 0; row < iterRows; row++ )
485 for (
int column = 0; column < iterCols; column++ )
490 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
491 double fuzzifiedValue;
495 fuzzifiedValue = mNoDataValue;
499 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, -mFuzzifySpread ) );
502 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
505 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
517QString QgsFuzzifyRasterSmallMembershipAlgorithm::name()
const
519 return QStringLiteral(
"fuzzifyrastersmallmembership" );
522QString QgsFuzzifyRasterSmallMembershipAlgorithm::displayName()
const
524 return QObject::tr(
"Fuzzify raster (small membership)" );
527QStringList QgsFuzzifyRasterSmallMembershipAlgorithm::tags()
const
529 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,small,membership" ).split(
',' );
532QString QgsFuzzifyRasterSmallMembershipAlgorithm::shortDescription()
const
534 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following the "
535 "'small' fuzzy membership function." );
538QString QgsFuzzifyRasterSmallMembershipAlgorithm::shortHelpString()
const
540 return QObject::tr(
"The Fuzzify raster (small membership) algorithm transforms an input raster "
541 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
542 "'small' fuzzy membership function. The value of 0 implies no membership with the "
543 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
544 "of membership of raster values follows the 'small' membership function.\n\n"
545 "The 'small' function is constructed using two user-defined input raster values "
546 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
547 "function spread which controls the function uptake.\n\n"
548 "This function is typically used when smaller input raster values should become members "
549 "of the fuzzy set more easily than higher values." );
552QgsFuzzifyRasterSmallMembershipAlgorithm *QgsFuzzifyRasterSmallMembershipAlgorithm::createInstance()
const
554 return new QgsFuzzifyRasterSmallMembershipAlgorithm();
557void QgsFuzzifyRasterSmallMembershipAlgorithm::addAlgorithmParams()
566 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
567 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
575 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
576 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
577 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
580 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
585 bool isNoData =
false;
586 std::unique_ptr<QgsRasterBlock> rasterBlock;
587 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
590 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
591 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
593 for (
int row = 0; row < iterRows; row++ )
597 for (
int column = 0; column < iterCols; column++ )
602 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
603 double fuzzifiedValue;
607 fuzzifiedValue = mNoDataValue;
611 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, mFuzzifySpread ) );
614 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
617 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
629QString QgsFuzzifyRasterGaussianMembershipAlgorithm::name()
const
631 return QStringLiteral(
"fuzzifyrastergaussianmembership" );
634QString QgsFuzzifyRasterGaussianMembershipAlgorithm::displayName()
const
636 return QObject::tr(
"Fuzzify raster (gaussian membership)" );
639QStringList QgsFuzzifyRasterGaussianMembershipAlgorithm::tags()
const
641 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,gaussian,membership" ).split(
',' );
644QString QgsFuzzifyRasterGaussianMembershipAlgorithm::shortDescription()
const
646 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following a "
647 "gaussian fuzzy membership function." );
650QString QgsFuzzifyRasterGaussianMembershipAlgorithm::shortHelpString()
const
652 return QObject::tr(
"This algorithm transforms an input raster "
653 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
654 "gaussian fuzzy membership function. The value of 0 implies no membership with the "
655 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
656 "of membership of raster values follows a gaussian membership function.\n\n"
657 "The gaussian function is constructed using two user-defined input values "
658 "which set the midpoint of the gaussian function (midpoint, results to 1) and a "
659 "predefined function spread which controls the function spread.\n\n"
660 "This function is typically used when a certain range of raster values around a "
661 "predefined function midpoint should become members of the fuzzy set." );
664QgsFuzzifyRasterGaussianMembershipAlgorithm *QgsFuzzifyRasterGaussianMembershipAlgorithm::createInstance()
const
666 return new QgsFuzzifyRasterGaussianMembershipAlgorithm();
669void QgsFuzzifyRasterGaussianMembershipAlgorithm::addAlgorithmParams()
678 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
679 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
687 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
688 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
689 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
692 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
697 bool isNoData =
false;
698 std::unique_ptr<QgsRasterBlock> rasterBlock;
699 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
702 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
703 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
705 for (
int row = 0; row < iterRows; row++ )
709 for (
int column = 0; column < iterCols; column++ )
714 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
715 double fuzzifiedValue;
719 fuzzifiedValue = mNoDataValue;
723 fuzzifiedValue = std::exp( -mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
726 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
729 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
741QString QgsFuzzifyRasterNearMembershipAlgorithm::name()
const
743 return QStringLiteral(
"fuzzifyrasternearmembership" );
746QString QgsFuzzifyRasterNearMembershipAlgorithm::displayName()
const
748 return QObject::tr(
"Fuzzify raster (near membership)" );
751QStringList QgsFuzzifyRasterNearMembershipAlgorithm::tags()
const
753 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,near,membership" ).split(
',' );
756QString QgsFuzzifyRasterNearMembershipAlgorithm::shortDescription()
const
758 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following the "
759 "'near' fuzzy membership function." );
762QString QgsFuzzifyRasterNearMembershipAlgorithm::shortHelpString()
const
764 return QObject::tr(
"The Fuzzify raster (near membership) algorithm transforms an input raster "
765 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
766 "'near' fuzzy membership function. The value of 0 implies no membership with the "
767 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
768 "of membership of raster values follows the 'near' membership function.\n\n"
769 "The 'near' function is constructed using two user-defined input values "
770 "which set the midpoint of the 'near' function (midpoint, results to 1) and a "
771 "predefined function spread which controls the function spread.\n\n"
772 "This function is typically used when a certain range of raster values near a "
773 "predefined function midpoint should become members of the fuzzy set. The function"
774 " generally shows a higher rate of decay than the gaussian membership function." );
777QgsFuzzifyRasterNearMembershipAlgorithm *QgsFuzzifyRasterNearMembershipAlgorithm::createInstance()
const
779 return new QgsFuzzifyRasterNearMembershipAlgorithm();
782void QgsFuzzifyRasterNearMembershipAlgorithm::addAlgorithmParams()
791 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
792 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
800 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
801 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
802 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
805 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
810 bool isNoData =
false;
811 std::unique_ptr<QgsRasterBlock> rasterBlock;
812 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
815 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
816 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
818 for (
int row = 0; row < iterRows; row++ )
822 for (
int column = 0; column < iterCols; column++ )
827 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
828 double fuzzifiedValue;
832 fuzzifiedValue = mNoDataValue;
836 fuzzifiedValue = 1 / ( 1 + mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
839 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
842 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...