Skip to content

Commit

Permalink
updates for cartopy 0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoebber committed May 5, 2020
1 parent 7de0ff3 commit 5e6fd9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/metpy/plots/cartopy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
# SPDX-License-Identifier: BSD-3-Clause
"""Cartopy specific mapping utilities."""

import cartopy.crs as ccrs
import cartopy.feature as cfeature

from ..cbook import get_test_data


class MetPyMapFeature(cfeature.NaturalEarthFeature):
class MetPyMapFeature(cfeature.Feature):
"""A simple interface to US County shapefiles."""

def __init__(self, name, scale, **kwargs):
"""Create USCountiesFeature instance."""
super().__init__('', name, scale, **kwargs)
super().__init__(ccrs.PlateCarree(), **kwargs)
self.name = name
self.scale = scale

def geometries(self):
"""Return an iterator of (shapely) geometries for this feature."""
Expand Down
10 changes: 7 additions & 3 deletions src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def lookup_projection(projection_code):
return projections[projection_code]


def lookup_map_feature(feature_name):
def lookup_map_feature(feature_name, area):
"""Get a Cartopy map feature based on a name."""
import cartopy.feature as cfeature
from . import cartopy_utils
Expand All @@ -491,7 +491,7 @@ def lookup_map_feature(feature_name):
except AttributeError:
feat = getattr(cartopy_utils, name)
scaler = cfeature.AdaptiveScaler('20m', (('5m', 5), ('500k', 1)))
return feat.with_scale(scaler)
return feat.with_scale(scaler.scale_from_extent(area))


class Panel(HasTraits):
Expand Down Expand Up @@ -685,7 +685,7 @@ def _layer_features(self):
"""
for item in self.layers:
if isinstance(item, str):
feat = lookup_map_feature(item)
feat = lookup_map_feature(item, self.feature_area)
else:
feat = item

Expand Down Expand Up @@ -733,14 +733,18 @@ def draw(self):
# Set the extent as appropriate based on the area. One special case for 'global'
if self.area == 'global':
self.ax.set_global()
self.feature_area = [-180, 180, 90, -90]
elif self.area is not None:
# Try to look up if we have a string
if isinstance(self.area, str):
area = _areas[self.area.lower()]
# Otherwise, assume we have a tuple to use as the extent
else:
area = self.area
self.feature_area = area
self.ax.set_extent(area, DEFAULT_LAT_LON)
else:
self.feature_area = None

# Draw all of the plots.
for p in self.plots:
Expand Down

0 comments on commit 5e6fd9e

Please sign in to comment.