Skip to content
Permalink
Browse files

Apply new GeometryOptions setter and getter to tests

  • Loading branch information
m-kuhn committed Aug 22, 2018
1 parent 35a87a1 commit 8a2e919752ddc14124d53a01cfb9f2d15efcb6f6
Showing with 14 additions and 6 deletions.
  1. +14 −6 tests/src/python/test_qgsvectorlayer.py
@@ -2758,36 +2758,44 @@ def testFeatureRequestWithReprojectionAndVirtualFields(self):

def testPrecision(self):
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int", "vl", "memory")
layer.setGeometryPrecision(10)
geomOps = QgsVectorLayer.GeometryOptions()
geomOps.geometryPrecision = 10
layer.setGeometryOptions(geomOps)
geom = QgsGeometry.fromWkt('Polygon ((2596411 1224654, 2596400 1224652, 2596405 1224640, 2596410 1224641, 2596411 1224654))')
feature = QgsFeature(layer.fields())
feature.setGeometry(geom)
layer.startEditing()
layer.addFeature(feature)
self.assertGeometriesEqual(QgsGeometry.fromWkt('Polygon ((2596410 1224650, 2596400 1224650, 2596410 1224640, 2596410 1224650))'), feature.geometry(), 'geometry with unsnapped nodes', 'fixed geometry')
layer.setGeometryPrecision(0.0)
geomOps.geometryPrecision = 0.0
layer.setGeometryOptions(geomOps)
feature.setGeometry(QgsGeometry.fromWkt('Polygon ((2596411 1224654, 2596400 1224652, 2596405 1224640, 2596410 1224641, 2596411 1224654))'))
layer.addFeature(feature)
self.assertGeometriesEqual(QgsGeometry.fromWkt('Polygon ((2596411 1224654, 2596400 1224652, 2596405 1224640, 2596410 1224641, 2596411 1224654))'), feature.geometry(), 'geometry with duplicates', 'unchanged geometry')

def testRemoveDuplicateNodes(self):
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int", "vl", "memory")
layer.setRemoveDuplicateNodes(True)
geomOps = QgsVectorLayer.GeometryOptions()
geomOps.removeDuplicateNodes = True
layer.setGeometryOptions(geomOps)
geom = QgsGeometry.fromWkt('Polygon ((70 80, 80 90, 80 90, 60 50, 70 80))')
feature = QgsFeature(layer.fields())
feature.setGeometry(geom)
layer.startEditing()
layer.addFeature(feature)
self.assertGeometriesEqual(feature.geometry(), QgsGeometry.fromWkt('Polygon ((70 80, 80 90, 60 50, 70 80))'), 'fixed geometry', 'geometry with duplicates')
layer.setRemoveDuplicateNodes(False)
geomOps.removeDuplicateNodes = False
layer.setGeometryOptions(geomOps)
feature.setGeometry(QgsGeometry.fromWkt('Polygon ((70 80, 80 90, 80 90, 60 50, 70 80))'))
layer.addFeature(feature)
self.assertGeometriesEqual(feature.geometry(), QgsGeometry.fromWkt('Polygon ((70 80, 80 90, 80 90, 60 50, 70 80))'), 'unchanged geometry', 'geometry with duplicates')

def testPrecisionAndDuplicateNodes(self):
layer = QgsVectorLayer("Polygon?crs=epsg:2056&field=pk:int", "vl", "memory")
layer.setGeometryPrecision(10)
layer.setRemoveDuplicateNodes(True)
geomOps = QgsVectorLayer.GeometryOptions()
geomOps.removeDuplicateNodes = True
geomOps.geometryPrecision = 10
layer.setGeometryOptions(geomOps)
geom = QgsGeometry.fromWkt('Polygon ((2596411 1224654, 2596400 1224652, 2596402 1224653, 2596405 1224640, 2596410 1224641, 2596411 1224654))')
feature = QgsFeature(layer.fields())
feature.setGeometry(geom)

0 comments on commit 8a2e919

Please sign in to comment.
You can’t perform that action at this time.