Skip to content

Commit

Permalink
ENH: Add Stadia Maps image tile server class
Browse files Browse the repository at this point in the history
The Stamen tiles are now being served by Stadia Maps. Stadia Maps
requires an API key, and has different naming convention for their
tiles, so create a new class to interact with the new server.
  • Loading branch information
greglucas committed Oct 12, 2023
1 parent f946084 commit 221091f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/reference/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ automatically load the proper tile and resolution depending on the desired domai
MapboxTiles
OrdnanceSurvey
QuadtreeTiles
StadiaMapsTiles
Stamen

Open Geospatial Consortium (OGC)
Expand Down
54 changes: 54 additions & 0 deletions lib/cartopy/io/img_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,57 @@ def _image_url(self, tile):
return f'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png'


class StadiaMapsTiles(GoogleWTS):
"""
Retrieves tiles from stadiamaps.com.
For a full reference on the styles available please see
https://docs.stadiamaps.com/themes/. A few of the specific styles
that are made available are ``alidade_smooth``, ``stamen_terrain`` and
``osm_bright``.
Using the Stadia Maps API requires including an attribution. Please see
https://docs.stadiamaps.com/attribution/ for details.
For most styles that means including the following attribution:
`© Stadia Maps <https://www.stadiamaps.com/>`_
`© OpenMapTiles <https://openmaptiles.org/>`_
`© OpenStreetMap contributors <https://www.openstreetmap.org/about/>`_
with Stamen styles *additionally* requiring the following attribution:
`© Stamen Design <https://stamen.com/>`_
Parameters
----------
apikey : str, required
The authentication key provided by Stadia Maps to query their APIs
style : str, optional
Name of the desired style. Defaults to ``alidade_smooth``.
See https://docs.stadiamaps.com/themes/ for a full list of styles.
cache : bool or str, optional
If True, the default cache directory is used. If False, no cache is
used. If a string, the string is used as the path to the cache.
"""

def __init__(self, apikey, style='alidade_smooth', cache=False):
super().__init__(cache=cache)
self.apikey = apikey
if style in ("alidade_satellite", "stamen_watercolor"):
# Known styles that have the jpg extension
self.extension = "jpg"
else:
self.extension = "png"
self.style = style

def _image_url(self, tile):
x, y, z = tile
return ("http://tiles.stadiamaps.com/tiles/"
f"{self.style}/{z}/{x}/{y}.{self.extension}"
f"?api_key={self.apikey}")


class Stamen(GoogleWTS):
"""
Retrieves tiles from maps.stamen.com. Styles include
Expand Down Expand Up @@ -351,6 +402,9 @@ class Stamen(GoogleWTS):

def __init__(self, style='toner',
desired_tile_form=None, cache=False):
warnings.warn("The Stamen styles are no longer served by Stamen and "
"are now served by Stadia Maps. Please use the "
"StadiaMapsTiles class instead.")

# preset layer configuration
layer_config = {
Expand Down

0 comments on commit 221091f

Please sign in to comment.