@@ -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,14 +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
- coordinates = [
174
+ @pytest .mark .parametrize (
175
+ "coordinates" ,
176
+ [
177
+ # Polygon with holes, no Z
178
+ [
165
179
[(0.0 , 0.0 ), (0.0 , 10.0 ), (10.0 , 10.0 ), (10.0 , 0.0 ), (0.0 , 0.0 )],
166
180
[(2.0 , 2.0 ), (2.0 , 4.0 ), (4.0 , 4.0 ), (4.0 , 2.0 ), (2.0 , 2.0 )],
167
- ]
168
- )
181
+ ],
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 (coordinates = coordinates )
169
204
170
205
assert polygon .type == "Polygon"
171
206
assert hasattr (polygon , "__geo_interface__" )
@@ -196,10 +231,18 @@ def test_polygon_invalid_coordinates(coordinates):
196
231
Polygon (coordinates = coordinates )
197
232
198
233
199
- def test_multi_polygon ():
200
- """Should accept sequence of polygons."""
201
- multi_polygon = MultiPolygon (
202
- coordinates = [
234
+ @pytest .mark .parametrize (
235
+ "coordinates" ,
236
+ [
237
+ # Multipolygon, no Z
238
+ [
239
+ [
240
+ [(0.0 , 0.0 ), (1.0 , 0.0 ), (1.0 , 1.0 ), (0.0 , 1.0 ), (0.0 , 0.0 )],
241
+ [(2.1 , 2.1 ), (2.2 , 2.1 ), (2.2 , 2.2 ), (2.1 , 2.2 ), (2.1 , 2.1 )],
242
+ ]
243
+ ],
244
+ # Multipolygon, has Z
245
+ [
203
246
[
204
247
[
205
248
(0.0 , 0.0 , 4.0 ),
@@ -216,8 +259,12 @@ def test_multi_polygon():
216
259
(2.1 , 2.1 , 4.0 ),
217
260
],
218
261
]
219
- ]
220
- )
262
+ ],
263
+ ],
264
+ )
265
+ def test_multi_polygon (coordinates ):
266
+ """Should accept sequence of polygons."""
267
+ multi_polygon = MultiPolygon (coordinates = coordinates )
221
268
222
269
assert multi_polygon .type == "MultiPolygon"
223
270
assert hasattr (multi_polygon , "__geo_interface__" )
0 commit comments