Skip to content
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
81 changes: 41 additions & 40 deletions lib/cartopy/feature/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# (C) British Crown Copyright 2011 - 2019, 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.

"""
This module defines :class:`Feature` instances, for use with
ax.add_feature().
Expand Down Expand Up @@ -474,38 +464,49 @@ def intersecting_geometries(self, extent):
return iter(geoms)


BORDERS = NaturalEarthFeature('cultural', 'admin_0_boundary_lines_land',
'110m', edgecolor='black', facecolor='never')
"""Small scale (1:110m) country boundaries."""
auto_scaler = AdaptiveScaler('110m', (('50m', 50), ('10m', 15)))
"""AdaptiveScaler for NaturalEarthFeature. Default scale is '110m'.
'110m' is used above 50 degrees, '50m' for 50-15 degrees and '10m' below 15
degrees."""


BORDERS = NaturalEarthFeature(
'cultural', 'admin_0_boundary_lines_land',
auto_scaler, edgecolor='black', facecolor='never')
"""Automatically scaled country boundaries."""


STATES = NaturalEarthFeature(
'cultural', 'admin_1_states_provinces_lakes',
auto_scaler, edgecolor='black', facecolor='none')
"""Automatically scaled state and province boundaries."""

STATES = NaturalEarthFeature('cultural', 'admin_1_states_provinces_lakes',
'110m', edgecolor='black', facecolor='none')
"""Small scale (1:110m) state and province boundaries."""

COASTLINE = NaturalEarthFeature('physical', 'coastline', '110m',
edgecolor='black', facecolor='never')
"""Small scale (1:110m) coastline, including major islands."""
COASTLINE = NaturalEarthFeature(
'physical', 'coastline', auto_scaler,
edgecolor='black', facecolor='never')
"""Automatically scaled coastline, including major islands."""


LAKES = NaturalEarthFeature('physical', 'lakes', '110m',
edgecolor='face',
facecolor=COLORS['water'])
"""Small scale (1:110m) natural and artificial lakes."""
LAKES = NaturalEarthFeature(
'physical', 'lakes', auto_scaler,
edgecolor='face', facecolor=COLORS['water'])
"""Automatically scaled natural and artificial lakes."""


LAND = NaturalEarthFeature('physical', 'land', '110m',
edgecolor='face',
facecolor=COLORS['land'], zorder=-1)
"""Small scale (1:110m) land polygons, including major islands."""
LAND = NaturalEarthFeature(
'physical', 'land', auto_scaler,
edgecolor='face', facecolor=COLORS['land'], zorder=-1)
"""Automatically scaled land polygons, including major islands."""


OCEAN = NaturalEarthFeature('physical', 'ocean', '110m',
edgecolor='face',
facecolor=COLORS['water'], zorder=-1)
"""Small scale (1:110m) ocean polygons."""
OCEAN = NaturalEarthFeature(
'physical', 'ocean', auto_scaler,
edgecolor='face', facecolor=COLORS['water'], zorder=-1)
"""Automatically scaled ocean polygons."""


RIVERS = NaturalEarthFeature('physical', 'rivers_lake_centerlines', '110m',
edgecolor=COLORS['water'],
facecolor='never')
"""Small scale (1:110m) single-line drainages, including lake centerlines."""
RIVERS = NaturalEarthFeature(
'physical', 'rivers_lake_centerlines', auto_scaler,
edgecolor=COLORS['water'], facecolor='never')
"""Automatically scaled single-line drainages, including lake centerlines."""
20 changes: 5 additions & 15 deletions lib/cartopy/mpl/feature_artist.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# (C) British Crown Copyright 2011 - 2019, 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.

"""
This module defines the :class:`FeatureArtist` class, for drawing
:class:`Feature` instances with matplotlib.
Expand Down
32 changes: 13 additions & 19 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# (C) British Crown Copyright 2011 - 2020, 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.

"""
This module defines the :class:`GeoAxes` class, for use with matplotlib.

Expand Down Expand Up @@ -533,22 +523,26 @@ def format_coord(self, x, y):
return u'%.4g, %.4g (%f\u00b0%s, %f\u00b0%s)' % (x, y, abs(lat),
ns, abs(lon), ew)

def coastlines(self, resolution='110m', color='black', **kwargs):
def coastlines(self, resolution='auto', color='black', **kwargs):
"""
Add coastal **outlines** to the current axes from the Natural Earth
"coastline" shapefile collection.

Parameters
----------
resolution
resolution : str or :class:`cartopy.feature.Scaler`, optional
A named resolution to use from the Natural Earth
dataset. Currently can be one of "110m", "50m", and "10m",
or a Scaler object.
dataset. Currently can be one of "auto" (default), "110m", "50m",
and "10m", or a Scaler object.

"""
kwargs['edgecolor'] = color
kwargs['facecolor'] = 'none'
feature = cartopy.feature.COASTLINE

# The coastline feature is automatically scaled by default, but for
# anything else, including custom scaler instances, create a new
# feature which derives from the default one.
if resolution != 'auto':
feature = feature.with_scale(resolution)

Expand Down
51 changes: 20 additions & 31 deletions lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
# (C) British Crown Copyright 2011 - 2019, 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)

Expand Down Expand Up @@ -71,49 +60,49 @@ def test_gridliner():

ax = plt.subplot(nx, ny, 1, projection=ccrs.PlateCarree())
ax.set_global()
ax.coastlines()
ax.coastlines(resolution="110m")
ax.gridlines(linestyle=':')

ax = plt.subplot(nx, ny, 2, projection=ccrs.OSGB(approx=False))
ax.set_global()
ax.coastlines()
ax.coastlines(resolution="110m")
ax.gridlines(linestyle=':')

ax = plt.subplot(nx, ny, 3, projection=ccrs.OSGB(approx=False))
ax.set_global()
ax.coastlines()
ax.coastlines(resolution="110m")
ax.gridlines(ccrs.PlateCarree(), color='blue', linestyle='-')
ax.gridlines(ccrs.OSGB(approx=False), linestyle=':')

ax = plt.subplot(nx, ny, 4, projection=ccrs.PlateCarree())
ax.set_global()
ax.coastlines()
ax.coastlines(resolution="110m")
ax.gridlines(ccrs.NorthPolarStereo(), alpha=0.5,
linewidth=1.5, linestyle='-')

ax = plt.subplot(nx, ny, 5, projection=ccrs.PlateCarree())
ax.set_global()
ax.coastlines()
ax.coastlines(resolution="110m")
osgb = ccrs.OSGB(approx=False)
ax.set_extent(tuple(osgb.x_limits) + tuple(osgb.y_limits), crs=osgb)
ax.gridlines(osgb, linestyle=':')

ax = plt.subplot(nx, ny, 6, projection=ccrs.NorthPolarStereo())
ax.set_global()
ax.coastlines()
ax.coastlines(resolution="110m")
ax.gridlines(alpha=0.5, linewidth=1.5, linestyle='-')

ax = plt.subplot(nx, ny, 7, projection=ccrs.NorthPolarStereo())
ax.set_global()
ax.coastlines()
ax.coastlines(resolution="110m")
osgb = ccrs.OSGB(approx=False)
ax.set_extent(tuple(osgb.x_limits) + tuple(osgb.y_limits), crs=osgb)
ax.gridlines(osgb, linestyle=':')

ax = plt.subplot(nx, ny, 8,
projection=ccrs.Robinson(central_longitude=135))
ax.set_global()
ax.coastlines()
ax.coastlines(resolution="110m")
ax.gridlines(ccrs.PlateCarree(), alpha=0.5, linewidth=1.5, linestyle='-')

delta = 1.5e-2
Expand Down Expand Up @@ -184,14 +173,14 @@ def test_grid_labels():
crs_merc = ccrs.Mercator()

ax = fig.add_subplot(3, 2, 1, projection=crs_pc)
ax.coastlines()
ax.coastlines(resolution="110m")
ax.gridlines(draw_labels=True)

# Check that adding labels to Mercator gridlines gives an error.
# (Currently can only label PlateCarree gridlines.)
ax = fig.add_subplot(3, 2, 2,
projection=ccrs.PlateCarree(central_longitude=180))
ax.coastlines()
ax.coastlines(resolution="110m")

ax.set_title('Known bug')
gl = ax.gridlines(crs=crs_pc, draw_labels=True)
Expand All @@ -200,12 +189,12 @@ def test_grid_labels():
gl.xlines = False

ax = fig.add_subplot(3, 2, 3, projection=crs_merc)
ax.coastlines()
ax.coastlines(resolution="110m")
gl = ax.gridlines(draw_labels=True)
gl.xlabel_style = gl.ylabel_style = {'size': 9}

ax = plt.subplot(3, 2, 4, projection=crs_pc)
ax.coastlines()
ax.coastlines(resolution="110m")
gl = ax.gridlines(
crs=crs_pc, linewidth=2, color='gray', alpha=0.5, linestyle=':')
gl.bottom_labels = True
Expand All @@ -231,12 +220,12 @@ def test_grid_labels():

ax = fig.add_subplot(3, 2, 5, projection=crs_pc)
ax.set_extent([-20, 10.0, 45.0, 70.0])
ax.coastlines()
ax.coastlines(resolution="110m")
ax.gridlines(draw_labels=True)

ax = fig.add_subplot(3, 2, 6, projection=crs_merc)
ax.set_extent([-20, 10.0, 45.0, 70.0], crs=crs_pc)
ax.coastlines()
ax.coastlines(resolution="110m")
gl = ax.gridlines(draw_labels=True)
gl.rotate_labels = False
gl.xlabel_style = gl.ylabel_style = {'size': 9}
Expand All @@ -263,7 +252,7 @@ def test_grid_labels_inline():
ax.gridlines()
else:
ax.gridlines(draw_labels=True, auto_inline=True)
ax.coastlines()
ax.coastlines(resolution="110m")
ax.set_title(proj, y=1.075)
plt.subplots_adjust(wspace=0.35, hspace=0.35)

Expand Down Expand Up @@ -297,5 +286,5 @@ def test_grid_labels_inline_usa():
ax.gridlines()
else:
ax.gridlines(draw_labels=True, auto_inline=True, clip_on=True)
ax.coastlines()
ax.coastlines(resolution="110m")
plt.subplots_adjust(wspace=0.35, hspace=0.35)
29 changes: 9 additions & 20 deletions lib/cartopy/tests/mpl/test_mpl_integration.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
# (C) British Crown Copyright 2011 - 2020, 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)

Expand Down Expand Up @@ -198,7 +187,7 @@ def test_multiple_projections():

ax.set_global()

ax.coastlines()
ax.coastlines(resolution="110m")

plt.plot(-0.08, 51.53, 'o', transform=ccrs.PlateCarree())

Expand Down Expand Up @@ -472,7 +461,7 @@ def test_quiver_plate_carree():
# plot on native projection
ax = plt.subplot(211, projection=ccrs.PlateCarree())
ax.set_extent(plot_extent, crs=ccrs.PlateCarree())
ax.coastlines()
ax.coastlines(resolution="110m")
ax.quiver(x, y, u, v, mag)
# plot on a different projection
ax = plt.subplot(212, projection=ccrs.NorthPolarStereo())
Expand Down Expand Up @@ -556,12 +545,12 @@ def test_barbs():
# plot on native projection
ax = plt.subplot(211, projection=ccrs.PlateCarree())
ax.set_extent(plot_extent, crs=ccrs.PlateCarree())
ax.coastlines()
ax.coastlines(resolution="110m")
ax.barbs(x, y, u, v, length=4, linewidth=.25)
# plot on a different projection
ax = plt.subplot(212, projection=ccrs.NorthPolarStereo())
ax.set_extent(plot_extent, crs=ccrs.PlateCarree())
ax.coastlines()
ax.coastlines(resolution="110m")
ax.barbs(x, y, u, v, transform=ccrs.PlateCarree(), length=4, linewidth=.25)


Expand Down Expand Up @@ -614,7 +603,7 @@ def test_barbs_1d():
plt.figure(figsize=(6, 5))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent(plot_extent, crs=ccrs.PlateCarree())
ax.coastlines()
ax.coastlines(resolution="110m")
ax.barbs(x, y, u, v, transform=ccrs.PlateCarree(),
length=8, linewidth=1, color='#7f7f7f')

Expand Down
Loading