Skip to content

Commit

Permalink
Report warnings when class boundaries overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 13, 2018
1 parent 6b24d8c commit 1a226e6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/analysis/processing/qgsalgorithmreclassifybylayer.cpp
Expand Up @@ -124,6 +124,9 @@ QVariantMap QgsReclassifyAlgorithmBase::processAlgorithm( const QVariantMap &par
{
QVector< QgsReclassifyUtils::RasterClass > classes = createClasses( mBoundsType, parameters, context, feedback );

QgsReclassifyUtils::reportClasses( classes, feedback );
QgsReclassifyUtils::checkForOverlaps( classes, feedback );

const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
QFileInfo fi( outputFile );
const QString outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
Expand Down
34 changes: 34 additions & 0 deletions src/analysis/processing/qgsreclassifyutils.cpp
Expand Up @@ -26,6 +26,40 @@

///@cond PRIVATE

void QgsReclassifyUtils::reportClasses( const QVector<QgsReclassifyUtils::RasterClass> &classes, QgsProcessingFeedback *feedback )
{
int i = 1;
feedback->pushInfo( QObject::tr( "Using classes:" ) );
for ( const RasterClass &c : classes )
{
feedback->pushInfo( QStringLiteral( " %1) %2 %3 %4" ).arg( i )
.arg( c.asText() )
.arg( QChar( 0x2192 ) )
.arg( c.value ) );
i++;
}
}

void QgsReclassifyUtils::checkForOverlaps( const QVector<QgsReclassifyUtils::RasterClass> &classes, QgsProcessingFeedback *feedback )
{
// test each class against each other class
for ( int i = 0; i < classes.count() - 1; i++ )
{
for ( int j = i + 1; j < classes.count(); j++ )
{
const QgsReclassifyUtils::RasterClass &class1 = classes.at( i );
const QgsReclassifyUtils::RasterClass &class2 = classes.at( j );
if ( class1.overlaps( class2 ) )
{
feedback->reportError( QObject::tr( "Warning: Class %1 (%2) overlaps with class %3 (%4)" ).arg( i + 1 )
.arg( class1.asText() )
.arg( j + 1 )
.arg( class2.asText() ) );
}
}
}
}

void QgsReclassifyUtils::reclassify( const QVector<QgsReclassifyUtils::RasterClass> &classes, QgsRasterInterface *sourceRaster, int band,
const QgsRectangle &extent, int sourceWidthPixels, int sourceHeightPixels,
QgsRasterDataProvider *destinationRaster, double destNoDataValue, bool useNoDataForMissingValues,
Expand Down
11 changes: 11 additions & 0 deletions src/analysis/processing/qgsreclassifyutils.h
Expand Up @@ -65,6 +65,17 @@ class ANALYSIS_EXPORT QgsReclassifyUtils
double value = 0;
};

/**
* Prints a list of classes contained within \a classes to specified \a feedback object.
*/
static void reportClasses( const QVector< RasterClass > &classes, QgsProcessingFeedback *feedback );

/**
* Checks for overlaps in a set of \a classes, reporting any overlapping
* classes the to specified \a feedback object.
*/
static void checkForOverlaps( const QVector< RasterClass > &classes, QgsProcessingFeedback *feedback );

/**
* Performs a reclassification operation on a raster source \a sourceRaster, reclassifying to the given
* list of \a classes.
Expand Down
2 changes: 1 addition & 1 deletion src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Expand Up @@ -565,7 +565,7 @@ QString QgsProcessingAlgorithmDialogBase::formatStringForLog( const QString &str
void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isError, bool escapeHtml )
{
if ( isError )
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).arg( formatStringForLog( message ) ) );
txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).arg( escapeHtml ? formatStringForLog( message.toHtmlEscaped() ) : formatStringForLog( message ) ) );
else if ( escapeHtml )
txtLog->append( formatStringForLog( message.toHtmlEscaped() ) );
else
Expand Down

0 comments on commit 1a226e6

Please sign in to comment.