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

Validating Natural Earth scales #1506

Merged
merged 1 commit into from Apr 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/cartopy/feature/__init__.py
Expand Up @@ -260,11 +260,20 @@ def __init__(self, category, name, scale, **kwargs):
scale = Scaler(scale)

self.scaler = scale
# Make sure this is a valid resolution
self._validate_scale()

@property
def scale(self):
return self.scaler.scale

def _validate_scale(self):
if self.scale not in ('110m', '50m', '10m'):
raise ValueError(
'{} is not a valid Natural Earth scale. '.format(self.scale) +
'Valid scales are "110m", "50m", and "10m".'
)

def geometries(self):
"""
Returns an iterator of (shapely) geometries for this feature.
Expand Down
25 changes: 10 additions & 15 deletions lib/cartopy/tests/test_features.py
@@ -1,23 +1,13 @@
# (C) British Crown Copyright 2017 - 2018, Met Office
# Copyright Cartopy Contributors
#
# This file is part of cartopy.
#
# cartopy is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cartopy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with cartopy. If not, see <https://www.gnu.org/licenses/>.
# This file is part of Cartopy and is released under the LGPL license.
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.

from __future__ import (absolute_import, division, print_function)

import cartopy.feature as cfeature
import pytest

small_extent = (-6, -8, 56, 59)
medium_extent = (-20, 20, 20, 60)
Expand Down Expand Up @@ -71,3 +61,8 @@ def test_intersecting_geometries_large(self, monkeypatch):
# '110m' when the extent is large and autoscale is True.
auto_land.intersecting_geometries(large_extent)
assert auto_land.scale == '110m'


def test_bad_ne_scale():
with pytest.raises(ValueError, match='not a valid Natural Earth scale'):
cfeature.NaturalEarthFeature('physical', 'land', '30m')