The cartopy Feature interface

The data copyright, license and attribution can be blended on the map using text annotations (mpl docs) as shown in feature_creation.

class cartopy.feature.Feature(crs, **kwargs)[source]

Represents a collection of points, lines and polygons with convenience methods for common drawing and filtering operations.

Parameters:crs – The coordinate reference system of this Feature
Other Parameters:
 **kwargs – Keyword arguments to be used when drawing this feature.

See also

To add features to the current Matplotlib axes, see GeoAxes.

crs

The cartopy CRS for the geometries in this feature.

geometries()[source]

Return an iterator of (shapely) geometries for this feature.

intersecting_geometries(extent)[source]

Return an iterator of shapely geometries that intersect with the given extent. The extent is assumed to be in the CRS of the feature. If extent is None, the method returns all geometries for this dataset.

kwargs

The read-only dictionary of keyword arguments that are used when creating the Matplotlib artists for this feature.


Specific Feature subclasses have been defined for common functionality, such as accessing Natural Earth or GSHHS shapefiles.

class cartopy.feature.ShapelyFeature(geometries, crs, **kwargs)[source]

A class capable of drawing a collection of shapely geometries.

Parameters:
  • geometries – A collection of shapely geometries.
  • crs – The cartopy CRS in which the provided geometries are defined.
Other Parameters:
 

**kwargs – Keyword arguments to be used when drawing this feature.

class cartopy.feature.NaturalEarthFeature(category, name, scale, **kwargs)[source]

A simple interface to Natural Earth shapefiles.

See http://www.naturalearthdata.com/

Parameters:
  • category – The category of the dataset, i.e. either ‘cultural’ or ‘physical’.
  • name – The name of the dataset, e.g. ‘admin_0_boundary_lines_land’.
  • scale – The dataset scale, i.e. one of ‘10m’, ‘50m’, or ‘110m’, or Scaler object. Dataset scales correspond to 1:10,000,000, 1:50,000,000, and 1:110,000,000 respectively.
Other Parameters:
 

**kwargs – Keyword arguments to be used when drawing this feature.

with_scale(new_scale)[source]

Return a copy of the feature with a new scale.

Parameters:new_scale – The new dataset scale, i.e. one of ‘10m’, ‘50m’, or ‘110m’. Corresponding to 1:10,000,000, 1:50,000,000, and 1:110,000,000 respectively.
class cartopy.feature.GSHHSFeature(scale='auto', levels=None, **kwargs)[source]

An interface to the GSHHS dataset.

See https://www.ngdc.noaa.gov/mgg/shorelines/gshhs.html

Parameters:
  • scale – The dataset scale. One of ‘auto’, ‘coarse’, ‘low’, ‘intermediate’, ‘high, or ‘full’ (default is ‘auto’).
  • levels – A list of integers 1-4 corresponding to the desired GSHHS feature levels to draw (default is [1] which corresponds to coastlines).
Other Parameters:
 

**kwargs – Keyword arguments to be used when drawing the feature. Defaults are edgecolor=’black’ and facecolor=’none’.

class cartopy.feature.WFSFeature(wfs, features, **kwargs)[source]

A class capable of drawing a collection of geometries obtained from an OGC Web Feature Service (WFS).

This feature requires additional dependencies. If installed via pip, try pip install cartopy[ows].

Parameters:
  • wfs (string or owslib.wfs.WebFeatureService instance) – The WebFeatureService instance, or URL of a WFS service, from which to retrieve the geometries.
  • features (string or list of strings) – The typename(s) of features available from the web service that will be retrieved. Somewhat analogous to layers in WMS/WMTS.
Other Parameters:
 

**kwargs – Keyword arguments to be used when drawing this feature.

class cartopy.feature.AdaptiveScaler(default_scale, limits)[source]

Automatically select scale of geometries based on extent of plotted axes.

Parameters:
  • default_scale – Coarsest scale used as default when plot is at maximum extent.
  • limits – Scale-extent pairs at which scale of geometries change. Must be a tuple of tuples ordered from coarsest to finest scales. Limit values are the upper bounds for their corresponding scale.

Example

>>> s = AdaptiveScaler('coarse',
...           (('intermediate', 30), ('fine', 10)))
>>> s.scale_from_extent([-180, 180, -90, 90])
'coarse'
>>> s.scale_from_extent([-5, 6, 45, 56])
'intermediate'
>>> s.scale_from_extent([-5, 5, 45, 56])
'fine'

To simplify some very common cases, some pre-defined Features exist as cartopy.feature constants. The pre-defined Features are all small-scale (1:110m) Natural Earth datasets, and can be added with methods such as GeoAxes.add_feature:

Name Description
cartopy.feature.BORDERS
Country boundaries.
cartopy.feature.COASTLINE
Coastline, including major islands.
cartopy.feature.LAKES
Natural and artificial lakes.
cartopy.feature.LAND
Land polygons, including major islands.
cartopy.feature.OCEAN
Ocean polygons.
cartopy.feature.RIVERS
Single-line drainages, including lake centerlines.
cartopy.feature.STATES
Internal, first-order administrative boundaries (limited to the United States at this scale). Natural Earth have first-order admin boundaries for most countries at the 1:10,000,000 scale; these may be accessed with cartopy.feature.STATES.with_scale('10m')

Note

Any Natural Earth dataset can be used by creating an instance of cartopy.feature.NaturalEarthFeature. For example:

import cartopy.feature as cfeature
land_50m = cfeature.NaturalEarthFeature('physical', 'land', '50m',
                                        edgecolor='face',
                                        facecolor=cfeature.COLORS['land'])

A dictionary of some useful colors for drawing features also exists:

cartopy.feature.COLORS = {'land': array([0.9375 , 0.9375 , 0.859375]), 'land_alt1': array([0.859375, 0.859375, 0.859375]), 'water': array([0.59375 , 0.71484375, 0.8828125 ])}

A dictionary of colors useful for drawing Features.

The named keys in this dictionary represent the “type” of feature being plotted.

For a full list of names in this dictionary:

>>> import cartopy.feature
>>> sorted(cartopy.feature.COLORS.keys())
['land', 'land_alt1', 'water']

Example of using the Feature class with the Matplotlib interface

../_images/sphx_glr_feature_creation_0011.png