@@ -22,7 +22,7 @@ def assert_wkt_equivalence(geom: Union[Geometry, GeometryCollection]):
22
22
"""Assert WKT equivalence with Shapely."""
23
23
# Remove any trailing `.0` to match Shapely format
24
24
clean_wkt = re .sub (r"\.0(\D)" , r"\1" , geom .wkt )
25
- assert shape (geom . dict () ).wkt == clean_wkt
25
+ assert shape (geom ).wkt == clean_wkt
26
26
27
27
28
28
@pytest .mark .parametrize ("coordinates" , [(1.01 , 2.01 ), (1.0 , 2.0 , 3.0 ), (1.0 , 2.0 )])
@@ -51,10 +51,11 @@ def test_point_invalid_coordinates(coordinates):
51
51
@pytest .mark .parametrize (
52
52
"coordinates" ,
53
53
[
54
+ # No Z
54
55
[(1.0 , 2.0 )],
55
56
[(1.0 , 2.0 ), (1.0 , 2.0 )],
57
+ # Has Z
56
58
[(1.0 , 2.0 , 3.0 ), (1.0 , 2.0 , 3.0 )],
57
- [(1.0 , 2.0 ), (1.0 , 2.0 )],
58
59
],
59
60
)
60
61
def test_multi_point_valid_coordinates (coordinates ):
@@ -83,9 +84,12 @@ def test_multi_point_invalid_coordinates(coordinates):
83
84
@pytest .mark .parametrize (
84
85
"coordinates" ,
85
86
[
87
+ # Two Points, no Z
86
88
[(1.0 , 2.0 ), (3.0 , 4.0 )],
87
- [( 0.0 , 0.0 , 0.0 ), ( 1.0 , 1.0 , 1.0 )],
89
+ # Three Points, no Z
88
90
[(1.0 , 2.0 ), (3.0 , 4.0 ), (5.0 , 6.0 )],
91
+ # Two Points, has Z
92
+ [(0.0 , 0.0 , 0.0 ), (1.0 , 1.0 , 1.0 )],
89
93
],
90
94
)
91
95
def test_line_string_valid_coordinates (coordinates ):
@@ -111,9 +115,16 @@ def test_line_string_invalid_coordinates(coordinates):
111
115
@pytest .mark .parametrize (
112
116
"coordinates" ,
113
117
[
118
+ # One line, two points, no Z
114
119
[[(1.0 , 2.0 ), (3.0 , 4.0 )]],
120
+ # One line, two points, has Z
115
121
[[(0.0 , 0.0 , 0.0 ), (1.0 , 1.0 , 1.0 )]],
122
+ # One line, three points, no Z
116
123
[[(1.0 , 2.0 ), (3.0 , 4.0 ), (5.0 , 6.0 )]],
124
+ # Two lines, two points each, no Z
125
+ [[(1.0 , 2.0 ), (3.0 , 4.0 )], [(0.0 , 0.0 ), (1.0 , 1.0 )]],
126
+ # Two lines, two points each, has Z
127
+ [[(1.0 , 2.0 , 0.0 ), (3.0 , 4.0 , 1.0 )], [(0.0 , 0.0 , 0.0 ), (1.0 , 1.0 , 1.0 )]],
117
128
],
118
129
)
119
130
def test_multi_line_string_valid_coordinates (coordinates ):
@@ -141,7 +152,9 @@ def test_multi_line_string_invalid_coordinates(coordinates):
141
152
@pytest .mark .parametrize (
142
153
"coordinates" ,
143
154
[
155
+ # Polygon, no Z
144
156
[[(1.0 , 2.0 ), (3.0 , 4.0 ), (5.0 , 6.0 ), (1.0 , 2.0 )]],
157
+ # Polygon, has Z
145
158
[[(0.0 , 0.0 , 0.0 ), (1.0 , 1.0 , 0.0 ), (1.0 , 0.0 , 0.0 ), (0.0 , 0.0 , 0.0 )]],
146
159
],
147
160
)
@@ -158,16 +171,36 @@ def test_polygon_valid_coordinates(coordinates):
158
171
assert_wkt_equivalence (polygon )
159
172
160
173
161
- def test_polygon_with_holes ():
162
- """Check interior and exterior rings."""
163
- polygon = Polygon (
164
- type = " Polygon" ,
165
- coordinates = [
174
+ @ pytest . mark . parametrize (
175
+ "coordinates" ,
176
+ [
177
+ # Polygon with holes, no Z
178
+ [
166
179
[(0.0 , 0.0 ), (0.0 , 10.0 ), (10.0 , 10.0 ), (10.0 , 0.0 ), (0.0 , 0.0 )],
167
180
[(2.0 , 2.0 ), (2.0 , 4.0 ), (4.0 , 4.0 ), (4.0 , 2.0 ), (2.0 , 2.0 )],
168
181
],
169
- )
170
-
182
+ # Polygon with holes, has Z
183
+ [
184
+ [
185
+ (0.0 , 0.0 , 0.0 ),
186
+ (0.0 , 10.0 , 0.0 ),
187
+ (10.0 , 10.0 , 0.0 ),
188
+ (10.0 , 0.0 , 0.0 ),
189
+ (0.0 , 0.0 , 0.0 ),
190
+ ],
191
+ [
192
+ (2.0 , 2.0 , 1.0 ),
193
+ (2.0 , 4.0 , 1.0 ),
194
+ (4.0 , 4.0 , 1.0 ),
195
+ (4.0 , 2.0 , 1.0 ),
196
+ (2.0 , 2.0 , 1.0 ),
197
+ ],
198
+ ],
199
+ ],
200
+ )
201
+ def test_polygon_with_holes (coordinates ):
202
+ """Check interior and exterior rings."""
203
+ polygon = Polygon (type = "Polygon" , coordinates = coordinates )
171
204
assert polygon .type == "Polygon"
172
205
assert hasattr (polygon , "__geo_interface__" )
173
206
assert polygon .exterior == polygon .coordinates [0 ]
@@ -197,11 +230,18 @@ def test_polygon_invalid_coordinates(coordinates):
197
230
Polygon (type = "Polygon" , coordinates = coordinates )
198
231
199
232
200
- def test_multi_polygon ():
201
- """Should accept sequence of polygons."""
202
- multi_polygon = MultiPolygon (
203
- type = "MultiPolygon" ,
204
- coordinates = [
233
+ @pytest .mark .parametrize (
234
+ "coordinates" ,
235
+ [
236
+ # Multipolygon, no Z
237
+ [
238
+ [
239
+ [(0.0 , 0.0 ), (1.0 , 0.0 ), (1.0 , 1.0 ), (0.0 , 1.0 ), (0.0 , 0.0 )],
240
+ [(2.1 , 2.1 ), (2.2 , 2.1 ), (2.2 , 2.2 ), (2.1 , 2.2 ), (2.1 , 2.1 )],
241
+ ]
242
+ ],
243
+ # Multipolygon, has Z
244
+ [
205
245
[
206
246
[
207
247
(0.0 , 0.0 , 4.0 ),
@@ -219,7 +259,11 @@ def test_multi_polygon():
219
259
],
220
260
]
221
261
],
222
- )
262
+ ],
263
+ )
264
+ def test_multi_polygon (coordinates ):
265
+ """Should accept sequence of polygons."""
266
+ multi_polygon = MultiPolygon (type = "MultiPolygon" , coordinates = coordinates )
223
267
224
268
assert multi_polygon .type == "MultiPolygon"
225
269
assert hasattr (multi_polygon , "__geo_interface__" )
0 commit comments