Skip to content

Commit 5256b80

Browse files
committed
- fix issue 7244
1 parent 20b45c3 commit 5256b80

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/core/qgsgeometry.cpp

+8-16
Original file line numberDiff line numberDiff line change
@@ -5401,22 +5401,6 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr
54015401
return 2; //an error occured during noding
54025402
}
54035403

5404-
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
5405-
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=1)))
5406-
GEOSGeometry *cutEdges = GEOSPolygonizer_getCutEdges( &nodedGeometry, 1 );
5407-
if ( cutEdges )
5408-
{
5409-
if ( numberOfGeometries( cutEdges ) > 0 )
5410-
{
5411-
GEOSGeom_destroy( cutEdges );
5412-
GEOSGeom_destroy( nodedGeometry );
5413-
return 3;
5414-
}
5415-
5416-
GEOSGeom_destroy( cutEdges );
5417-
}
5418-
#endif
5419-
54205404
GEOSGeometry *polygons = GEOSPolygonize( &nodedGeometry, 1 );
54215405
if ( !polygons || numberOfGeometries( polygons ) == 0 )
54225406
{
@@ -5486,6 +5470,14 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr
54865470
mDirtyWkb = true;
54875471
}
54885472

5473+
for ( int i = 1; i < testedGeometries.size(); ++i )
5474+
{
5475+
if ( GEOSisValid( testedGeometries[i] ) != 1 )
5476+
{
5477+
return 3;
5478+
}
5479+
}
5480+
54895481
for ( int i = 1; i < testedGeometries.size(); ++i )
54905482
{
54915483
newGeometries << fromGeosGeom( testedGeometries[i] );

tests/src/python/test_qgsissue7244.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,19 @@ def setUpClass(cls):
5959
sql += str(i+1) + " " + str(j) + ","
6060
sql += str(i+1) + " " + str(j+1) + ","
6161
sql += str(i) + " " + str(j+1) + ","
62-
sql += str(i) + " " + str(j)
62+
sql += str(i) + " " + str(j)
6363
sql += ")),"
6464
sql = sql[:-1] # remove last comma
6565
sql += ")', 4326))"
6666
cur.execute(sql)
67-
67+
68+
sql = "CREATE TABLE test_pg (id SERIAL PRIMARY KEY, name STRING NOT NULL)"
69+
cur.execute(sql)
70+
sql = "SELECT AddGeometryColumn('test_pg', 'geometry', 4326, 'POLYGON', 'XY')"
71+
cur.execute(sql)
72+
sql = "INSERT INTO test_pg (name, geometry) "
73+
sql += "VALUES ('polygon with interior ring', GeomFromText('POLYGON((0 0,3 0,3 3,0 3,0 0),(1 1,1 2,2 2,2 1,1 1))', 4326))"
74+
cur.execute(sql)
6875
con.commit()
6976
con.close()
7077

@@ -85,16 +92,27 @@ def tearDown(self):
8592
pass
8693

8794
def test_SplitMultipolygon(self):
88-
"""Create spatialite database"""
95+
"""Split multipolygon"""
8996
layer = QgsVectorLayer("dbname=test.sqlite table=test_mpg (geometry)", "test_mpg", "spatialite")
9097
assert(layer.isValid())
9198
assert(layer.hasGeometryType())
92-
layer.featureCount() == 1 or die("we should have 1 features")
99+
layer.featureCount() == 1 or die("wrong number of features")
93100
layer.startEditing()
94101
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split of one polygon of multipolygon")
95102
layer.splitFeatures([QgsPoint(2.5, -0.5), QgsPoint(2.5, 4)], 0)==0 or die("error in split of two polygons of multipolygon at a time")
96103
layer.commitChanges() or die("this commit should work")
97-
#layer.featureCount() == 9 or die("we should have 9 features after 2 split")
104+
layer.featureCount() == 7 or die("wrong number of features after 2 split")
105+
106+
def test_SplitTruToCreateCutEdge(self):
107+
"""Try to creat a cut edge"""
108+
layer = QgsVectorLayer("dbname=test.sqlite table=test_pg (geometry)", "test_pg", "spatialite")
109+
assert(layer.isValid())
110+
assert(layer.hasGeometryType())
111+
layer.featureCount() == 1 or die("wrong number of features")
112+
layer.startEditing()
113+
layer.splitFeatures([QgsPoint(1.5, -0.5), QgsPoint(1.5, 1.5)], 0)==0 or die("error when trying to create an invalid polygon in split")
114+
layer.commitChanges() or die("this commit should work")
115+
layer.featureCount() == 1 or die("wrong number of features, polygon should be unafected by cut")
98116

99117

100118

0 commit comments

Comments
 (0)