Skip to content

Commit

Permalink
Abort geometry checks if feedback is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent e300387 commit 42c3f45
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/analysis/vector/geometry_checker/qgsgeometrygapcheck.cpp
Expand Up @@ -44,6 +44,13 @@ void QgsGeometryGapCheck::collectErrors( const QMap<QString, QgsFeaturePool *> &
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
geomList.append( layerFeature.geometry().constGet()->clone() );

if ( feedback->isCanceled() )
{
qDeleteAll( geomList );
geomList.clear();
break;
}
}

if ( geomList.isEmpty() )
Expand Down
Expand Up @@ -43,11 +43,16 @@ void QgsGeometryMissingVertexCheck::collectErrors( const QMap<QString, QgsFeatur

for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
if ( feedback->isCanceled() )
{
break;
}

const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();

if ( QgsCurvePolygon *polygon = qgsgeometry_cast<QgsCurvePolygon *>( geom ) )
{
processPolygon( polygon, featurePool, errors, layerFeature );
processPolygon( polygon, featurePool, errors, layerFeature, feedback );
}
else if ( QgsGeometryCollection *collection = qgsgeometry_cast<QgsGeometryCollection *>( geom ) )
{
Expand All @@ -56,7 +61,7 @@ void QgsGeometryMissingVertexCheck::collectErrors( const QMap<QString, QgsFeatur
{
if ( QgsCurvePolygon *polygon = qgsgeometry_cast<QgsCurvePolygon *>( collection->geometryN( i ) ) )
{
processPolygon( polygon, featurePool, errors, layerFeature );
processPolygon( polygon, featurePool, errors, layerFeature, feedback );
}
}
}
Expand Down Expand Up @@ -105,7 +110,7 @@ QString QgsGeometryMissingVertexCheck::description() const
return factoryDescription();
}

void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature ) const
void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, QgsFeedback *feedback ) const
{
const QgsFeature &currentFeature = layerFeature.feature();
std::unique_ptr<QgsMultiPolygon> boundaries = qgis::make_unique<QgsMultiPolygon>();
Expand Down Expand Up @@ -133,6 +138,9 @@ void QgsGeometryMissingVertexCheck::processPolygon( const QgsCurvePolygon *polyg

if ( featurePool->getFeature( fid, compareFeature ) )
{
if ( feedback->isCanceled() )
break;

QgsVertexIterator vertexIterator = compareFeature.geometry().vertices();
while ( vertexIterator.hasNext() )
{
Expand Down
Expand Up @@ -62,7 +62,7 @@ class ANALYSIS_EXPORT QgsGeometryMissingVertexCheck : public QgsGeometryCheck
///@endcond

private:
void processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature ) const;
void processPolygon( const QgsCurvePolygon *polygon, QgsFeaturePool *featurePool, QList<QgsGeometryCheckError *> &errors, const QgsGeometryCheckerUtils::LayerFeature &layerFeature, QgsFeedback *feedback ) const;
};


Expand Down
15 changes: 10 additions & 5 deletions src/analysis/vector/geometry_checker/qgsgeometryoverlapcheck.cpp
Expand Up @@ -18,7 +18,7 @@
#include "qgsgeometryoverlapcheck.h"
#include "qgsfeaturepool.h"
#include "qgsvectorlayer.h"

#include "qgsfeedback.h"

QgsGeometryOverlapCheck::QgsGeometryOverlapCheck( const QgsGeometryCheckContext *context, const QVariantMap &configuration )
: QgsGeometryCheck( context, configuration )
Expand All @@ -35,6 +35,9 @@ void QgsGeometryOverlapCheck::collectErrors( const QMap<QString, QgsFeaturePool
QList<QString> layerIds = featureIds.keys();
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureA : layerFeaturesA )
{
if ( feedback->isCanceled() )
break;

// Ensure each pair of layers only gets compared once: remove the current layer from the layerIds, but add it to the layerList for layerFeaturesB
layerIds.removeOne( layerFeatureA.layer()->id() );

Expand All @@ -49,6 +52,9 @@ void QgsGeometryOverlapCheck::collectErrors( const QMap<QString, QgsFeaturePool
const QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( featurePools, QList<QString>() << layerFeatureA.layer()->id() << layerIds, bboxA, compatibleGeometryTypes(), mContext );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureB : layerFeaturesB )
{
if ( feedback->isCanceled() )
break;

// > : only report overlaps within same layer once
if ( layerFeatureA.layer()->id() == layerFeatureB.layer()->id() && layerFeatureB.feature().id() >= layerFeatureA.feature().id() )
{
Expand All @@ -57,13 +63,13 @@ void QgsGeometryOverlapCheck::collectErrors( const QMap<QString, QgsFeaturePool
QString errMsg;
if ( geomEngineA->overlaps( layerFeatureB.geometry().constGet(), &errMsg ) )
{
QgsAbstractGeometry *interGeom = geomEngineA->intersection( layerFeatureB.geometry().constGet() );
std::unique_ptr<QgsAbstractGeometry> interGeom( geomEngineA->intersection( layerFeatureB.geometry().constGet() ) );
if ( interGeom && !interGeom->isEmpty() )
{
QgsGeometryCheckerUtils::filter1DTypes( interGeom );
QgsGeometryCheckerUtils::filter1DTypes( interGeom.get() );
for ( int iPart = 0, nParts = interGeom->partCount(); iPart < nParts; ++iPart )
{
QgsAbstractGeometry *interPart = QgsGeometryCheckerUtils::getGeomPart( interGeom, iPart );
QgsAbstractGeometry *interPart = QgsGeometryCheckerUtils::getGeomPart( interGeom.get(), iPart );
double area = interPart->area();
if ( area > mContext->reducedTolerance && ( area < mOverlapThresholdMapUnits || mOverlapThresholdMapUnits == 0.0 ) )
{
Expand All @@ -75,7 +81,6 @@ void QgsGeometryOverlapCheck::collectErrors( const QMap<QString, QgsFeaturePool
{
messages.append( tr( "Overlap check between features %1 and %2 %3" ).arg( layerFeatureA.id(), layerFeatureB.id(), errMsg ) );
}
delete interGeom;
}
}
}
Expand Down

0 comments on commit 42c3f45

Please sign in to comment.