Skip to content

Commit e7efde2

Browse files
committedOct 23, 2017
[Geometry checker] Make checks report affected are in selected crs
1 parent 2a92bfb commit e7efde2

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed
 

‎src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* *
1414
***************************************************************************/
1515

16+
#include "qgscrscache.h"
1617
#include "qgsgeometrycollection.h"
1718
#include "qgscurvepolygon.h"
1819
#include "qgsgeometrycheck.h"
@@ -41,7 +42,7 @@ QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check, con
4142
, mStatus( StatusPending )
4243
{}
4344

44-
QgsAbstractGeometry *QgsGeometryCheckError::geometry()
45+
QgsAbstractGeometry *QgsGeometryCheckError::geometry() const
4546
{
4647
QgsFeature f;
4748
if ( mCheck->getContext()->featurePools[ layerId() ]->get( featureId(), f ) && f.hasGeometry() )
@@ -53,6 +54,20 @@ QgsAbstractGeometry *QgsGeometryCheckError::geometry()
5354
return nullptr;
5455
}
5556

57+
QgsRectangle QgsGeometryCheckError::affectedAreaBBox() const
58+
{
59+
QgsAbstractGeometry *geom = geometry();
60+
if ( !geom )
61+
{
62+
return QgsRectangle();
63+
}
64+
QString srcCrs = mCheck->getContext()->featurePools[ layerId() ]->getLayer()->crs().authid();
65+
QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( srcCrs, mCheck->getContext()->crs );
66+
QgsRectangle rect = t.transformBoundingBox( geom->boundingBox() );
67+
delete geom;
68+
return rect;
69+
}
70+
5671
bool QgsGeometryCheckError::handleChanges( const QgsGeometryCheck::Changes &changes )
5772
{
5873
if ( status() == StatusObsolete )

‎src/plugins/geometry_checker/checks/qgsgeometrycheck.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ class QgsGeometryCheckError
105105
QgsVertexId vidx = QgsVertexId(),
106106
const QVariant &value = QVariant(),
107107
ValueType valueType = ValueOther );
108-
virtual ~QgsGeometryCheckError() = default;
108+
virtual ~QgsGeometryCheckError() {}
109109

110110
const QgsGeometryCheckError &operator=( const QgsGeometryCheckError & ) = delete;
111111

112112
const QgsGeometryCheck *check() const { return mCheck; }
113113
const QString &layerId() const { return mLayerId; }
114114
QgsFeatureId featureId() const { return mFeatureId; }
115-
virtual QgsAbstractGeometry *geometry();
116-
virtual QgsRectangle affectedAreaBBox() { return geometry() ? geometry()->boundingBox() : QgsRectangle(); }
115+
virtual QgsAbstractGeometry *geometry() const;
116+
virtual QgsRectangle affectedAreaBBox() const;
117117
virtual QString description() const { return mCheck->errorDescription(); }
118118
const QgsPoint &location() const { return mErrorLocation; }
119119
QVariant value() const { return mValue; }

‎src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* *
1414
***************************************************************************/
1515

16+
#include "qgscrscache.h"
1617
#include "qgsgeometryengine.h"
1718
#include "qgsgeometrygapcheck.h"
1819
#include "qgsgeometrycollection.h"
@@ -28,6 +29,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,
2829
for ( const QString &layerId : featureIds.keys() )
2930
{
3031
QgsFeaturePool *featurePool = mContext->featurePools[ layerId ];
32+
QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( featurePool->getLayer()->crs().authid(), mContext->crs );
3133
if ( !getCompatibility( featurePool->getLayer()->geometryType() ) )
3234
{
3335
continue;
@@ -110,7 +112,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,
110112

111113
// Get neighboring polygons
112114
QgsFeatureIds neighboringIds;
113-
QgsRectangle gapAreaBBox = geom->boundingBox();
115+
QgsRectangle gapAreaBBox = t.transform( geom->boundingBox() );
114116
QgsFeatureIds intersectIds = featurePool->getIntersects( geom->boundingBox() );
115117

116118
for ( QgsFeatureId id : intersectIds )
@@ -125,7 +127,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &errors,
125127
if ( QgsGeometryCheckerUtils::sharedEdgeLength( geom, geom2, mContext->reducedTolerance ) > 0 )
126128
{
127129
neighboringIds.insert( feature.id() );
128-
gapAreaBBox.unionRect( geom2->boundingBox() );
130+
gapAreaBBox.unionRect( t.transform( geom2->boundingBox() ) );
129131
}
130132
}
131133
if ( neighboringIds.isEmpty() )

‎src/plugins/geometry_checker/checks/qgsgeometrygapcheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class QgsGeometryGapCheckError : public QgsGeometryCheckError
3939
delete mGeometry;
4040
}
4141

42-
QgsAbstractGeometry *geometry() override { return mGeometry->clone(); }
42+
QgsAbstractGeometry *geometry() const override { return mGeometry->clone(); }
4343
const QgsFeatureIds &neighbors() const { return mNeighbors; }
4444

4545
bool isEqual( QgsGeometryCheckError *other ) const override
@@ -70,7 +70,7 @@ class QgsGeometryGapCheckError : public QgsGeometryCheckError
7070
return true;
7171
}
7272

73-
QgsRectangle affectedAreaBBox() override
73+
QgsRectangle affectedAreaBBox() const override
7474
{
7575
return mGapAreaBBox;
7676
}

‎src/plugins/geometry_checker/qgsgeometrychecker.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* *
1515
***************************************************************************/
1616

17+
#include "qgscrscache.h"
1718
#include "qgsgeometrychecker.h"
1819
#include "checks/qgsgeometrycheck.h"
1920
#include "utils/qgsfeaturepool.h"
@@ -111,6 +112,8 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
111112
for ( const QString &layerId : changes.keys() )
112113
{
113114
const QMap<QgsFeatureId, QList<QgsGeometryCheck::Change>> &layerChanges = changes[layerId];
115+
QgsFeaturePool *featurePool = mContext->featurePools[layerId];
116+
QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( featurePool->getLayer()->crs().authid(), mContext->crs );
114117
for ( QgsFeatureId id : layerChanges.keys() )
115118
{
116119
bool removed = false;
@@ -125,10 +128,10 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
125128
if ( !removed )
126129
{
127130
QgsFeature f;
128-
if ( mContext->featurePools[layerId]->get( id, f ) )
131+
if ( featurePool->get( id, f ) )
129132
{
130133
recheckFeatures[layerId].insert( id );
131-
recheckArea.combineExtentWith( f.geometry().boundingBox() );
134+
recheckArea.combineExtentWith( t.transformBoundingBox( f.geometry().boundingBox() ) );
132135
}
133136
}
134137
}
@@ -149,7 +152,8 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
149152
for ( const QString &layerId : mContext->featurePools.keys() )
150153
{
151154
QgsFeaturePool *featurePool = mContext->featurePools[layerId];
152-
recheckAreaFeatures[layerId] = featurePool->getIntersects( recheckArea );
155+
QgsCoordinateTransform t = QgsCoordinateTransformCache::instance()->transform( mContext->crs, featurePool->getLayer()->crs().authid() );
156+
recheckAreaFeatures[layerId] = featurePool->getIntersects( t.transform( recheckArea ) );
153157
// If only selected features were checked, confine the recheck areas to the selected features
154158
if ( featurePool->getSelectedOnly() )
155159
{

0 commit comments

Comments
 (0)
Please sign in to comment.