Skip to content

Commit

Permalink
ENH: Allow a single geometry in add_geometries
Browse files Browse the repository at this point in the history
Allow single geometries to be added to a geoaxes, even though the
method is plural.
  • Loading branch information
greglucas committed Jan 27, 2022
1 parent 7c39f28 commit e7aef2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/cartopy/feature/__init__.py
Expand Up @@ -214,6 +214,8 @@ def __init__(self, geometries, crs, **kwargs):
"""
super().__init__(crs, **kwargs)
if isinstance(geometries, sgeom.base.BaseGeometry):
geometries = [geometries]
self._geoms = tuple(geometries)

def geometries(self):
Expand Down
9 changes: 9 additions & 0 deletions lib/cartopy/tests/mpl/test_axes.py
Expand Up @@ -13,6 +13,7 @@
import pytest

import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.geoaxes import InterProjectionTransform, GeoAxes


Expand Down Expand Up @@ -108,6 +109,14 @@ def test_styler_kwarg(self, ShapelyFeature, add_feature_method):
add_feature_method.assert_called_once_with(
ShapelyFeature(), styler=mock.sentinel.styler)

@pytest.mark.natural_earth
def test_single_geometry(self):
# A single geometry is acceptable
proj = ccrs.PlateCarree()
ax = GeoAxes(plt.figure(), [0, 0, 1, 1],
map_projection=proj)
ax.add_geometries(next(cfeature.COASTLINE.geometries()), crs=proj)


@cleanup
def test_geoaxes_subplot():
Expand Down

0 comments on commit e7aef2c

Please sign in to comment.