Skip to content
Permalink
Browse files

[Geometry checker] Make line intersection test and line layer interse…

…ction test also report multiple intersections for same line
  • Loading branch information
manisandro committed Sep 28, 2017
1 parent 5ded4f8 commit baf4a39c684dcc948c49204600075560a3ae032f
@@ -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 )
@@ -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 );

@@ -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() ) );
}
}
}
@@ -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() ) );
}
}
}

0 comments on commit baf4a39

Please sign in to comment.
You can’t perform that action at this time.