Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Allow a single geometry in add_geometries #1999

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/cartopy/feature/__init__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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