Skip to content

Commit

Permalink
Support LinearRing objects in the shape() function (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored Oct 1, 2021
1 parent 9963cca commit 578b36f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion shapely/geometry/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .point import Point, asPoint
from .linestring import LineString, asLineString
from .polygon import Polygon, asPolygon
from .polygon import LinearRing, Polygon, asPolygon
from .multipoint import MultiPoint, asMultiPoint
from .multilinestring import MultiLineString, asMultiLineString
from .multipolygon import MultiPolygon, MultiPolygonAdapter
Expand Down Expand Up @@ -106,6 +106,8 @@ def shape(context):
return Point(ob["coordinates"])
elif geom_type == "linestring":
return LineString(ob["coordinates"])
elif geom_type == "linearring":
return LinearRing(ob["coordinates"])
elif geom_type == "polygon":
return Polygon(ob["coordinates"][0], ob["coordinates"][1:])
elif geom_type == "multipoint":
Expand Down
13 changes: 12 additions & 1 deletion tests/test_geointerface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from shapely.geometry.multipoint import MultiPoint, MultiPointAdapter
from shapely.geometry.linestring import LineString, LineStringAdapter
from shapely.geometry.multilinestring import MultiLineString, MultiLineStringAdapter
from shapely.geometry.polygon import Polygon, PolygonAdapter
from shapely.geometry.polygon import LinearRing, Polygon, PolygonAdapter
from shapely.geometry.multipolygon import MultiPolygon, MultiPolygonAdapter
from shapely import wkt

Expand Down Expand Up @@ -94,6 +94,17 @@ def test_geointerface(self):
self.assertIsInstance(geom, LineString)
self.assertEqual(tuple(geom.coords), ((-1.0, -1.0), (1.0, 1.0)))

# Check linearring
geom = shape(
{'type': 'LinearRing',
'coordinates':
((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (2.0, -1.0), (0.0, 0.0))}
)
self.assertIsInstance(geom, LinearRing)
self.assertEqual(
tuple(geom.coords),
((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (2.0, -1.0), (0.0, 0.0)))

# polygon
geom = shape(
{'type': 'Polygon',
Expand Down

0 comments on commit 578b36f

Please sign in to comment.