Skip to content

Commit

Permalink
do check WKTs
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 26, 2022
1 parent 6ad3490 commit e72ca18
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions tests/src/python/test_qgsgeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2316,8 +2316,8 @@ def testAddPart(self):
[QgsPointXY(0, 0), QgsPointXY(1, 0), QgsPointXY(1, 1), QgsPointXY(2, 1), QgsPointXY(2, 0), ],
[QgsPointXY(3, 0), QgsPointXY(3, 1), QgsPointXY(5, 1), QgsPointXY(5, 0), QgsPointXY(6, 0), ]
]
polyline1_geom = QgsGeometry.fromPolylineXY(line_points[0])
polyline2_geom = QgsGeometry.fromPolylineXY(line_points[1])
def polyline1_geom(): return QgsGeometry.fromPolylineXY(line_points[0])
def polyline2_geom(): return QgsGeometry.fromPolylineXY(line_points[1])

# 5-+-4 0-+-9
# | | | |
Expand All @@ -2330,10 +2330,11 @@ def testAddPart(self):
[[QgsPointXY(4, 0), QgsPointXY(5, 0), QgsPointXY(5, 2), QgsPointXY(3, 2), QgsPointXY(3, 1),
QgsPointXY(4, 1), QgsPointXY(4, 0), ]]
]
polygon1_geom = QgsGeometry.fromPolygonXY(poly_points[0])
polygon2_geom = QgsGeometry.fromPolygonXY(poly_points[1])
multi_polygon1_geom = QgsGeometry.fromMultiPolygonXY(poly_points[:1])
multi_polygon2_geom = QgsGeometry.fromMultiPolygonXY(poly_points[1:])
def polygon1_geom(): return QgsGeometry.fromPolygonXY(poly_points[0])
def polygon2_geom(): return QgsGeometry.fromPolygonXY(poly_points[1])
def multi_polygon_geom(): return QgsGeometry.fromMultiPolygonXY(poly_points)
def multi_polygon1_geom(): return QgsGeometry.fromMultiPolygonXY(poly_points[:1])
def multi_polygon2_geom(): return QgsGeometry.fromMultiPolygonXY(poly_points[1:])

geoms = {} # initial geometry
parts = {} # part to add
Expand All @@ -2352,63 +2353,63 @@ def testAddPart(self):
expec[T] = "MultiPointZ ((0 0 4), (1 0 3))"

T = 'line_add_1_point_fails'
geoms[T] = polyline1_geom
geoms[T] = polyline1_geom()
parts[T] = line_points[1][0:1]
resul[T] = QgsGeometry.InvalidInputGeometryType

T = 'line_add_2_point'
geoms[T] = polyline1_geom
geoms[T] = polyline1_geom()
parts[T] = line_points[1][0:2]
expec[T] = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1))"

T = 'add_point_with_more_points'
geoms[T] = polyline1_geom
geoms[T] = polyline1_geom()
parts[T] = line_points[1]
expec[T] = "MultiLineString ((0 0, 1 0, 1 1, 2 1, 2 0), (3 0, 3 1, 5 1, 5 0, 6 0))"

T = 'line_add_points_with_Z'
geoms[T] = polyline1_geom
geoms[T] = polyline1_geom()
geoms[T].get().addZValue(4.0)
parts[T] = [QgsPoint(p[0], p[1], 3.0, wkbType=QgsWkbTypes.PointZ) for p in line_points[1]]
expec[T] = "MultiLineStringZ ((0 0 4, 1 0 4, 1 1 4, 2 1 4, 2 0 4),(3 0 3, 3 1 3, 5 1 3, 5 0 3, 6 0 3))"

T = 'polygon_add_ring_1_point'
geoms[T] = polygon1_geom
geoms[T] = polygon1_geom()
parts[T] = poly_points[1][0][0:1]
resul[T] = QgsGeometry.InvalidInputGeometryType

T = 'polygon_add_ring_2_points'
geoms[T] = polygon1_geom
geoms[T] = polygon1_geom()
parts[T] = poly_points[1][0][0:2]
resul[T] = QgsGeometry.InvalidInputGeometryType

T = 'polygon_add_ring_3_points'
geoms[T] = polygon1_geom
geoms[T] = polygon1_geom()
parts[T] = poly_points[1][0][0:3]
resul[T] = QgsGeometry.InvalidInputGeometryType

T = 'polygon_add_ring_3_points_closed'
geoms[T] = polygon1_geom
geoms[T] = polygon1_geom()
parts[T] = [QgsPointXY(4, 0), QgsPointXY(5, 0), QgsPointXY(4, 0)]
resul[T] = QgsGeometry.InvalidInputGeometryType

T = 'polygon_add_polygon'
geoms[T] = polygon1_geom
geoms[T] = polygon1_geom()
parts[T] = poly_points[1][0]
expec[T] = "MultiPolygon (((0 0, 1 0, 1 1, 2 1, 2 2, 0 2, 0 0)),((4 0, 5 0, 5 2, 3 2, 3 1, 4 1, 4 0)))"

T = 'multipolygon_add_polygon'
geoms[T] = multi_polygon1_geom
parts[T] = polygon2_geom
expec[T] = multi_polygon1_geom.asWkt()
geoms[T] = multi_polygon1_geom()
parts[T] = polygon2_geom()
expec[T] = multi_polygon_geom().asWkt()

T = 'multipolygon_add_multipolygon'
geoms[T] = multi_polygon1_geom
parts[T] = multi_polygon2_geom
expec[T] = multi_polygon1_geom.asWkt()
geoms[T] = multi_polygon1_geom()
parts[T] = multi_polygon2_geom()
expec[T] = multi_polygon_geom().asWkt()

T = 'polygon_add_point_with_Z'
geoms[T] = polygon1_geom
geoms[T] = polygon1_geom()
geoms[T].get().addZValue(4.0)
parts[T] = [QgsPoint(pi[0], pi[1], 3.0, wkbType=QgsWkbTypes.PointZ) for pi in poly_points[1][0]]
expec[T] = "MultiPolygonZ (((0 0 4, 1 0 4, 1 1 4, 2 1 4, 2 2 4, 0 2 4, 0 0 4)),((4 0 3, 5 0 3, 5 2 3, 3 2 3, 3 1 3, 4 1 3, 4 0 3)))"
Expand Down Expand Up @@ -2468,9 +2469,9 @@ def testAddPart(self):
if type(parts[t]) == QgsGeometry:
self.assertEqual(geoms[t].addPartGeometry(parts[t]), expected_result, message)
else:
self.assertEqual(geoms[t].addPart(parts[t].get().clone(), geom_type), expected_result, message_with_wkt)
self.assertEqual(geoms[t].addPart(parts[t], geom_type), expected_result, message_with_wkt)

if expected_result == Qgis.Success:
if expected_result == Qgis.GeometryOperationResult.Success:
wkt = geoms[t].asWkt()
assert compareWkt(expec[t], wkt), message + "\nExpected:\n%s\nGot:\n%s\n" % (expec[t], wkt)

Expand Down

0 comments on commit e72ca18

Please sign in to comment.