shapely.get_rings#

get_rings(geometry, return_index=False)#

Gets rings of Polygon geometry object.

For each Polygon, the first returned ring is always the exterior ring and potential subsequent rings are interior rings.

If the geometry is not a Polygon, nothing is returned (empty array for scalar geometry input or no element in output array for array input).

Parameters:
geometryGeometry or array_like
return_indexbool, default False

If True, will return a tuple of ndarrays of (rings, indexes), where indexes are the indexes of the original geometries in the source array.

Returns:
ndarray of rings or tuple of (rings, indexes)

Examples

```>>> from shapely import Polygon
>>> polygon_with_hole = Polygon(
...     [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
...     holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> get_rings(polygon_with_hole).tolist()
[<LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)>,
<LINEARRING (2 2, 2 4, 4 4, 4 2, 2 2)>]
```

With `return_index=True`:

```>>> polygon = Polygon([(0, 0), (2, 0), (2, 2), (0, 2), (0, 0)])
>>> rings, index = get_rings([polygon, polygon_with_hole], return_index=True)
>>> rings.tolist()
[<LINEARRING (0 0, 2 0, 2 2, 0 2, 0 0)>,
<LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)>,
<LINEARRING (2 2, 2 4, 4 4, 4 2, 2 2)>]
>>> index.tolist()
[0, 1, 1]
```