mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-23 00:05:43 -04:00
[Geometry checker] Make checks report affected are in selected crs
This commit is contained in:
parent
2a92bfb2c9
commit
e7efde2c31
@ -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 )
|
||||
|
@ -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; }
|
||||
|
@ -13,6 +13,7 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgscrscache.h"
|
||||
#include "qgsgeometryengine.h"
|
||||
#include "qgsgeometrygapcheck.h"
|
||||
#include "qgsgeometrycollection.h"
|
||||
@ -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;
|
||||
@ -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 )
|
||||
@ -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() )
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<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;
|
||||
@ -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() )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user