Skip to content

Commit

Permalink
[Geometry checker] Make line intersection test and line layer interse…
Browse files Browse the repository at this point in the history
…ction test also report multiple intersections for same line
  • Loading branch information
manisandro committed Oct 23, 2017
1 parent 5ded4f8 commit baf4a39
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 7 additions & 5 deletions src/analysis/vector/geometry_checker/qgsgeometrycheckerutils.cpp
Expand Up @@ -253,23 +253,25 @@ namespace QgsGeometryCheckerUtils
return false;
}

bool linesIntersect( const QgsLineString *line1, const QgsLineString *line2, double tol, QgsPoint &inter )
QList<QgsPoint> lineIntersections( const QgsLineString *line1, const QgsLineString *line2, double tol )
{
QList<QgsPoint> intersections;
QgsPoint inter;
for ( int i = 0, n = line1->vertexCount() - 1; i < n; ++i )
{
for ( int j = 0, m = line2->vertexCount() - 1; j < m; ++j )
{
QgsPoint p1 = line1->vertexAt( QgsVertexId( 0, 0, i ) );
QgsPoint p2 = line1->vertexAt( QgsVertexId( 0, 0, i + 1 ) );
QgsPoint q1 = line1->vertexAt( QgsVertexId( 0, 0, j ) );
QgsPoint q2 = line1->vertexAt( QgsVertexId( 0, 0, j + 1 ) );
QgsPoint q1 = line2->vertexAt( QgsVertexId( 0, 0, j ) );
QgsPoint q2 = line2->vertexAt( QgsVertexId( 0, 0, j + 1 ) );
if ( QgsGeometryUtils::segmentIntersection( p1, p2, q1, q2, inter, tol ) )
{
return true;
intersections.append( inter );
}
}
}
return false;
return intersections;
}

double sharedEdgeLength( const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol )
Expand Down
Expand Up @@ -133,7 +133,7 @@ namespace QgsGeometryCheckerUtils

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

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

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

Expand Down
Expand Up @@ -59,10 +59,9 @@ void QgsGeometryLineIntersectionCheck::collectErrors( QList<QgsGeometryCheckErro
{
continue;
}
QgsPoint inter;
if ( QgsGeometryCheckerUtils::linesIntersect( line, testLine, mContext->tolerance, inter ) )
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance ) )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, inter ) );
errors.append( new QgsGeometryCheckError( this, layerFeatureA, inter, QgsVertexId(), layerFeatureB.id() ) );
}
}
}
Expand Down
Expand Up @@ -42,22 +42,21 @@ void QgsGeometryLineLayerIntersectionCheck::collectErrors( QList<QgsGeometryChec
const QgsAbstractGeometry *testGeom = checkFeature.geometry();
for ( int jPart = 0, mParts = testGeom->partCount(); jPart < mParts; ++jPart )
{
QgsPoint inter;
const QgsAbstractGeometry *part = QgsGeometryCheckerUtils::getGeomPart( testGeom, jPart );
if ( const QgsLineString *testLine = dynamic_cast<const QgsLineString *>( part ) )
{
if ( QgsGeometryCheckerUtils::linesIntersect( line, testLine, mContext->tolerance, inter ) )
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, testLine, mContext->tolerance ) )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, inter ) );
errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId(), checkFeature.id() ) );
}
}
else if ( const QgsPolygonV2 *polygon = dynamic_cast<const QgsPolygonV2 *>( part ) )
{
for ( const QgsLineString *ring : QgsGeometryCheckerUtils::polygonRings( polygon ) )
{
if ( QgsGeometryCheckerUtils::linesIntersect( ring, testLine, mContext->tolerance, inter ) )
for ( const QgsPoint &inter : QgsGeometryCheckerUtils::lineIntersections( line, ring, mContext->tolerance ) )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, inter ) );
errors.append( new QgsGeometryCheckError( this, layerFeature, inter, QgsVertexId(), checkFeature.id() ) );
}
}
}
Expand Down

0 comments on commit baf4a39

Please sign in to comment.