Skip to content

Commit

Permalink
[Geometry checker] Make checks report affected are in selected crs
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 23, 2017
1 parent 2a92bfb commit e7efde2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
17 changes: 16 additions & 1 deletion src/plugins/geometry_checker/checks/qgsgeometrycheck.cpp
Expand Up @@ -13,6 +13,7 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometrycollection.h"
#include "qgscurvepolygon.h"
#include "qgsgeometrycheck.h"
Expand Down Expand Up @@ -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() )
Expand All @@ -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 )
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/geometry_checker/checks/qgsgeometrycheck.h
Expand Up @@ -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; }
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/geometry_checker/checks/qgsgeometrygapcheck.cpp
Expand Up @@ -13,6 +13,7 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometryengine.h"
#include "qgsgeometrygapcheck.h"
#include "qgsgeometrycollection.h"
Expand All @@ -28,6 +29,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &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;
Expand Down Expand Up @@ -110,7 +112,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &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 )
Expand All @@ -125,7 +127,7 @@ void QgsGeometryGapCheck::collectErrors( QList<QgsGeometryCheckError *> &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() )
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/geometry_checker/checks/qgsgeometrygapcheck.h
Expand Up @@ -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
Expand Down Expand Up @@ -70,7 +70,7 @@ class QgsGeometryGapCheckError : public QgsGeometryCheckError
return true;
}

QgsRectangle affectedAreaBBox() override
QgsRectangle affectedAreaBBox() const override
{
return mGapAreaBBox;
}
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/geometry_checker/qgsgeometrychecker.cpp
Expand Up @@ -14,6 +14,7 @@
* *
***************************************************************************/

#include "qgscrscache.h"
#include "qgsgeometrychecker.h"
#include "checks/qgsgeometrycheck.h"
#include "utils/qgsfeaturepool.h"
Expand Down Expand Up @@ -111,6 +112,8 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
for ( const QString &layerId : changes.keys() )
{
const QMap<QgsFeatureId, QList<QgsGeometryCheck::Change>> &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;
Expand All @@ -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() ) );
}
}
}
Expand All @@ -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() )
{
Expand Down

0 comments on commit e7efde2

Please sign in to comment.