Skip to content
Permalink
Browse files
Compare square distance with square tolerance in duplicated node check
  • Loading branch information
mhugent authored and nyalldawson committed Nov 2, 2021
1 parent 9693f8d commit af8f05a3379f3401eead7a1434a6aa617e338d28
Showing with 25 additions and 1 deletion.
  1. +3 −1 src/analysis/vector/geometry_checker/qgsgeometryduplicatenodescheck.cpp
  2. +22 −0 tests/src/geometry_checker/testqgsgeometrychecks.cpp
@@ -25,6 +25,8 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( const QMap<QString, QgsFeatu

const QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds( featurePools ) : ids.toMap();
const QgsGeometryCheckerUtils::LayerFeatures layerFeatures( featurePools, featureIds, compatibleGeometryTypes(), feedback, mContext );
const double sqrTolerance = mContext->tolerance * mContext->tolerance;

for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry().constGet();
@@ -39,7 +41,7 @@ void QgsGeometryDuplicateNodesCheck::collectErrors( const QMap<QString, QgsFeatu
{
const QgsPoint pi = geom->vertexAt( QgsVertexId( iPart, iRing, iVert ) );
const QgsPoint pj = geom->vertexAt( QgsVertexId( iPart, iRing, jVert ) );
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) < mContext->tolerance )
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) < sqrTolerance )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, pj, QgsVertexId( iPart, iRing, jVert ) ) );
}
@@ -83,6 +83,7 @@ class TestQgsGeometryChecks: public QObject
void testDegeneratePolygonCheck();
void testDuplicateCheck();
void testDuplicateNodesCheck();
void testDuplicateNodesCheckTolerance();
void testFollowBoundariesCheck();
void testGapCheck();
void testAllowedGaps();
@@ -490,6 +491,27 @@ void TestQgsGeometryChecks::testDuplicateNodesCheck()
cleanupTestContext( testContext );
}

void TestQgsGeometryChecks::testDuplicateNodesCheckTolerance()
{
QTemporaryDir dir;
QMap<QString, QString> layers;
layers.insert( "line_layer.shp", "" );
auto testContext = createTestContext( dir, layers, QgsCoordinateReferenceSystem( "EPSG:4326" ), 3 );

QList<QgsGeometryCheckError *> checkErrors;
QStringList messages;
QgsFeedback feedback;

const QgsGeometryDuplicateNodesCheck check( testContext.first, QVariantMap() );
check.collectErrors( testContext.second, checkErrors, messages, &feedback );
listErrors( checkErrors, messages );

int nErrors = checkErrors.size();
QCOMPARE( nErrors, 3 );

cleanupTestContext( testContext );
}

void TestQgsGeometryChecks::testFollowBoundariesCheck()
{
QTemporaryDir dir;

0 comments on commit af8f05a

Please sign in to comment.