Skip to content

Commit

Permalink
Expose choice of how to handle out-of-class values
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 13, 2018
1 parent 18ddc4e commit dafa384
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/analysis/processing/qgsalgorithmreclassifybylayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ void QgsReclassifyAlgorithmBase::initAlgorithm( const QVariantMap &configuration
boundsHandling->setFlags( QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( boundsHandling.release() );

std::unique_ptr< QgsProcessingParameterBoolean > missingValuesParam = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( "NODATA_FOR_MISSING" ),
QObject::tr( "Use no data when no range matches value" ), false, false );
missingValuesParam->setFlags( QgsProcessingParameterDefinition::FlagAdvanced );
addParameter( missingValuesParam.release() );

addParameter( new QgsProcessingParameterRasterDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Reclassified raster" ) ) );
}

Expand All @@ -80,7 +85,7 @@ bool QgsReclassifyAlgorithmBase::prepareAlgorithm( const QVariantMap &parameters
mNbCellsYProvider = mInterface->ySize();

mNoDataValue = parameterAsDouble( parameters, QStringLiteral( "NO_DATA" ), context );

mUseNoDataForMissingValues = parameterAsBool( parameters, QStringLiteral( "NODATA_FOR_MISSING" ), context );

int boundsType = parameterAsEnum( parameters, QStringLiteral( "RANGE_BOUNDARIES" ), context );
switch ( boundsType )
Expand All @@ -107,7 +112,7 @@ bool QgsReclassifyAlgorithmBase::prepareAlgorithm( const QVariantMap &parameters

QVariantMap QgsReclassifyAlgorithmBase::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
QVector< QgsReclassifyUtils::RasterClass > classes = createClasses( parameters, context, feedback );
QVector< QgsReclassifyUtils::RasterClass > classes = createClasses( mBoundsType, parameters, context, feedback );

const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
QFileInfo fi( outputFile );
Expand All @@ -122,7 +127,8 @@ QVariantMap QgsReclassifyAlgorithmBase::processAlgorithm( const QVariantMap &par

provider->setNoDataValue( 1, mNoDataValue );

QgsReclassifyUtils::reclassify( classes, mInterface.get(), mBand, mExtent, mNbCellsXProvider, mNbCellsYProvider, provider.get(), mNoDataValue, feedback );
QgsReclassifyUtils::reclassify( classes, mInterface.get(), mBand, mExtent, mNbCellsXProvider, mNbCellsYProvider, provider.get(), mNoDataValue, mUseNoDataForMissingValues,
feedback );

QVariantMap outputs;
outputs.insert( QStringLiteral( "OUTPUT" ), outputFile );
Expand Down
4 changes: 3 additions & 1 deletion src/analysis/processing/qgsalgorithmreclassifybylayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class QgsReclassifyAlgorithmBase : public QgsProcessingAlgorithm
int mNbCellsXProvider = 0;
int mNbCellsYProvider = 0;
QgsReclassifyUtils::RasterClass::BoundsType mBoundsType = QgsReclassifyUtils::RasterClass::IncludeMax;
bool mUseNoDataForMissingValues = false;
};

/**
Expand Down Expand Up @@ -124,7 +125,8 @@ class QgsReclassifyByTableAlgorithm : public QgsReclassifyAlgorithmBase

void addAlgorithmParams() override;
bool _prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QVector< QgsReclassifyUtils::RasterClass > createClasses( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QVector< QgsReclassifyUtils::RasterClass > createClasses( QgsReclassifyUtils::RasterClass::BoundsType boundsType,
const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

};

Expand Down

0 comments on commit dafa384

Please sign in to comment.