Skip to content
Permalink
Browse files

Report warnings when class boundaries overlap

  • Loading branch information
nyalldawson committed Jun 12, 2018
1 parent 6b24d8c commit 1a226e6cd3545ceb6b067465902e9d2dd32259b1
@@ -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() );
@@ -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,
@@ -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.
@@ -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

0 comments on commit 1a226e6

Please sign in to comment.
You can’t perform that action at this time.