CRS and projections

Cartopy provides few default projections, documented on their webpage. Cartes extends these definitions with a full set of projections as defined by the libproj C library.

Introduction example

For instance, the Lambert93 projection is the default official one in France, used for tiles by the National Geographic Institute (IGN).

from cartes.crs import Lambert93
Lambert93()
2021-03-10T14:37:24.321619 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
<abc.EPSG_2154 object at 0x7fbc61e1e130>

As displayed above, Lambert93 is nothing more than an alias for an EPSG specification. It is possible to obtain the same result with the following code.

from cartes.crs import EPSG_2154
EPSG_2154()

Warning

Classes are generated dynamically based on their description in the libproj library. A star import would not work here.

Valid projections at a given location

A list of valid projections is available with a call to the valid_crs functioni which accepts a string or any object implementing the __geo_interface__ protocol:

from cartes.crs import valid_crs
valid_crs("Rome, Italy")
area auth_name code deprecated name projection_method_name
0 Europe - between 12°E and 18°E onshore and off... EPSG 23033 False ED50 / UTM zone 33N Transverse Mercator
1 Italy - onshore and offshore - east of 12°E in... EPSG 3004 False Monte Mario / Italy zone 2 Transverse Mercator
2 Europe - European Union (EU) countries and can... EPSG 3034 False ETRS89-extended / LCC Europe Lambert Conic Conformal (2SP)
3 Europe - European Union (EU) countries and can... EPSG 3035 False ETRS89-extended / LAEA Europe Lambert Azimuthal Equal Area
4 Italy - onshore and offshore - east of 12°E in... EPSG 3065 False IGM95 / UTM zone 33N Transverse Mercator
... ... ... ... ... ... ...
20 Italy - onshore and offshore. EPSG 7794 False RDN2008 / Italy zone (E-N) Transverse Mercator
21 Italy - onshore and offshore. EPSG 7795 False RDN2008 / Zone 12 (E-N) Transverse Mercator
22 World. EPSG 8857 False WGS 84 / Equal Earth Greenwich Equal Earth
23 World centred on the Americas. EPSG 8858 False WGS 84 / Equal Earth Americas Equal Earth
24 World centred on Asia-Pacific. EPSG 8859 False WGS 84 / Equal Earth Asia-Pacific Equal Earth

You can then pick one for your future needs:

from cartes.crs import EPSG_3034
EPSG_3034()
2021-03-10T14:57:16.819087 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
<abc.EPSG_3034 object at 0x7fbc5618b770>

Adjusting bounds for a projection

Some definitions in the library set very narrow bounds which are then incompatible with plotting in a larger area. It is possible to set different bounds by subclassing the projection.

from cartes import crs
crs.EPSG_6674()
2021-03-10T15:06:14.211535 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
<abc.EPSG_6674 object at 0x7fbc4d455680>
class Custom(crs.EPSG_6674):
    bbox = {
        "east_longitude": 151,
        "north_latitude": 47,
        "south_latitude": 25,
        "west_longitude": 124,
    }

Custom()
2021-03-10T15:06:22.322129 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/
<__main__.Custom object at 0x7fbc4d348090>

Tip

See also: Projections in Altair