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(
',' );
155QString QgsFuzzifyRasterLinearMembershipAlgorithm::shortDescription()
const
157 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following a "
158 "linear fuzzy membership function." );
161QString QgsFuzzifyRasterLinearMembershipAlgorithm::shortHelpString()
const
163 return QObject::tr(
"This algorithm transforms an input raster "
164 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
165 "linear fuzzy membership function. The value of 0 implies no membership with the "
166 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
167 "of membership of raster values follows a linear membership function.\n\n"
168 "The linear function is constructed using two user-defined input raster values "
169 "which set the point of full membership (high bound, results to 1) and no membership "
170 "(low bound, results to 0) respectively. The fuzzy set in between those values is defined as a "
171 "linear function.\n\n"
172 "Both increasing and decreasing fuzzy sets can be modeled by "
173 "swapping the high and low bound parameters." );
176QgsFuzzifyRasterLinearMembershipAlgorithm *QgsFuzzifyRasterLinearMembershipAlgorithm::createInstance()
const
178 return new QgsFuzzifyRasterLinearMembershipAlgorithm();
181void QgsFuzzifyRasterLinearMembershipAlgorithm::addAlgorithmParams()
190 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
191 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
199 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
200 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
201 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
204 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
209 bool isNoData =
false;
210 std::unique_ptr<QgsRasterBlock> rasterBlock;
211 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
214 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
215 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
217 for (
int row = 0; row < iterRows; row++ )
221 for (
int column = 0; column < iterCols; column++ )
226 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
227 double fuzzifiedValue;
231 fuzzifiedValue = mNoDataValue;
233 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
235 if ( value <= mFuzzifyLowBound )
237 else if ( value >= mFuzzifyHighBound )
240 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
242 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
244 if ( value >= mFuzzifyLowBound )
246 else if ( value <= mFuzzifyHighBound )
249 fuzzifiedValue = ( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ) );
253 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
256 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
259 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
271QString QgsFuzzifyRasterPowerMembershipAlgorithm::name()
const
273 return QStringLiteral(
"fuzzifyrasterpowermembership" );
276QString QgsFuzzifyRasterPowerMembershipAlgorithm::displayName()
const
278 return QObject::tr(
"Fuzzify raster (power membership)" );
281QStringList QgsFuzzifyRasterPowerMembershipAlgorithm::tags()
const
283 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,power,non-linear,membership,exponent" ).split(
',' );
286QString QgsFuzzifyRasterPowerMembershipAlgorithm::shortDescription()
const
288 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following a "
292QString QgsFuzzifyRasterPowerMembershipAlgorithm::shortHelpString()
const
294 return QObject::tr(
"This algorithm transforms an input raster "
295 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
296 "power function. The value of 0 implies no membership with the "
297 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
298 "of membership of raster values follows a power function.\n\n"
299 "The power function is constructed using three user-defined input raster values "
300 "which set the point of full membership (high bound, results to 1), no membership "
301 "(low bound, results to 0) and function exponent (only positive) respectively. "
302 "The fuzzy set in between those the upper and lower bounds values is then defined as "
303 "a power function.\n\n"
304 "Both increasing and decreasing fuzzy sets can be modeled by "
305 "swapping the high and low bound parameters." );
308QgsFuzzifyRasterPowerMembershipAlgorithm *QgsFuzzifyRasterPowerMembershipAlgorithm::createInstance()
const
310 return new QgsFuzzifyRasterPowerMembershipAlgorithm();
313void QgsFuzzifyRasterPowerMembershipAlgorithm::addAlgorithmParams()
323 mFuzzifyHighBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYHIGHBOUND" ), context );
324 mFuzzifyLowBound = parameterAsDouble( parameters, QStringLiteral(
"FUZZYLOWBOUND" ), context );
325 mFuzzifyExponent = parameterAsDouble( parameters, QStringLiteral(
"FUZZYEXPONENT" ), context );
333 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
334 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
335 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
338 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
343 bool isNoData =
false;
344 std::unique_ptr<QgsRasterBlock> rasterBlock;
345 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
348 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
349 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
351 for (
int row = 0; row < iterRows; row++ )
355 for (
int column = 0; column < iterCols; column++ )
360 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
361 double fuzzifiedValue;
365 fuzzifiedValue = mNoDataValue;
367 else if ( mFuzzifyLowBound < mFuzzifyHighBound )
369 if ( value <= mFuzzifyLowBound )
371 else if ( value >= mFuzzifyHighBound )
374 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
376 else if ( mFuzzifyLowBound > mFuzzifyHighBound )
378 if ( value >= mFuzzifyLowBound )
380 else if ( value <= mFuzzifyHighBound )
383 fuzzifiedValue = std::pow( ( value - mFuzzifyLowBound ) / ( mFuzzifyHighBound - mFuzzifyLowBound ), mFuzzifyExponent );
387 throw QgsProcessingException( QObject::tr(
"Please choose varying values for the high and low membership parameters" ) );
390 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
393 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
404QString QgsFuzzifyRasterLargeMembershipAlgorithm::name()
const
406 return QStringLiteral(
"fuzzifyrasterlargemembership" );
409QString QgsFuzzifyRasterLargeMembershipAlgorithm::displayName()
const
411 return QObject::tr(
"Fuzzify raster (large membership)" );
414QStringList QgsFuzzifyRasterLargeMembershipAlgorithm::tags()
const
416 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,large,membership" ).split(
',' );
419QString QgsFuzzifyRasterLargeMembershipAlgorithm::shortDescription()
const
421 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following the "
422 "'large' fuzzy membership function." );
425QString QgsFuzzifyRasterLargeMembershipAlgorithm::shortHelpString()
const
427 return QObject::tr(
"This algorithm transforms an input raster "
428 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
429 "'large' fuzzy membership function. The value of 0 implies no membership with the "
430 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
431 "of membership of raster values follows the 'large' membership function.\n\n"
432 "The 'large' function is constructed using two user-defined input raster values "
433 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
434 "function spread which controls the function uptake.\n\n"
435 "This function is typically used when larger input raster values should become members "
436 "of the fuzzy set more easily than smaller values." );
439QgsFuzzifyRasterLargeMembershipAlgorithm *QgsFuzzifyRasterLargeMembershipAlgorithm::createInstance()
const
441 return new QgsFuzzifyRasterLargeMembershipAlgorithm();
444void QgsFuzzifyRasterLargeMembershipAlgorithm::addAlgorithmParams()
453 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
454 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
462 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
463 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
464 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
467 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
472 bool isNoData =
false;
473 std::unique_ptr<QgsRasterBlock> rasterBlock;
474 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
477 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
478 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
480 for (
int row = 0; row < iterRows; row++ )
484 for (
int column = 0; column < iterCols; column++ )
489 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
490 double fuzzifiedValue;
494 fuzzifiedValue = mNoDataValue;
498 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, -mFuzzifySpread ) );
501 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
504 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
516QString QgsFuzzifyRasterSmallMembershipAlgorithm::name()
const
518 return QStringLiteral(
"fuzzifyrastersmallmembership" );
521QString QgsFuzzifyRasterSmallMembershipAlgorithm::displayName()
const
523 return QObject::tr(
"Fuzzify raster (small membership)" );
526QStringList QgsFuzzifyRasterSmallMembershipAlgorithm::tags()
const
528 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,small,membership" ).split(
',' );
531QString QgsFuzzifyRasterSmallMembershipAlgorithm::shortDescription()
const
533 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following the "
534 "'small' fuzzy membership function." );
537QString QgsFuzzifyRasterSmallMembershipAlgorithm::shortHelpString()
const
539 return QObject::tr(
"The Fuzzify raster (small membership) algorithm transforms an input raster "
540 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
541 "'small' fuzzy membership function. The value of 0 implies no membership with the "
542 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
543 "of membership of raster values follows the 'small' membership function.\n\n"
544 "The 'small' function is constructed using two user-defined input raster values "
545 "which set the point of half membership (midpoint, results to 0.5) and a predefined "
546 "function spread which controls the function uptake.\n\n"
547 "This function is typically used when smaller input raster values should become members "
548 "of the fuzzy set more easily than higher values." );
551QgsFuzzifyRasterSmallMembershipAlgorithm *QgsFuzzifyRasterSmallMembershipAlgorithm::createInstance()
const
553 return new QgsFuzzifyRasterSmallMembershipAlgorithm();
556void QgsFuzzifyRasterSmallMembershipAlgorithm::addAlgorithmParams()
565 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
566 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
574 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
575 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
576 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
579 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
584 bool isNoData =
false;
585 std::unique_ptr<QgsRasterBlock> rasterBlock;
586 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
589 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
590 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
592 for (
int row = 0; row < iterRows; row++ )
596 for (
int column = 0; column < iterCols; column++ )
601 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
602 double fuzzifiedValue;
606 fuzzifiedValue = mNoDataValue;
610 fuzzifiedValue = 1 / ( 1 + std::pow( value / mFuzzifyMidpoint, mFuzzifySpread ) );
613 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
616 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
628QString QgsFuzzifyRasterGaussianMembershipAlgorithm::name()
const
630 return QStringLiteral(
"fuzzifyrastergaussianmembership" );
633QString QgsFuzzifyRasterGaussianMembershipAlgorithm::displayName()
const
635 return QObject::tr(
"Fuzzify raster (gaussian membership)" );
638QStringList QgsFuzzifyRasterGaussianMembershipAlgorithm::tags()
const
640 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,gaussian,membership" ).split(
',' );
643QString QgsFuzzifyRasterGaussianMembershipAlgorithm::shortDescription()
const
645 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following a "
646 "gaussian fuzzy membership function." );
649QString QgsFuzzifyRasterGaussianMembershipAlgorithm::shortHelpString()
const
651 return QObject::tr(
"This algorithm transforms an input raster "
652 "to a fuzzified raster and thereby assigns values between 0 and 1 following a "
653 "gaussian fuzzy membership function. The value of 0 implies no membership with the "
654 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
655 "of membership of raster values follows a gaussian membership function.\n\n"
656 "The gaussian function is constructed using two user-defined input values "
657 "which set the midpoint of the gaussian function (midpoint, results to 1) and a "
658 "predefined function spread which controls the function spread.\n\n"
659 "This function is typically used when a certain range of raster values around a "
660 "predefined function midpoint should become members of the fuzzy set." );
663QgsFuzzifyRasterGaussianMembershipAlgorithm *QgsFuzzifyRasterGaussianMembershipAlgorithm::createInstance()
const
665 return new QgsFuzzifyRasterGaussianMembershipAlgorithm();
668void QgsFuzzifyRasterGaussianMembershipAlgorithm::addAlgorithmParams()
677 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
678 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
686 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
687 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
688 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
691 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
696 bool isNoData =
false;
697 std::unique_ptr<QgsRasterBlock> rasterBlock;
698 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
701 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
702 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
704 for (
int row = 0; row < iterRows; row++ )
708 for (
int column = 0; column < iterCols; column++ )
713 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
714 double fuzzifiedValue;
718 fuzzifiedValue = mNoDataValue;
722 fuzzifiedValue = std::exp( -mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
725 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
728 if ( !destinationProvider->
writeBlock( fuzzifiedBlock.get(), mBand, iterLeft, iterTop ) )
740QString QgsFuzzifyRasterNearMembershipAlgorithm::name()
const
742 return QStringLiteral(
"fuzzifyrasternearmembership" );
745QString QgsFuzzifyRasterNearMembershipAlgorithm::displayName()
const
747 return QObject::tr(
"Fuzzify raster (near membership)" );
750QStringList QgsFuzzifyRasterNearMembershipAlgorithm::tags()
const
752 return QObject::tr(
"fuzzy logic,fuzzify,fuzzy,logic,near,membership" ).split(
',' );
755QString QgsFuzzifyRasterNearMembershipAlgorithm::shortDescription()
const
757 return QObject::tr(
"Transforms an input raster to a fuzzified raster where values range from 0 to 1 following the "
758 "'near' fuzzy membership function." );
761QString QgsFuzzifyRasterNearMembershipAlgorithm::shortHelpString()
const
763 return QObject::tr(
"The Fuzzify raster (near membership) algorithm transforms an input raster "
764 "to a fuzzified raster and thereby assigns values between 0 and 1 following the "
765 "'near' fuzzy membership function. The value of 0 implies no membership with the "
766 "defined fuzzy set, a value of 1 depicts full membership. In between, the degree "
767 "of membership of raster values follows the 'near' membership function.\n\n"
768 "The 'near' function is constructed using two user-defined input values "
769 "which set the midpoint of the 'near' function (midpoint, results to 1) and a "
770 "predefined function spread which controls the function spread.\n\n"
771 "This function is typically used when a certain range of raster values near a "
772 "predefined function midpoint should become members of the fuzzy set. The function"
773 " generally shows a higher rate of decay than the gaussian membership function." );
776QgsFuzzifyRasterNearMembershipAlgorithm *QgsFuzzifyRasterNearMembershipAlgorithm::createInstance()
const
778 return new QgsFuzzifyRasterNearMembershipAlgorithm();
781void QgsFuzzifyRasterNearMembershipAlgorithm::addAlgorithmParams()
790 mFuzzifyMidpoint = parameterAsDouble( parameters, QStringLiteral(
"FUZZYMIDPOINT" ), context );
791 mFuzzifySpread = parameterAsDouble( parameters, QStringLiteral(
"FUZZYSPREAD" ), context );
799 const int nbBlocksWidth =
static_cast<int>( std::ceil( 1.0 * mLayerWidth / maxWidth ) );
800 const int nbBlocksHeight =
static_cast<int>( std::ceil( 1.0 * mLayerHeight / maxHeight ) );
801 const int nbBlocks = nbBlocksWidth * nbBlocksHeight;
804 iter.startRasterRead( mBand, mLayerWidth, mLayerHeight, mExtent );
809 bool isNoData =
false;
810 std::unique_ptr<QgsRasterBlock> rasterBlock;
811 while ( iter.readNextRasterPart( mBand, iterCols, iterRows, rasterBlock, iterLeft, iterTop ) )
814 feedback->
setProgress( 100 * ( ( iterTop / maxHeight * nbBlocksWidth ) + iterLeft / maxWidth ) / nbBlocks );
815 auto fuzzifiedBlock = std::make_unique<QgsRasterBlock>( destinationProvider->
dataType( 1 ), iterCols, iterRows );
817 for (
int row = 0; row < iterRows; row++ )
821 for (
int column = 0; column < iterCols; column++ )
826 const double value = rasterBlock->valueAndNoData( row, column, isNoData );
827 double fuzzifiedValue;
831 fuzzifiedValue = mNoDataValue;
835 fuzzifiedValue = 1 / ( 1 + mFuzzifySpread * std::pow( value - mFuzzifyMidpoint, 2 ) );
838 fuzzifiedBlock->setValue( row, column, fuzzifiedValue );
841 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...