From e7efde2c31f017f851e32ea10d889626bc985fbd Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Thu, 30 Mar 2017 18:55:14 +0200 Subject: [PATCH] [Geometry checker] Make checks report affected are in selected crs --- .../checks/qgsgeometrycheck.cpp | 17 ++++++++++++++++- .../geometry_checker/checks/qgsgeometrycheck.h | 6 +++--- .../checks/qgsgeometrygapcheck.cpp | 6 ++++-- .../checks/qgsgeometrygapcheck.h | 4 ++-- .../geometry_checker/qgsgeometrychecker.cpp | 10 +++++++--- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp index b36b6ee392d..2405834ff76 100644 --- a/src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp +++ b/src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp @@ -13,6 +13,7 @@ * * ***************************************************************************/ +#include "qgscrscache.h" #include "qgsgeometrycollection.h" #include "qgscurvepolygon.h" #include "qgsgeometrycheck.h" @@ -41,7 +42,7 @@ QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check, con , mStatus( StatusPending ) {} -QgsAbstractGeometry *QgsGeometryCheckError::geometry() +QgsAbstractGeometry *QgsGeometryCheckError::geometry() const { QgsFeature f; if ( mCheck->getContext()->featurePools[ layerId() ]->get( featureId(), f ) && f.hasGeometry() ) @@ -53,6 +54,20 @@ QgsAbstractGeometry *QgsGeometryCheckError::geometry() return nullptr; } +QgsRectangle QgsGeometryCheckError::affectedAreaBBox() const +{ + QgsAbstractGeometry *geom = geometry(); + if ( !geom ) + { + return QgsRectangle(); + } + QString srcCrs = mCheck->getContext()->featurePools[ layerId() ]->getLayer()->crs().authid(); + QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( srcCrs, mCheck->getContext()->crs ); + QgsRectangle rect = t.transformBoundingBox( geom->boundingBox() ); + delete geom; + return rect; +} + bool QgsGeometryCheckError::handleChanges( const QgsGeometryCheck::Changes &changes ) { if ( status() == StatusObsolete ) diff --git a/src/plugins/geometry_checker/checks/qgsgeometrycheck.h b/src/plugins/geometry_checker/checks/qgsgeometrycheck.h index 9f186bf437c..84ca20d299c 100644 --- a/src/plugins/geometry_checker/checks/qgsgeometrycheck.h +++ b/src/plugins/geometry_checker/checks/qgsgeometrycheck.h @@ -105,15 +105,15 @@ class QgsGeometryCheckError QgsVertexId vidx = QgsVertexId(), const QVariant &value = QVariant(), ValueType valueType = ValueOther ); - virtual ~QgsGeometryCheckError() = default; + virtual ~QgsGeometryCheckError() {} const QgsGeometryCheckError &operator=( const QgsGeometryCheckError & ) = delete; const QgsGeometryCheck *check() const { return mCheck; } const QString &layerId() const { return mLayerId; } QgsFeatureId featureId() const { return mFeatureId; } - virtual QgsAbstractGeometry *geometry(); - virtual QgsRectangle affectedAreaBBox() { return geometry() ? geometry()->boundingBox() : QgsRectangle(); } + virtual QgsAbstractGeometry *geometry() const; + virtual QgsRectangle affectedAreaBBox() const; virtual QString description() const { return mCheck->errorDescription(); } const QgsPoint &location() const { return mErrorLocation; } QVariant value() const { return mValue; } diff --git a/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp b/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp index 4c0e1e06a05..7d7a53241e0 100644 --- a/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp +++ b/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp @@ -13,6 +13,7 @@ * * ***************************************************************************/ +#include "qgscrscache.h" #include "qgsgeometryengine.h" #include "qgsgeometrygapcheck.h" #include "qgsgeometrycollection.h" @@ -28,6 +29,7 @@ void QgsGeometryGapCheck::collectErrors( QList &errors, for ( const QString &layerId : featureIds.keys() ) { QgsFeaturePool *featurePool = mContext->featurePools[ layerId ]; + QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( featurePool->getLayer()->crs().authid(), mContext->crs ); if ( !getCompatibility( featurePool->getLayer()->geometryType() ) ) { continue; @@ -110,7 +112,7 @@ void QgsGeometryGapCheck::collectErrors( QList &errors, // Get neighboring polygons QgsFeatureIds neighboringIds; - QgsRectangle gapAreaBBox = geom->boundingBox(); + QgsRectangle gapAreaBBox = t.transform( geom->boundingBox() ); QgsFeatureIds intersectIds = featurePool->getIntersects( geom->boundingBox() ); for ( QgsFeatureId id : intersectIds ) @@ -125,7 +127,7 @@ void QgsGeometryGapCheck::collectErrors( QList &errors, if ( QgsGeometryCheckerUtils::sharedEdgeLength( geom, geom2, mContext->reducedTolerance ) > 0 ) { neighboringIds.insert( feature.id() ); - gapAreaBBox.unionRect( geom2->boundingBox() ); + gapAreaBBox.unionRect( t.transform( geom2->boundingBox() ) ); } } if ( neighboringIds.isEmpty() ) diff --git a/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.h b/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.h index 1a5cd3e7d5a..60cf1315453 100644 --- a/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.h +++ b/src/plugins/geometry_checker/checks/qgsgeometrygapcheck.h @@ -39,7 +39,7 @@ class QgsGeometryGapCheckError : public QgsGeometryCheckError delete mGeometry; } - QgsAbstractGeometry *geometry() override { return mGeometry->clone(); } + QgsAbstractGeometry *geometry() const override { return mGeometry->clone(); } const QgsFeatureIds &neighbors() const { return mNeighbors; } bool isEqual( QgsGeometryCheckError *other ) const override @@ -70,7 +70,7 @@ class QgsGeometryGapCheckError : public QgsGeometryCheckError return true; } - QgsRectangle affectedAreaBBox() override + QgsRectangle affectedAreaBBox() const override { return mGapAreaBBox; } diff --git a/src/plugins/geometry_checker/qgsgeometrychecker.cpp b/src/plugins/geometry_checker/qgsgeometrychecker.cpp index 38654e0c789..43059f829db 100644 --- a/src/plugins/geometry_checker/qgsgeometrychecker.cpp +++ b/src/plugins/geometry_checker/qgsgeometrychecker.cpp @@ -14,6 +14,7 @@ * * ***************************************************************************/ +#include "qgscrscache.h" #include "qgsgeometrychecker.h" #include "checks/qgsgeometrycheck.h" #include "utils/qgsfeaturepool.h" @@ -111,6 +112,8 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo for ( const QString &layerId : changes.keys() ) { const QMap> &layerChanges = changes[layerId]; + QgsFeaturePool *featurePool = mContext->featurePools[layerId]; + QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( featurePool->getLayer()->crs().authid(), mContext->crs ); for ( QgsFeatureId id : layerChanges.keys() ) { bool removed = false; @@ -125,10 +128,10 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo if ( !removed ) { QgsFeature f; - if ( mContext->featurePools[layerId]->get( id, f ) ) + if ( featurePool->get( id, f ) ) { recheckFeatures[layerId].insert( id ); - recheckArea.combineExtentWith( f.geometry().boundingBox() ); + recheckArea.combineExtentWith( t.transformBoundingBox( f.geometry().boundingBox() ) ); } } } @@ -149,7 +152,8 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo for ( const QString &layerId : mContext->featurePools.keys() ) { QgsFeaturePool *featurePool = mContext->featurePools[layerId]; - recheckAreaFeatures[layerId] = featurePool->getIntersects( recheckArea ); + QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( mContext->crs, featurePool->getLayer()->crs().authid() ); + recheckAreaFeatures[layerId] = featurePool->getIntersects( t.transform( recheckArea ) ); // If only selected features were checked, confine the recheck areas to the selected features if ( featurePool->getSelectedOnly() ) {