Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Geometry checker] Don't self-compare features in contained check
  • Loading branch information
manisandro committed Oct 23, 2017
1 parent 2b01ccf commit 5c84840
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Expand Up @@ -28,10 +28,14 @@ void QgsGeometryContainedCheck::collectErrors( QList<QgsGeometryCheckError *> &e
QgsGeometryCheckerUtils::LayerFeatures layerFeaturesB( mContext->featurePools, featureIds.keys(), bboxA, mCompatibleGeometryTypes );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeatureB : layerFeaturesB )
{
if ( layerFeatureA == layerFeatureB )
{
continue;
}
QString errMsg;
if ( geomEngineA->within( *layerFeatureB.geometry(), &errMsg ) )
{
errors.append( new QgsGeometryContainedCheckError( this, layerFeatureA, layerFeatureA.geometry()->centroid(), qMakePair( layerFeatureB.layer().id(), layerFeatureB.feature().id() ) ) );
errors.append( new QgsGeometryContainedCheckError( this, layerFeatureA, layerFeatureA.geometry()->centroid(), layerFeatureB ) );
}
else if ( !errMsg.isEmpty() )
{
Expand Down
Expand Up @@ -24,10 +24,10 @@ class QgsGeometryContainedCheckError : public QgsGeometryCheckError
QgsGeometryContainedCheckError( const QgsGeometryCheck *check,
const QgsGeometryCheckerUtils::LayerFeature &layerFeature,
const QgsPointXY &errorLocation,
const QPair<QString, QgsFeatureId> &containingFeature
const QgsGeometryCheckerUtils::LayerFeature &containingFeature
)
: QgsGeometryCheckError( check, layerFeature, errorLocation, QgsVertexId(), QString( "%1:%2" ).arg( containingFeature.first ).arg( containingFeature.second ), ValueOther )
, mContainingFeature( containingFeature )
: QgsGeometryCheckError( check, layerFeature, errorLocation, QgsVertexId(), containingFeature.id(), ValueOther )
, mContainingFeature( qMakePair( containingFeature.layer().id(), containingFeature.feature().id() ) )
{ }
const QPair<QString, QgsFeatureId> &containingFeature() const { return mContainingFeature; }

Expand All @@ -38,7 +38,7 @@ class QgsGeometryContainedCheckError : public QgsGeometryCheckError
static_cast<QgsGeometryContainedCheckError *>( other )->containingFeature() == containingFeature();
}

virtual QString description() const override { return QApplication::translate( "QgsGeometryContainedCheckError", "Within %1:%2" ).arg( mContainingFeature.first ).arg( mContainingFeature.second ); }
virtual QString description() const override { return QApplication::translate( "QgsGeometryContainedCheckError", "Within feature" ); }

private:
QPair<QString, QgsFeatureId> mContainingFeature;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/geometry_checker/utils/qgsgeometrycheckerutils.h
Expand Up @@ -61,6 +61,8 @@ namespace QgsGeometryCheckerUtils
const QgsAbstractGeometry *geometry() const { return mGeometry; }
QString geometryCrs() const { return mMapCrs ? mLayerToMapTransform.destinationCrs().authid() : mLayerToMapTransform.sourceCrs().authid(); }
QString id() const { return QString( "%1:%2" ).arg( mLayer->id() ).arg( mFeature.id() ); }
bool operator==( const LayerFeature &other ) const { return layer().id() == other.layer().id() && feature().id() == other.feature().id(); }
bool operator!=( const LayerFeature &other ) const { return layer().id() != other.layer().id() || feature().id() != other.feature().id(); }

private:
const QgsVectorLayer *mLayer = nullptr;
Expand Down

0 comments on commit 5c84840

Please sign in to comment.