Skip to content

Commit ab8d54f

Browse files
elpasonyalldawson
authored andcommittedSep 14, 2018
Add test for snappointstogrid
1 parent 699a9a3 commit ab8d54f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 

‎tests/src/python/test_qgsprocessinginplace.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,41 @@ def test_reprojectlayer(self):
474474
# Check selected
475475
self.assertEqual(self.vl.selectedFeatureIds(), [1])
476476

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+
477512
def test_clip(self):
478513

479514
mask_layer = QgsMemoryProviderUtils.createMemoryLayer(

0 commit comments

Comments
 (0)
Please sign in to comment.