@@ -2878,14 +2878,27 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
2878
2878
return 7 ;
2879
2879
2880
2880
// make sure splitLine is valid
2881
- if ( splitLine.size () < 2 )
2881
+ if (( type () == QGis::Line && splitLine.size () < 1 ) ||
2882
+ ( type () == QGis::Polygon && splitLine.size () < 2 ) )
2882
2883
return 1 ;
2883
2884
2884
2885
newGeometries.clear ();
2885
2886
2886
2887
try
2887
2888
{
2888
- GEOSGeometry *splitLineGeos = createGeosLineString ( splitLine.toVector () );
2889
+ GEOSGeometry* splitLineGeos;
2890
+ if ( splitLine.size () > 1 )
2891
+ {
2892
+ splitLineGeos = createGeosLineString ( splitLine.toVector () );
2893
+ }
2894
+ else if ( splitLine.size () == 1 )
2895
+ {
2896
+ splitLineGeos = createGeosPoint ( splitLine.at ( 0 ) );
2897
+ }
2898
+ else
2899
+ {
2900
+ return 1 ;
2901
+ }
2889
2902
if ( !GEOSisValid ( splitLineGeos ) || !GEOSisSimple ( splitLineGeos ) )
2890
2903
{
2891
2904
GEOSGeom_destroy ( splitLineGeos );
@@ -4549,6 +4562,51 @@ void QgsGeometry::transformVertex( QgsWkbPtr &wkbPtr, const QgsCoordinateTransfo
4549
4562
4550
4563
}
4551
4564
4565
+ GEOSGeometry* QgsGeometry::linePointDifference ( GEOSGeometry* GEOSsplitPoint )
4566
+ {
4567
+ int type = GEOSGeomTypeId ( mGeos );
4568
+ QgsMultiPolyline multiLine;
4569
+
4570
+ if ( type == GEOS_MULTILINESTRING )
4571
+ multiLine = asMultiPolyline ();
4572
+ else if ( type == GEOS_LINESTRING )
4573
+ multiLine = QgsMultiPolyline () << asPolyline ();
4574
+ else
4575
+ return 0 ;
4576
+
4577
+ QgsPoint splitPoint = fromGeosGeom ( GEOSsplitPoint )->asPoint ();
4578
+
4579
+ QgsMultiPolyline lines;
4580
+ QgsPolyline line;
4581
+ QgsPolyline newline;
4582
+
4583
+ // For each part
4584
+ for ( int i = 0 ; i < multiLine.size () ; ++i )
4585
+ {
4586
+ line = multiLine[i];
4587
+ newline = QgsPolyline ();
4588
+ newline.append ( line[0 ] );
4589
+ // For each segment
4590
+ for ( int j = 1 ; j < line.size () - 1 ; ++j )
4591
+ {
4592
+ newline.append ( line[j] );
4593
+ if ( line[j] == splitPoint )
4594
+ {
4595
+ lines.append ( newline );
4596
+ newline = QgsPolyline ();
4597
+ newline.append ( line[j] );
4598
+ }
4599
+ }
4600
+ newline.append ( line.last () );
4601
+ lines.append ( newline );
4602
+ }
4603
+ QgsGeometry* splitLines = fromMultiPolyline ( lines );
4604
+ GEOSGeometry* splitGeom = GEOSGeom_clone ( splitLines->asGeos () );
4605
+
4606
+ return splitGeom;
4607
+
4608
+ }
4609
+
4552
4610
int QgsGeometry::splitLinearGeometry ( GEOSGeometry *splitLine, QList<QgsGeometry*>& newGeometries )
4553
4611
{
4554
4612
if ( !splitLine )
@@ -4569,7 +4627,17 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry
4569
4627
if ( linearIntersect > 0 )
4570
4628
return 3 ;
4571
4629
4572
- GEOSGeometry* splitGeom = GEOSDifference ( mGeos , splitLine );
4630
+ int splitGeomType = GEOSGeomTypeId ( splitLine );
4631
+
4632
+ GEOSGeometry* splitGeom;
4633
+ if ( splitGeomType == GEOS_POINT )
4634
+ {
4635
+ splitGeom = linePointDifference ( splitLine );
4636
+ }
4637
+ else
4638
+ {
4639
+ splitGeom = GEOSDifference ( mGeos , splitLine );
4640
+ }
4573
4641
QVector<GEOSGeometry*> lineGeoms;
4574
4642
4575
4643
int splitType = GEOSGeomTypeId ( splitGeom );
0 commit comments