File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -159,9 +159,9 @@ def check_closure(cls, coordinates: List) -> List:
159
159
return coordinates
160
160
161
161
@property
162
- def exterior (self ) -> LinearRing :
162
+ def exterior (self ) -> Union [ LinearRing , None ] :
163
163
"""Return the exterior Linear Ring of the polygon."""
164
- return self .coordinates [0 ]
164
+ return self .coordinates [0 ] if self . coordinates else None
165
165
166
166
@property
167
167
def interiors (self ) -> Iterator [LinearRing ]:
@@ -250,7 +250,11 @@ def _wkt_coordinates(self) -> str:
250
250
@property
251
251
def wkt (self ) -> str :
252
252
"""Return the Well Known Text representation."""
253
- return f"{ self ._wkt_type } ({ self ._wkt_coordinates } )"
253
+ return (
254
+ self ._wkt_type
255
+ + " "
256
+ + (f"({ self ._wkt_coordinates } )" if self ._wkt_coordinates else "EMPTY" )
257
+ )
254
258
255
259
@property
256
260
def __geo_interface__ (self ) -> Dict [str , Any ]:
Original file line number Diff line number Diff line change @@ -175,6 +175,8 @@ def test_polygon_valid_coordinates(coordinates):
175
175
assert hasattr (polygon , "__geo_interface__" )
176
176
if polygon .coordinates :
177
177
assert polygon .exterior == coordinates [0 ]
178
+ else :
179
+ assert polygon .exterior is None
178
180
assert not list (polygon .interiors )
179
181
assert_wkt_equivalence (polygon )
180
182
@@ -468,3 +470,22 @@ class PointType(Point):
468
470
PointType (type = "Point" , coordinates = (1.01 , 2.01 )).wkt
469
471
== Point (type = "Point" , coordinates = (1.01 , 2.01 )).wkt
470
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
+ )
You can’t perform that action at this time.
0 commit comments