@@ -474,6 +474,41 @@ def test_reprojectlayer(self):
474
474
# Check selected
475
475
self .assertEqual (self .vl .selectedFeatureIds (), [1 ])
476
476
477
+ def test_snappointstogrid (self ):
478
+ """Check that this runs correctly"""
479
+
480
+ polygon_layer = self ._make_layer ('Polygon' )
481
+ f1 = QgsFeature (polygon_layer .fields ())
482
+ f1 .setAttributes ([1 ])
483
+ f1 .setGeometry (QgsGeometry .fromWkt ('POLYGON((1.2 1.2, 1.2 2.2, 2.2 2.2, 2.2 1.2, 1.2 1.2))' ))
484
+ f2 = QgsFeature (polygon_layer .fields ())
485
+ f2 .setAttributes ([2 ])
486
+ f2 .setGeometry (QgsGeometry .fromWkt ('POLYGON((1.1 1.1, 1.1 2.1, 2.1 2.1, 2.1 1.1, 1.1 1.1))' ))
487
+ self .assertTrue (f2 .isValid ())
488
+ self .assertTrue (polygon_layer .startEditing ())
489
+ self .assertTrue (polygon_layer .addFeatures ([f1 , f2 ]))
490
+ self .assertEqual (polygon_layer .featureCount (), 2 )
491
+ polygon_layer .commitChanges ()
492
+ self .assertEqual (polygon_layer .featureCount (), 2 )
493
+ QgsProject .instance ().addMapLayers ([polygon_layer ])
494
+
495
+ polygon_layer .selectByIds ([next (polygon_layer .getFeatures ()).id ()])
496
+ self .assertEqual (polygon_layer .selectedFeatureCount (), 1 )
497
+
498
+ old_features , new_features = self ._alg_tester (
499
+ 'native:snappointstogrid' ,
500
+ polygon_layer ,
501
+ {
502
+ 'HSPACING' : 0.5 ,
503
+ 'VSPACING' : 0.5 ,
504
+ }
505
+ )
506
+
507
+ g = [f .geometry () for f in new_features ][0 ]
508
+ self .assertEqual (g .asWkt (), 'Polygon ((1 1, 1 2, 2 2, 2 1, 1 1))' )
509
+ # Check selected
510
+ self .assertEqual (polygon_layer .selectedFeatureIds (), [1 ])
511
+
477
512
def test_clip (self ):
478
513
479
514
mask_layer = QgsMemoryProviderUtils .createMemoryLayer (
0 commit comments