Skip to content

Commit baf4a39

Browse files
committedOct 23, 2017
[Geometry checker] Make line intersection test and line layer intersection test also report multiple intersections for same line
1 parent 5ded4f8 commit baf4a39

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed
 

‎src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,23 +253,25 @@ namespace QgsGeometryCheckerUtils
253253
return false;
254254
}
255255

256-
bool linesIntersect( const QgsLineString *line1, const QgsLineString *line2, double tol, QgsPoint &inter )
256+
QList<QgsPoint> lineIntersections( const QgsLineString *line1, const QgsLineString *line2, double tol )
257257
{
258+
QList<QgsPoint> intersections;
259+
QgsPoint inter;
258260
for ( int i = 0, n = line1->vertexCount() - 1; i < n; ++i )
259261
{
260262
for ( int j = 0, m = line2->vertexCount() - 1; j < m; ++j )
261263
{
262264
QgsPoint p1 = line1->vertexAt( QgsVertexId( 0, 0, i ) );
263265
QgsPoint p2 = line1->vertexAt( QgsVertexId( 0, 0, i + 1 ) );
264-
QgsPoint q1 = line1->vertexAt( QgsVertexId( 0, 0, j ) );
265-
QgsPoint q2 = line1->vertexAt( QgsVertexId( 0, 0, j + 1 ) );
266+
QgsPoint q1 = line2->vertexAt( QgsVertexId( 0, 0, j ) );
267+
QgsPoint q2 = line2->vertexAt( QgsVertexId( 0, 0, j + 1 ) );
266268
if ( QgsGeometryUtils::segmentIntersection( p1, p2, q1, q2, inter, tol ) )
267269
{
268-
return true;
270+
intersections.append( inter );
269271
}
270272
}
271273
}
272-
return false;
274+
return intersections;
273275
}
274276

275277
double sharedEdgeLength( const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol )

‎src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ namespace QgsGeometryCheckerUtils
133133

134134
bool pointOnLine( const QgsPoint &p, const QgsLineString *line, double tol, bool excludeExtremities = false );
135135

136-
bool linesIntersect( const QgsLineString *line1, const QgsLineString *line2, double tol, QgsPoint &inter );
136+
QList<QgsPoint> lineIntersections( const QgsLineString *line1, const QgsLineString *line2, double tol );
137137

138138
double sharedEdgeLength( const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol );
139139

‎src/analysis/vector/geometry_checker/qgsgeometrylineintersectioncheck.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ void QgsGeometryLineIntersectionCheck::collectErrors( QList<QgsGeometryCheckErro
5959
{
6060
continue;
6161
}
62-
QgsPoint inter;
63-
if ( QgsGeometryCheckerUtils::linesIntersect( line, testLine, mContext->tolerance, inter ) )
62+
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance ) )
6463
{
65-
errors.append( new QgsGeometryCheckError( this, layerFeature, inter ) );
64+
errors.append( new QgsGeometryCheckError( this, layerFeatureA, inter, QgsVertexId(), layerFeatureB.id() ) );
6665
}
6766
}
6867
}

‎src/analysis/vector/geometry_checker/qgsgeometrylinelayerintersectioncheck.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,21 @@ void QgsGeometryLineLayerIntersectionCheck::collectErrors( QList<QgsGeometryChec
4242
const QgsAbstractGeometry *testGeom = checkFeature.geometry();
4343
for ( int jPart = 0, mParts = testGeom->partCount(); jPart < mParts; ++jPart )
4444
{
45-
QgsPoint inter;
4645
const QgsAbstractGeometry *part = QgsGeometryCheckerUtils::getGeomPart( testGeom, jPart );
4746
if ( const QgsLineString *testLine = dynamic_cast<const QgsLineString *>( part ) )
4847
{
49-
if ( QgsGeometryCheckerUtils::linesIntersect( line, testLine, mContext->tolerance, inter ) )
48+
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance ) )
5049
{
51-
errors.append( new QgsGeometryCheckError( this, layerFeature, inter ) );
50+
errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId(), checkFeature.id() ) );
5251
}
5352
}
5453
else if ( const QgsPolygonV2 *polygon = dynamic_cast<const QgsPolygonV2 *>( part ) )
5554
{
5655
for ( const QgsLineString *ring : QgsGeometryCheckerUtils::polygonRings( polygon ) )
5756
{
58-
if ( QgsGeometryCheckerUtils::linesIntersect( ring, testLine, mContext->tolerance, inter ) )
57+
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, ring, mContext->tolerance ) )
5958
{
60-
errors.append( new QgsGeometryCheckError( this, layerFeature, inter ) );
59+
errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId(), checkFeature.id() ) );
6160
}
6261
}
6362
}

0 commit comments

Comments
 (0)
Please sign in to comment.