@@ -216,7 +216,6 @@ def testCrosses(self):
216
216
("True" , crossesGeom ))
217
217
assert crossesGeom == True , myMessage
218
218
219
- @expectedFailure
220
219
def testSimplifyIssue4189 (self ):
221
220
"""Test we can simplify a complex geometry.
222
221
@@ -752,16 +751,16 @@ def testMultipoint(self):
752
751
if not TestQgsGeometry .wkbPtr :
753
752
return
754
753
755
- # #9423
756
- points = [ QgsPoint (10 , 30 ), QgsPoint (40 , 20 ), QgsPoint (30 ,10 ), QgsPoint (20 ,10 ) ]
757
- wkt = "MULTIPOINT (10 30, 40 20, 30 10, 20 10)"
758
- multipoint = QgsGeometry .fromWkt (wkt )
759
- assert multipoint .isMultipart (), "Expected MULTIPOINT to be multipart"
760
- assert multipoint .wkbType () == QGis .WKBMultiPoint , "Expected wkbType to be WKBMultipoint"
761
- i = 0
762
- for p in multipoint .asMultiPoint ():
763
- assert p == points [i ], "Expected %s at %d, got %s" % (points [i ].toString (), i , p .toString ())
764
- i += 1
754
+ # #9423
755
+ points = [ QgsPoint (10 , 30 ), QgsPoint (40 , 20 ), QgsPoint (30 ,10 ), QgsPoint (20 ,10 ) ]
756
+ wkt = "MULTIPOINT (10 30, 40 20, 30 10, 20 10)"
757
+ multipoint = QgsGeometry .fromWkt (wkt )
758
+ assert multipoint .isMultipart (), "Expected MULTIPOINT to be multipart"
759
+ assert multipoint .wkbType () == QGis .WKBMultiPoint , "Expected wkbType to be WKBMultipoint"
760
+ i = 0
761
+ for p in multipoint .asMultiPoint ():
762
+ assert p == points [i ], "Expected %s at %d, got %s" % (points [i ].toString (), i , p .toString ())
763
+ i += 1
765
764
766
765
multipoint = QgsGeometry .fromWkt ( "MULTIPOINT(5 5)" )
767
766
assert multipoint .vertexAt ( 0 ) == QgsPoint (5 ,5 ), "MULTIPOINT fromWkt failed"
@@ -802,8 +801,8 @@ def testMultipoint(self):
802
801
def testMoveVertex (self ):
803
802
multipoint = QgsGeometry .fromWkt ( "MULTIPOINT(5 0,0 0,0 4,5 4,5 1,1 1,1 3,4 3,4 2,2 2)" )
804
803
for i in range (0 ,10 ):
805
- assert multipoint .moveVertex ( i + 1 , i + 1 , i ), "move vertex %d failed" % i
806
- expwkt = "MULTIPOINT(1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9, 10 10)"
804
+ assert multipoint .moveVertex ( i + 1 , - 1 - i , i ), "move vertex %d failed" % i
805
+ expwkt = "MULTIPOINT(1 - 1, 2 - 2, 3 - 3, 4 - 4, 5 - 5, 6 - 6, 7 - 7, 8 - 8, 9 - 9, 10 - 10)"
807
806
wkt = multipoint .exportToWkt ()
808
807
assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
809
808
@@ -833,12 +832,15 @@ def testMoveVertex(self):
833
832
wkt = polygon .exportToWkt ()
834
833
assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
835
834
836
- assert polygon .moveVertex ( 1 , 1 , 0 ), "move vertex failed"
837
- expwkt = "MULTIPOLYGON(((1 1,1 0,1 1,2 1,2 2,0 2,1 1)),((4 0,5 0,6 2,3 2,3 1,4 1,4 0)))"
838
-
839
- assert polygon .moveVertex ( 1 , 1 , 8 ), "move vertex failed"
840
- expwkt = "MULTIPOLYGON(((1 1,1 0,1 1,2 1,2 2,0 2,1 1)),((1 1,5 0,6 2,3 2,3 1,4 1,1 1)))"
835
+ assert polygon .moveVertex ( 1 , 2 , 0 ), "move vertex failed"
836
+ expwkt = "MULTIPOLYGON(((1 2,1 0,1 1,2 1,2 2,0 2,1 2)),((4 0,5 0,6 2,3 2,3 1,4 1,4 0)))"
837
+ wkt = polygon .exportToWkt ()
838
+ assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
841
839
840
+ assert polygon .moveVertex ( 2 , 1 , 7 ), "move vertex failed"
841
+ expwkt = "MULTIPOLYGON(((1 2,1 0,1 1,2 1,2 2,0 2,1 2)),((2 1,5 0,6 2,3 2,3 1,4 1,2 1)))"
842
+ wkt = polygon .exportToWkt ()
843
+ assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
842
844
843
845
def testDeleteVertex (self ):
844
846
# 2-+-+-+-+-3
@@ -957,27 +959,26 @@ def testInsertVertex(self):
957
959
958
960
def testTranslate (self ):
959
961
point = QgsGeometry .fromWkt ( "POINT(1 1)" )
960
- assert point .translate ( 1 , 1 )== 0 , "Translate failed"
961
- expwkt = "POINT(2 2 )"
962
+ assert point .translate ( 1 , 2 )== 0 , "Translate failed"
963
+ expwkt = "POINT(2 3 )"
962
964
wkt = point .exportToWkt ()
963
965
assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
964
966
965
967
point = QgsGeometry .fromWkt ( "MULTIPOINT(1 1,2 2,3 3)" )
966
- assert point .translate ( 1 , 1 )== 0 , "Translate failed"
967
- expwkt = "MULTIPOINT(2 2 , 3 3 , 4 4 )"
968
+ assert point .translate ( 1 , 2 )== 0 , "Translate failed"
969
+ expwkt = "MULTIPOINT(2 3 , 3 4 , 4 5 )"
968
970
wkt = point .exportToWkt ()
969
971
assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
970
972
971
973
linestring = QgsGeometry .fromWkt ( "LINESTRING(1 0,2 0)" )
972
-
973
- assert linestring .translate ( 1 , 1 )== 0 , "Translate failed"
974
- expwkt = "LINESTRING(2 1, 3 1)"
974
+ assert linestring .translate ( 1 , 2 )== 0 , "Translate failed"
975
+ expwkt = "LINESTRING(2 2, 3 2)"
975
976
wkt = linestring .exportToWkt ()
976
977
assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
977
978
978
979
polygon = QgsGeometry .fromWkt ( "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))" )
979
- assert polygon .translate ( 1 , 1 )== 0 , "Translate failed"
980
- expwkt = "MULTIPOLYGON(((1 1 ,2 1 ,2 2 ,3 2 ,3 3 ,1 3 ,1 1 )),((5 1 ,6 1 ,6 1 ,4 3 ,4 2 ,5 2 ,5 1 )))"
980
+ assert polygon .translate ( 1 , 2 )== 0 , "Translate failed"
981
+ expwkt = "MULTIPOLYGON(((1 2 ,2 2 ,2 3 ,3 3 ,3 4 ,1 4 ,1 2 )),((5 2 ,6 2 ,6 2 ,4 4 ,4 3 ,5 3 ,5 2 )))"
981
982
wkt = polygon .exportToWkt ()
982
983
983
984
ct = QgsCoordinateTransform ()
@@ -1077,5 +1078,47 @@ def testBoundingBox(self):
1077
1078
bb = polygon .boundingBox ()
1078
1079
assert expbb == bb , "Expected:\n %s\n Got:\n %s\n " % (expbb .toString (), bb .toString ())
1079
1080
1081
+ def testAddPart (self ):
1082
+ # 2-3 6-+-7
1083
+ # | | | |
1084
+ # 0-1 4 5 8-9
1085
+ points = [
1086
+ [ QgsPoint (0 ,0 ), QgsPoint (1 ,0 ), QgsPoint (1 ,1 ), QgsPoint (2 ,1 ), QgsPoint (2 ,0 ), ],
1087
+ [ QgsPoint (3 ,0 ), QgsPoint (3 ,1 ), QgsPoint (5 ,1 ), QgsPoint (5 ,0 ), QgsPoint (6 ,0 ), ]
1088
+ ]
1089
+
1090
+ polyline = QgsGeometry .fromPolyline ( points [0 ] )
1091
+ assert polyline .addPart ( points [1 ][0 :1 ] ) == 2 , "addPart with one point line unexpectedly succeeded."
1092
+ assert polyline .addPart ( points [1 ][0 :2 ] ) == 0 , "addPart with two point line failed."
1093
+ expwkt = "MULTILINESTRING((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1))"
1094
+ wkt = polyline .exportToWkt ()
1095
+ assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
1096
+
1097
+ polyline = QgsGeometry .fromPolyline ( points [0 ] )
1098
+ assert polyline .addPart ( points [1 ] ) == 0 , "addPart with %d point line failed." % len (points [1 ])
1099
+ expwkt = "MULTILINESTRING((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1, 5 1, 5 0, 6 0))"
1100
+
1101
+ # 5-+-4 0-+-9
1102
+ # | | | |
1103
+ # | 2-3 1-2 |
1104
+ # | | | |
1105
+ # 0-1 7-8
1106
+ points = [
1107
+ [ [ QgsPoint (0 ,0 ), QgsPoint (1 ,0 ), QgsPoint (1 ,1 ), QgsPoint (2 ,1 ), QgsPoint (2 ,2 ), QgsPoint (0 ,2 ), QgsPoint (0 ,0 ), ] ],
1108
+ [ [ QgsPoint (4 ,0 ), QgsPoint (5 ,0 ), QgsPoint (5 ,2 ), QgsPoint (3 ,2 ), QgsPoint (3 ,1 ), QgsPoint (4 ,1 ), QgsPoint (4 ,0 ), ] ]
1109
+ ]
1110
+
1111
+ polygon = QgsGeometry .fromPolygon ( points [0 ] )
1112
+
1113
+ assert polygon .addPart ( points [1 ][0 ][0 :1 ] ) == 2 , "addPart with one point ring unexpectedly succeeded."
1114
+ assert polygon .addPart ( points [1 ][0 ][0 :2 ] ) == 2 , "addPart with two point ring unexpectedly succeeded."
1115
+ assert polygon .addPart ( points [1 ][0 ][0 :3 ] ) == 2 , "addPart with unclosed three point ring unexpectedly succeeded."
1116
+ assert polygon .addPart ( [ QgsPoint (4 ,0 ), QgsPoint (5 ,0 ), QgsPoint (4 ,0 ) ] ) == 2 , "addPart with 'closed' three point ring unexpectedly succeeded."
1117
+
1118
+ assert polygon .addPart ( points [1 ][0 ] ) == 0 , "addPart failed"
1119
+ expwkt = "MULTIPOLYGON(((0 0,1 0,1 1,2 1,2 2,0 2,0 0)),((4 0,5 0,5 2,3 2,3 1,4 1,4 0)))"
1120
+ wkt = polygon .exportToWkt ()
1121
+ assert compareWkt ( expwkt , wkt ), "Expected:\n %s\n Got:\n %s\n " % (expwkt , wkt )
1122
+
1080
1123
if __name__ == '__main__' :
1081
1124
unittest .main ()
0 commit comments