RasterSources and accessing WMS and WMTS

Implements RasterSource classes which can retrieve imagery from web services such as WMS and WMTS.

The matplotlib interface can make use of RasterSources via the cartopy.mpl.geoaxes.GeoAxes.add_raster() method, with additional specific methods which make use of this for WMS and WMTS (add_wms() and add_wmts()). An example of using WMTS in this way can be found at Interactive WMTS (Web Map Tile Service).

class cartopy.io.ogc_clients.WFSGeometrySource(service, features, getfeature_extra_kwargs=None)[source]

Web Feature Service (WFS) retrieval for Cartopy.

Parameters:
  • service – The URL of a WFS, or an instance of owslib.wfs.WebFeatureService.
  • features – The typename(s) of the features from the WFS that will be retrieved and made available as geometries.
  • getfeature_extra_kwargs (optional) – Extra keyword args to pass to the service’s getfeature call. Defaults to None
default_projection()[source]

Return a cartopy.crs.Projection in which the WFS service can supply the requested features.

fetch_geometries(projection, extent)[source]

Return any Point, Linestring or LinearRing geometries available from the WFS that lie within the specified extent.

Parameters:
  • projection (cartopy.crs.Projection) – The projection in which the extent is specified and in which the geometries should be returned. Only the default (native) projection is supported.
  • extent (four element tuple) – (min_x, max_x, min_y, max_y) tuple defining the geographic extent of the geometries to obtain.
Returns:

geoms – A list of Shapely geometries.

class cartopy.io.ogc_clients.WMSRasterSource(service, layers, getmap_extra_kwargs=None)[source]

A WMS imagery retriever which can be added to a map.

Note

Requires owslib and Pillow to work.

No caching of retrieved maps is done with this WMSRasterSource.

To reduce load on the WMS server it is encouraged to tile map requests and subsequently stitch them together to recreate a single raster, thus allowing for a more aggressive caching scheme, but this WMSRasterSource does not currently implement WMS tile fetching.

Whilst not the same service, there is also a WMTSRasterSource which makes use of tiles and comes with built-in caching for fast repeated map retrievals.

Parameters:
  • service (string or WebMapService instance) – The WebMapService instance, or URL of a WMS service, from whence to retrieve the image.
  • layers (string or list of strings) – The name(s) of layers to use from the WMS service.
  • getmap_extra_kwargs (dict, optional) – Extra keywords to pass through to the service’s getmap method. If None, a dictionary with {'transparent': True} will be defined.
fetch_raster(projection, extent, target_resolution)[source]

Return a sequence of images with extents given some constraining information.

Parameters:
  • projection (cartopy.crs.Projection) – The desired projection of the image.
  • extent (iterable of length 4) – The extent of the requested image in projected coordinates. The resulting image may not be defined exactly by these extents, and so the extent of the resulting image is also returned. The extents must be defined in the form (min_x, max_x, min_y, max_y).
  • target_resolution (iterable of length 2) – The desired resolution of the image as (width, height) in pixels.
Returns:

images – A sequence of LocatedImage instances.

getmap_extra_kwargs = None

Extra kwargs passed through to the service’s getmap request.

layers = None

The names of the layers to fetch.

service = None

The OWSLib WebMapService instance.

validate_projection(projection)[source]

Raise an error if this raster source cannot provide images in the specified projection.

Parameters:projection (cartopy.crs.Projection) – The desired projection of the image.
class cartopy.io.ogc_clients.WMTSRasterSource(wmts, layer_name, gettile_extra_kwargs=None)[source]

A WMTS imagery retriever which can be added to a map.

Uses tile caching for fast repeated map retrievals.

Note

Requires owslib and Pillow to work.

Parameters:
  • wmts – The URL of the WMTS, or an owslib.wmts.WebMapTileService instance.
  • layer_name – The name of the layer to use.
  • gettile_extra_kwargs (dict, optional) – Extra keywords (e.g. time) to pass through to the service’s gettile method.
fetch_raster(projection, extent, target_resolution)[source]

Return a sequence of images with extents given some constraining information.

Parameters:
  • projection (cartopy.crs.Projection) – The desired projection of the image.
  • extent (iterable of length 4) – The extent of the requested image in projected coordinates. The resulting image may not be defined exactly by these extents, and so the extent of the resulting image is also returned. The extents must be defined in the form (min_x, max_x, min_y, max_y).
  • target_resolution (iterable of length 2) – The desired resolution of the image as (width, height) in pixels.
Returns:

images – A sequence of LocatedImage instances.

layer = None

The layer to fetch.

validate_projection(projection)[source]

Raise an error if this raster source cannot provide images in the specified projection.

Parameters:projection (cartopy.crs.Projection) – The desired projection of the image.
wmts = None

The OWSLib WebMapTileService instance.