@@ -4165,6 +4165,33 @@ def testPoint(self):
41654165 self .assertEqual (point_zm .z (), 3 )
41664166 self .assertEqual (point_zm .m (), 4 )
41674167
4168+ def testClipped (self ):
4169+ tests = [["LINESTRING (1 1,1 9,9 9,9 1)" , QgsRectangle (0 , 0 , 10 , 10 ), "LINESTRING (1 1,1 9,9 9,9 1)" ],
4170+ ["LINESTRING (-1 -9,-1 11,9 11)" , QgsRectangle (0 , 0 , 10 , 10 ), "GEOMETRYCOLLECTION ()" ],
4171+ ["LINESTRING (-1 5,5 5,9 9)" , QgsRectangle (0 , 0 , 10 , 10 ), "LINESTRING (0 5,5 5,9 9)" ],
4172+ ["LINESTRING (5 5,8 5,12 5)" , QgsRectangle (0 , 0 , 10 , 10 ), "LINESTRING (5 5,8 5,10 5)" ],
4173+ ["LINESTRING (5 -1,5 5,1 2,-3 2,1 6)" , QgsRectangle (0 , 0 , 10 , 10 ), "MULTILINESTRING ((5 0,5 5,1 2,0 2),(0 5,1 6))" ],
4174+ ["LINESTRING (0 3,0 5,0 7)" , QgsRectangle (0 , 0 , 10 , 10 ), "GEOMETRYCOLLECTION ()" ],
4175+ ["LINESTRING (0 3,0 5,-1 7)" , QgsRectangle (0 , 0 , 10 , 10 ), "GEOMETRYCOLLECTION ()" ],
4176+ ["LINESTRING (0 3,0 5,2 7)" , QgsRectangle (0 , 0 , 10 , 10 ), "LINESTRING (0 5,2 7)" ],
4177+ ["LINESTRING (2 1,0 0,1 2)" , QgsRectangle (0 , 0 , 10 , 10 ), "LINESTRING (2 1,0 0,1 2)" ],
4178+ ["LINESTRING (3 3,0 3,0 5,2 7)" , QgsRectangle (0 , 0 , 10 , 10 ), "MULTILINESTRING ((3 3,0 3),(0 5,2 7))" ],
4179+ ["LINESTRING (5 5,10 5,20 5)" , QgsRectangle (0 , 0 , 10 , 10 ), "LINESTRING (5 5,10 5)" ],
4180+ ["LINESTRING (3 3,0 6,3 9)" , QgsRectangle (0 , 0 , 10 , 10 ), "LINESTRING (3 3,0 6,3 9)" ],
4181+ ["POLYGON ((5 5,5 6,6 6,6 5,5 5))" , QgsRectangle (0 , 0 , 10 , 10 ), "POLYGON ((5 5,5 6,6 6,6 5,5 5))" ],
4182+ ["POLYGON ((15 15,15 16,16 16,16 15,15 15))" , QgsRectangle (0 , 0 , 10 , 10 ), "GEOMETRYCOLLECTION ()" ],
4183+ ["POLYGON ((-1 -1,-1 11,11 11,11 -1,-1 -1))" , QgsRectangle (0 , 0 , 10 , 10 ), "Polygon ((0 0, 0 10, 10 10, 10 0, 0 0))" ],
4184+ ["POLYGON ((-1 -1,-1 5,5 5,5 -1,-1 -1))" , QgsRectangle (0 , 0 , 10 , 10 ), "Polygon ((0 0, 0 5, 5 5, 5 0, 0 0))" ],
4185+ ["POLYGON ((-2 -2,-2 5,5 5,5 -2,-2 -2), (3 3,4 4,4 2,3 3))" , QgsRectangle (0 , 0 , 10 , 10 ), "Polygon ((0 0, 0 5, 5 5, 5 0, 0 0),(3 3, 4 4, 4 2, 3 3))" ]
4186+ ]
4187+ for t in tests :
4188+ input = QgsGeometry .fromWkt (t [0 ])
4189+ o = input .clipped (t [1 ])
4190+ exp = t [2 ]
4191+ result = o .exportToWkt ()
4192+ self .assertTrue (compareWkt (result , exp , 0.00001 ),
4193+ "clipped: mismatch Expected:\n {}\n Got:\n {}\n " .format (exp , result ))
4194+
41684195
41694196if __name__ == '__main__' :
41704197 unittest .main ()
0 commit comments