Skip to content

Commit e79c0e4

Browse files
author
mhugent
committedJun 16, 2009
Replace the hardcoded treshold in line splitting code and added more comment
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10935 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed
 

‎src/core/qgsgeometry.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4794,18 +4794,27 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry
47944794
QVector<GEOSGeometry*> testedGeometries;
47954795
GEOSGeometry* intersectGeom = 0;
47964796

4797-
//hardcoded thresholds
4797+
//Create a small buffer around the original geometry
4798+
//and intersect candidate line segments with the buffer.
4799+
//Then we use the ratio intersection length / segment length to
4800+
//decide if the line segment belongs to the original geometry or
4801+
//if it is part of the splitting line
47984802
double bufferDistance = 0.0000001;
4799-
double intersectThreshold = 0.00001;
48004803

48014804
for ( int i = 0; i < GEOSGetNumGeometries( mergedLines ); i++ )
48024805
{
48034806
const GEOSGeometry *testing = GEOSGetGeometryN( mergedLines, i );
48044807
intersectGeom = GEOSIntersection( mGeos, GEOSBuffer( testing, bufferDistance, DEFAULT_QUADRANT_SEGMENTS ) );
48054808
double len;
48064809
GEOSLength( intersectGeom, &len );
4807-
if ( len > intersectThreshold )
4810+
double testingLen;
4811+
GEOSLength( testing, &testingLen);
4812+
double ratio = len / testingLen;
4813+
//the ratios for geometries that belong to the original line are usually close to 1
4814+
if ( ratio >= 0.5 && ratio <= 1.5)
4815+
{
48084816
testedGeometries << GEOSGeom_clone( testing );
4817+
}
48094818
GEOSGeom_destroy( intersectGeom );
48104819
}
48114820

0 commit comments

Comments
 (0)
Please sign in to comment.