rasterio.crs module

Coordinate Reference Systems

Notes

In Rasterio versions <= 1.0.13, coordinate reference system support was limited to the CRS that can be described by PROJ parameters. This limitation is gone in versions >= 1.0.14. Any CRS that can be defined using WKT (version 1) may be used.

class rasterio.crs.CRS(initialdata=None, **kwargs)

Bases: collections.abc.Mapping

A geographic or projected coordinate reference system

CRS objects may be created by passing PROJ parameters as keyword arguments to the standard constructor or by passing EPSG codes, PROJ mappings, PROJ strings, or WKT strings to the from_epsg, from_dict, from_string, or from_wkt class methods or static methods.

Examples

The from_dict method takes PROJ parameters as keyword arguments.

>>> crs = CRS.from_dict(init='epsg:3005')

EPSG codes may be used with the from_epsg method.

>>> crs = CRS.from_epsg(3005)

The from_string method takes a variety of input.

>>> crs = CRS.from_string('EPSG:3005')
property data

A PROJ4 dict representation of the CRS

classmethod from_dict(initialdata=None, **kwargs)

Make a CRS from a PROJ dict

Parameters
  • initialdata (mapping, optional) – A dictionary or other mapping

  • kwargs (mapping, optional) – Another mapping. Will be overlaid on the initialdata.

Returns

Return type

CRS

classmethod from_epsg(code)

Make a CRS from an EPSG code

Parameters

code (int or str) – An EPSG code. Strings will be converted to integers.

Notes

The input code is not validated against an EPSG database.

Returns

Return type

CRS

classmethod from_proj4(proj)

Make a CRS from a PROJ4 string

Parameters

proj (str) – A PROJ4 string like “+proj=longlat …”

Returns

Return type

CRS

classmethod from_string(string, morph_from_esri_dialect=False)

Make a CRS from an EPSG, PROJ, or WKT string

Parameters
  • string (str) – An EPSG, PROJ, or WKT string.

  • morph_from_esri_dialect (bool, optional) – If True, items in the input using Esri’s dialect of WKT will be replaced by OGC standard equivalents.

Returns

Return type

CRS

classmethod from_user_input(value, morph_from_esri_dialect=False)

Make a CRS from various input

Dispatches to from_epsg, from_proj, or from_string

Parameters
  • value (obj) – A Python int, dict, or str.

  • morph_from_esri_dialect (bool, optional) – If True, items in the input using Esri’s dialect of WKT will be replaced by OGC standard equivalents.

Returns

Return type

CRS

classmethod from_wkt(wkt, morph_from_esri_dialect=False)

Make a CRS from a WKT string

Parameters
  • wkt (str) – A WKT string.

  • morph_from_esri_dialect (bool, optional) – If True, items in the input using Esri’s dialect of WKT will be replaced by OGC standard equivalents.

Returns

Return type

CRS

property is_epsg_code

Test if the CRS is defined by an EPSG code

Returns

Return type

bool

property is_geographic

Test that the CRS is a geographic CRS

Returns

Return type

bool

property is_projected

Test that the CRS is a projected CRS

Returns

Return type

bool

property is_valid

Test that the CRS is a geographic or projected CRS

Notes

There are other types of CRS, such as compound or local or engineering CRS, but these are not supported in Rasterio 1.0.

Returns

Return type

bool

property linear_units

The linear units of the CRS

Possible values include “metre” and “US survey foot”.

Returns

Return type

str

property linear_units_factor

The linear units of the CRS and the conversion factor to meters.

The first element of the tuple is a string, its possible values include “metre” and “US survey foot”. The second element of the tuple is a float that represent the conversion factor of the raster units to meters.

Returns

Return type

tuple

to_dict()

Convert CRS to a PROJ4 dict

Notes

If there is a corresponding EPSG code, it will be used.

Returns

Return type

dict

to_epsg()

The epsg code of the CRS

Returns None if there is no corresponding EPSG code.

Returns

Return type

int

to_proj4()

Convert CRS to a PROJ4 string

Returns

Return type

str

to_string()

Convert CRS to a PROJ4 or WKT string

Notes

Mapping keys are tested against the all_proj_keys list. Values of True are omitted, leaving the key bare: {‘no_defs’: True} -> “+no_defs” and items where the value is otherwise not a str, int, or float are omitted.

Returns

Return type

str

to_wkt(morph_to_esri_dialect=False)

Convert CRS to its OGC WKT representation

Parameters

morph_to_esri_dialect (bool, optional) – Whether or not to morph to the Esri dialect of WKT

Returns

Return type

str

property wkt

An OGC WKT representation of the CRS

Returns

Return type

str