@@ -204,8 +204,11 @@ def _make_compatible_tester(self, feature_wkt, layer_wkb_name, attrs=[1]):
204
204
def test_QgsVectorLayerUtilsmakeFeaturesCompatible (self ):
205
205
"""Test fixer function"""
206
206
# Test failure
207
- with self .assertRaises (AssertionError ):
208
- self ._make_compatible_tester ('LineString (1 1, 2 2, 3 3)' , 'Point' )
207
+ self ._make_compatible_tester ('LineString (1 1, 2 2, 3 3)' , 'Point' )
208
+ self ._make_compatible_tester ('LineString (1 1, 2 2, 3 3)' , 'Polygon' )
209
+ self ._make_compatible_tester ('Polygon((1 1, 2 2, 1 2, 1 1))' , 'Point' )
210
+ self ._make_compatible_tester ('Polygon((1 1, 2 2, 1 2, 1 1))' , 'LineString' )
211
+
209
212
self ._make_compatible_tester ('Point(1 1)' , 'Point' )
210
213
self ._make_compatible_tester ('Point(1 1)' , 'Point' , [1 , 'nope' ])
211
214
self ._make_compatible_tester ('Point z (1 1 3)' , 'Point' )
@@ -277,6 +280,96 @@ def test_QgsVectorLayerUtilsmakeFeaturesCompatible(self):
277
280
self .assertEqual (f [0 ].geometry ().asWkt (), 'LineString (1 1, 2 2, 3 3, 1 1)' )
278
281
self .assertEqual (f [1 ].geometry ().asWkt (), 'LineString (10 1, 20 2, 30 3, 10 1)' )
279
282
283
+ # line -> points
284
+ l , f = self ._make_compatible_tester ('LineString (1 1, 2 2, 3 3)' , 'Point' )
285
+ self .assertEqual (len (f ), 3 )
286
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'Point (1 1)' )
287
+ self .assertEqual (f [1 ].geometry ().asWkt (), 'Point (2 2)' )
288
+ self .assertEqual (f [2 ].geometry ().asWkt (), 'Point (3 3)' )
289
+
290
+ l , f = self ._make_compatible_tester ('LineString (1 1, 2 2, 3 3)' , 'MultiPoint' )
291
+ self .assertEqual (len (f ), 1 )
292
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'MultiPoint ((1 1),(2 2),(3 3))' )
293
+
294
+ l , f = self ._make_compatible_tester ('MultiLineString ((1 1, 2 2),(4 4, 3 3))' , 'Point' )
295
+ self .assertEqual (len (f ), 4 )
296
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'Point (1 1)' )
297
+ self .assertEqual (f [1 ].geometry ().asWkt (), 'Point (2 2)' )
298
+ self .assertEqual (f [2 ].geometry ().asWkt (), 'Point (4 4)' )
299
+ self .assertEqual (f [3 ].geometry ().asWkt (), 'Point (3 3)' )
300
+
301
+ l , f = self ._make_compatible_tester ('MultiLineString ((1 1, 2 2),(4 4, 3 3))' , 'MultiPoint' )
302
+ self .assertEqual (len (f ), 1 )
303
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'MultiPoint ((1 1),(2 2),(4 4),(3 3))' )
304
+
305
+ # line -> polygon
306
+ l , f = self ._make_compatible_tester ('LineString (1 1, 1 2, 2 2)' , 'Polygon' )
307
+ self .assertEqual (len (f ), 1 )
308
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'Polygon ((1 1, 1 2, 2 2, 1 1))' )
309
+
310
+ l , f = self ._make_compatible_tester ('LineString (1 1, 1 2, 2 2)' , 'MultiPolygon' )
311
+ self .assertEqual (len (f ), 1 )
312
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'MultiPolygon (((1 1, 1 2, 2 2, 1 1)))' )
313
+
314
+ l , f = self ._make_compatible_tester ('MultiLineString ((1 1, 1 2, 2 2, 1 1),(3 3, 4 3, 4 4))' , 'Polygon' )
315
+ self .assertEqual (len (f ), 2 )
316
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'Polygon ((1 1, 1 2, 2 2, 1 1))' )
317
+ self .assertEqual (f [1 ].geometry ().asWkt (), 'Polygon ((3 3, 4 3, 4 4, 3 3))' )
318
+
319
+ l , f = self ._make_compatible_tester ('MultiLineString ((1 1, 1 2, 2 2, 1 1),(3 3, 4 3, 4 4))' , 'MultiPolygon' )
320
+ self .assertEqual (len (f ), 1 )
321
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'MultiPolygon (((1 1, 1 2, 2 2, 1 1)),((3 3, 4 3, 4 4, 3 3)))' )
322
+
323
+ l , f = self ._make_compatible_tester ('CircularString (1 1, 1 2, 2 2, 2 0, 1 1)' , 'CurvePolygon' )
324
+ self .assertEqual (len (f ), 1 )
325
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'CurvePolygon (CircularString (1 1, 1 2, 2 2, 2 0, 1 1))' )
326
+
327
+ l , f = self ._make_compatible_tester ('CircularString (1 1, 1 2, 2 2, 2 0, 1 1)' , 'Polygon' )
328
+ self .assertEqual (len (f ), 1 )
329
+ self .assertTrue (f [0 ].geometry ().asWkt (2 ).startswith ('Polygon ((1 1, 0.99 1.01, 0.98 1.02' ))
330
+
331
+ # polygon -> points
332
+ l , f = self ._make_compatible_tester ('Polygon ((1 1, 1 2, 2 2, 1 1))' , 'Point' )
333
+ self .assertEqual (len (f ), 3 )
334
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'Point (1 1)' )
335
+ self .assertEqual (f [1 ].geometry ().asWkt (), 'Point (1 2)' )
336
+ self .assertEqual (f [2 ].geometry ().asWkt (), 'Point (2 2)' )
337
+
338
+ l , f = self ._make_compatible_tester ('Polygon ((1 1, 1 2, 2 2, 1 1))' , 'MultiPoint' )
339
+ self .assertEqual (len (f ), 1 )
340
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'MultiPoint ((1 1),(1 2),(2 2))' )
341
+
342
+ l , f = self ._make_compatible_tester ('MultiPolygon (((1 1, 1 2, 2 2, 1 1)),((3 3, 4 3, 4 4, 3 3)))' , 'Point' )
343
+ self .assertEqual (len (f ), 6 )
344
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'Point (1 1)' )
345
+ self .assertEqual (f [1 ].geometry ().asWkt (), 'Point (1 2)' )
346
+ self .assertEqual (f [2 ].geometry ().asWkt (), 'Point (2 2)' )
347
+ self .assertEqual (f [3 ].geometry ().asWkt (), 'Point (3 3)' )
348
+ self .assertEqual (f [4 ].geometry ().asWkt (), 'Point (4 3)' )
349
+ self .assertEqual (f [5 ].geometry ().asWkt (), 'Point (4 4)' )
350
+
351
+ l , f = self ._make_compatible_tester ('MultiPolygon (((1 1, 1 2, 2 2, 1 1)),((3 3, 4 3, 4 4, 3 3)))' , 'MultiPoint' )
352
+ self .assertEqual (len (f ), 1 )
353
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'MultiPoint ((1 1),(1 2),(2 2),(3 3),(4 3),(4 4))' )
354
+
355
+ # polygon -> lines
356
+ l , f = self ._make_compatible_tester ('Polygon ((1 1, 1 2, 2 2, 1 1))' , 'LineString' )
357
+ self .assertEqual (len (f ), 1 )
358
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'LineString (1 1, 1 2, 2 2, 1 1)' )
359
+
360
+ l , f = self ._make_compatible_tester ('Polygon ((1 1, 1 2, 2 2, 1 1))' , 'MultiLineString' )
361
+ self .assertEqual (len (f ), 1 )
362
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'MultiLineString ((1 1, 1 2, 2 2, 1 1))' )
363
+
364
+ l , f = self ._make_compatible_tester ('MultiPolygon (((1 1, 1 2, 2 2, 1 1)),((3 3, 4 3, 4 4, 3 3)))' , 'LineString' )
365
+ self .assertEqual (len (f ), 2 )
366
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'LineString (1 1, 1 2, 2 2, 1 1)' )
367
+ self .assertEqual (f [1 ].geometry ().asWkt (), 'LineString (3 3, 4 3, 4 4, 3 3)' )
368
+
369
+ l , f = self ._make_compatible_tester ('MultiPolygon (((1 1, 1 2, 2 2, 1 1)),((3 3, 4 3, 4 4, 3 3)))' , 'MultiLineString' )
370
+ self .assertEqual (len (f ), 1 )
371
+ self .assertEqual (f [0 ].geometry ().asWkt (), 'MultiLineString ((1 1, 1 2, 2 2, 1 1),(3 3, 4 3, 4 4, 3 3))' )
372
+
280
373
def test_make_features_compatible_attributes (self ):
281
374
"""Test corner cases for attributes"""
282
375
0 commit comments