Skip to content

Commit 2377f17

Browse files
committed
code cleanup
1 parent a14744c commit 2377f17

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/core/qgsgeometry.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,18 +2878,10 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
28782878
return 7;
28792879

28802880
//make sure splitLine is valid
2881-
if ( splitLine.size() < 1 )
2881+
if (( type() == QGis::Line && splitLine.size() < 1 ) ||
2882+
( type() == QGis::Polygon && splitLine.size() < 2 ) )
28822883
return 1;
28832884

2884-
// Treat the special case of a single point to split a line without geos
2885-
if ( splitLine.size() == 1 )
2886-
{
2887-
//A point cannot split a polygon
2888-
if ( type() == QGis::Polygon )
2889-
return 1;
2890-
//return splitLinearGeometryAtPoint( splitLine[0], newGeometries );
2891-
}
2892-
28932885
newGeometries.clear();
28942886

28952887
try
@@ -4584,8 +4576,6 @@ GEOSGeometry* QgsGeometry::linePointDifference( GEOSGeometry* GEOSsplitPoint )
45844576

45854577
QgsPoint splitPoint = fromGeosGeom( GEOSsplitPoint )->asPoint();
45864578

4587-
QgsPoint p1, p2;
4588-
QgsGeometry* g;
45894579
QgsMultiPolyline lines;
45904580
QgsPolyline line;
45914581
QgsPolyline newline;
@@ -4594,10 +4584,10 @@ GEOSGeometry* QgsGeometry::linePointDifference( GEOSGeometry* GEOSsplitPoint )
45944584
for ( int i = 0; i < multiLine.size() ; ++i )
45954585
{
45964586
line = multiLine[i];
4597-
//For each segment
45984587
newline = QgsPolyline();
4599-
newline.append(line[0]);
4600-
for ( int j = 1; j < line.size()-1 ; ++j )
4588+
newline.append( line[0] );
4589+
//For each segment
4590+
for ( int j = 1; j < line.size() - 1 ; ++j )
46014591
{
46024592
newline.append( line[j] );
46034593
if ( line[j] == splitPoint )
@@ -4628,24 +4618,25 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry
46284618
if ( !mGeos )
46294619
return 5;
46304620

4621+
//first test if linestring intersects geometry. If not, return straight away
4622+
if ( !GEOSIntersects( splitLine, mGeos ) )
4623+
return 1;
46314624

46324625
//check that split line has no linear intersection
46334626
int linearIntersect = GEOSRelatePattern( mGeos, splitLine, "1********" );
46344627
if ( linearIntersect > 0 )
46354628
return 3;
46364629

46374630
int splitGeomType = GEOSGeomTypeId( splitLine );
4638-
//first test if linestring intersects geometry. If not, return straight away
4639-
if ( splitGeomType == GEOS_LINESTRING && !GEOSIntersects( splitLine, mGeos ) )
4640-
return 1;
4631+
46414632
GEOSGeometry* splitGeom;
4642-
if ( splitGeomType == GEOS_LINESTRING )
4633+
if ( splitGeomType == GEOS_POINT )
46434634
{
4644-
splitGeom = GEOSDifference( mGeos, splitLine );
4635+
splitGeom = linePointDifference( splitLine );
46454636
}
46464637
else
46474638
{
4648-
splitGeom = linePointDifference( splitLine );
4639+
splitGeom = GEOSDifference( mGeos, splitLine );
46494640
}
46504641
QVector<GEOSGeometry*> lineGeoms;
46514642

0 commit comments

Comments
 (0)