@@ -28,7 +28,7 @@ def assert_wkt_equivalence(geom: Union[Geometry, GeometryCollection]):
28
28
@pytest .mark .parametrize ("coordinates" , [(1.01 , 2.01 ), (1.0 , 2.0 , 3.0 ), (1.0 , 2.0 )])
29
29
def test_point_valid_coordinates (coordinates ):
30
30
"""
31
- Two or three number elements as coordinates shold be okay
31
+ Two or three number elements as coordinates should be okay
32
32
"""
33
33
p = Point (type = "Point" , coordinates = coordinates )
34
34
assert p .type == "Point"
@@ -38,7 +38,8 @@ def test_point_valid_coordinates(coordinates):
38
38
39
39
40
40
@pytest .mark .parametrize (
41
- "coordinates" , [(1.0 ,), (1.0 , 2.0 , 3.0 , 4.0 ), "Foo" , (None , 2.0 ), (1.0 , (2.0 ,))]
41
+ "coordinates" ,
42
+ [(1.0 ,), (1.0 , 2.0 , 3.0 , 4.0 ), "Foo" , (None , 2.0 ), (1.0 , (2.0 ,)), (), [], None ],
42
43
)
43
44
def test_point_invalid_coordinates (coordinates ):
44
45
"""
@@ -51,6 +52,8 @@ def test_point_invalid_coordinates(coordinates):
51
52
@pytest .mark .parametrize (
52
53
"coordinates" ,
53
54
[
55
+ # Empty array
56
+ [],
54
57
# No Z
55
58
[(1.0 , 2.0 )],
56
59
[(1.0 , 2.0 ), (1.0 , 2.0 )],
@@ -60,7 +63,7 @@ def test_point_invalid_coordinates(coordinates):
60
63
)
61
64
def test_multi_point_valid_coordinates (coordinates ):
62
65
"""
63
- Two or three number elements as coordinates shold be okay
66
+ Two or three number elements as coordinates should be okay, as well as an empty array.
64
67
"""
65
68
p = MultiPoint (type = "MultiPoint" , coordinates = coordinates )
66
69
assert p .type == "MultiPoint"
@@ -71,7 +74,7 @@ def test_multi_point_valid_coordinates(coordinates):
71
74
72
75
@pytest .mark .parametrize (
73
76
"coordinates" ,
74
- [[(1.0 ,)], [(1.0 , 2.0 , 3.0 , 4.0 )], ["Foo" ], [(None , 2.0 )], [(1.0 , (2.0 ,))]],
77
+ [[(1.0 ,)], [(1.0 , 2.0 , 3.0 , 4.0 )], ["Foo" ], [(None , 2.0 )], [(1.0 , (2.0 ,))], None ],
75
78
)
76
79
def test_multi_point_invalid_coordinates (coordinates ):
77
80
"""
@@ -115,6 +118,8 @@ def test_line_string_invalid_coordinates(coordinates):
115
118
@pytest .mark .parametrize (
116
119
"coordinates" ,
117
120
[
121
+ # Empty array
122
+ [],
118
123
# One line, two points, no Z
119
124
[[(1.0 , 2.0 ), (3.0 , 4.0 )]],
120
125
# One line, two points, has Z
@@ -139,7 +144,7 @@ def test_multi_line_string_valid_coordinates(coordinates):
139
144
140
145
141
146
@pytest .mark .parametrize (
142
- "coordinates" , [[None ], ["Foo" ], [[]], [[(1.0 , 2.0 )]], [["Foo" , "Bar" ]]]
147
+ "coordinates" , [None , [None ], ["Foo" ], [[]], [[(1.0 , 2.0 )]], [["Foo" , "Bar" ]]]
143
148
)
144
149
def test_multi_line_string_invalid_coordinates (coordinates ):
145
150
"""
@@ -152,6 +157,8 @@ def test_multi_line_string_invalid_coordinates(coordinates):
152
157
@pytest .mark .parametrize (
153
158
"coordinates" ,
154
159
[
160
+ # Empty array
161
+ [],
155
162
# Polygon, no Z
156
163
[[(1.0 , 2.0 ), (3.0 , 4.0 ), (5.0 , 6.0 ), (1.0 , 2.0 )]],
157
164
# Polygon, has Z
@@ -166,7 +173,10 @@ def test_polygon_valid_coordinates(coordinates):
166
173
assert polygon .type == "Polygon"
167
174
assert polygon .coordinates == coordinates
168
175
assert hasattr (polygon , "__geo_interface__" )
169
- assert polygon .exterior == coordinates [0 ]
176
+ if polygon .coordinates :
177
+ assert polygon .exterior == coordinates [0 ]
178
+ else :
179
+ assert polygon .exterior is None
170
180
assert not list (polygon .interiors )
171
181
assert_wkt_equivalence (polygon )
172
182
@@ -212,10 +222,10 @@ def test_polygon_with_holes(coordinates):
212
222
"coordinates" ,
213
223
[
214
224
"foo" ,
225
+ None ,
215
226
[[(1.0 , 2.0 ), (3.0 , 4.0 ), (5.0 , 6.0 ), (1.0 , 2.0 )], "foo" , None ],
216
227
[[(1.0 , 2.0 ), (3.0 , 4.0 ), (1.0 , 2.0 )]],
217
228
[[(1.0 , 2.0 ), (3.0 , 4.0 ), (5.0 , 6.0 ), (7.0 , 8.0 )]],
218
- [],
219
229
],
220
230
)
221
231
def test_polygon_invalid_coordinates (coordinates ):
@@ -233,6 +243,8 @@ def test_polygon_invalid_coordinates(coordinates):
233
243
@pytest .mark .parametrize (
234
244
"coordinates" ,
235
245
[
246
+ # Empty array
247
+ [],
236
248
# Multipolygon, no Z
237
249
[
238
250
[
@@ -270,6 +282,26 @@ def test_multi_polygon(coordinates):
270
282
assert_wkt_equivalence (multi_polygon )
271
283
272
284
285
+ @pytest .mark .parametrize (
286
+ "coordinates" ,
287
+ [
288
+ "foo" ,
289
+ None ,
290
+ [
291
+ [
292
+ [(0.0 , 0.0 ), (1.0 , 0.0 ), (1.0 , 1.0 ), (0.0 , 1.0 ), (0.0 , 0.0 )],
293
+ ],
294
+ [
295
+ [(2.1 , 2.1 ), (2.2 , 2.1 ), (2.2 , 2.2 ), (2.1 , 4.2 )],
296
+ ],
297
+ ],
298
+ ],
299
+ )
300
+ def test_multipolygon_invalid_coordinates (coordinates ):
301
+ with pytest .raises (ValidationError ):
302
+ MultiPolygon (type = "MultiPolygon" , coordinates = coordinates )
303
+
304
+
273
305
def test_parse_geometry_obj_point ():
274
306
assert parse_geometry_obj ({"type" : "Point" , "coordinates" : [102.0 , 0.5 ]}) == Point (
275
307
type = "Point" , coordinates = (102.0 , 0.5 )
@@ -438,3 +470,22 @@ class PointType(Point):
438
470
PointType (type = "Point" , coordinates = (1.01 , 2.01 )).wkt
439
471
== Point (type = "Point" , coordinates = (1.01 , 2.01 )).wkt
440
472
)
473
+
474
+
475
+ @pytest .mark .parametrize (
476
+ "shape" ,
477
+ [
478
+ MultiPoint ,
479
+ MultiLineString ,
480
+ Polygon ,
481
+ MultiPolygon ,
482
+ ],
483
+ )
484
+ def test_wkt_empty (shape ):
485
+ assert shape (type = shape .__name__ , coordinates = []).wkt .endswith (" EMPTY" )
486
+
487
+
488
+ def test_wkt_empty_geometrycollection ():
489
+ assert GeometryCollection (type = "GeometryCollection" , geometries = []).wkt .endswith (
490
+ " EMPTY"
491
+ )
0 commit comments