@@ -59,12 +59,19 @@ def setUpClass(cls):
59
59
sql += str (i + 1 ) + " " + str (j ) + ","
60
60
sql += str (i + 1 ) + " " + str (j + 1 ) + ","
61
61
sql += str (i ) + " " + str (j + 1 ) + ","
62
- sql += str (i ) + " " + str (j )
62
+ sql += str (i ) + " " + str (j )
63
63
sql += ")),"
64
64
sql = sql [:- 1 ] # remove last comma
65
65
sql += ")', 4326))"
66
66
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 )
68
75
con .commit ()
69
76
con .close ()
70
77
@@ -85,16 +92,27 @@ def tearDown(self):
85
92
pass
86
93
87
94
def test_SplitMultipolygon (self ):
88
- """Create spatialite database """
95
+ """Split multipolygon """
89
96
layer = QgsVectorLayer ("dbname=test.sqlite table=test_mpg (geometry)" , "test_mpg" , "spatialite" )
90
97
assert (layer .isValid ())
91
98
assert (layer .hasGeometryType ())
92
- layer .featureCount () == 1 or die ("we should have 1 features" )
99
+ layer .featureCount () == 1 or die ("wrong number of features" )
93
100
layer .startEditing ()
94
101
layer .splitFeatures ([QgsPoint (0.5 , - 0.5 ), QgsPoint (0.5 , 1.5 )], 0 )== 0 or die ("error in split of one polygon of multipolygon" )
95
102
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" )
96
103
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" )
98
116
99
117
100
118
0 commit comments