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.MappingA 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
Make a CRS from an authority name and authority code
New in version 1.1.7.
- Parameters
auth_name (str) – The name of the authority.
code (int or str) – The code used by the authority.
- Returns
- Return type
-
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
-
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
-
classmethod
from_proj4(proj)¶ Make a CRS from a PROJ4 string
- Parameters
proj (str) – A PROJ4 string like “+proj=longlat …”
- Returns
- Return type
-
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
-
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
-
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
-
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
The authority name and code of the CRS
New in version 1.1.7.
- Returns
- Return type
(str, str) or None
-
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_keyslist. Values ofTrueare 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, version=None)¶ Convert CRS to its OGC WKT representation
New in version 1.3.0: version
- Parameters
morph_to_esri_dialect (bool, optional) – Whether or not to morph to the Esri dialect of WKT. Only works for GDAL 2.
version (WktVersion or str, optional) – The version of the WKT output. Only works with GDAL 3+. Default is WKT1_GDAL.
- Returns
- Return type
str
-
property
wkt¶ An OGC WKT representation of the CRS
- Returns
- Return type
str
-
property
-
rasterio.crs.epsg_treats_as_latlong(input)¶ Test if the CRS is in latlon order
From GDAL docs:
> This method returns TRUE if EPSG feels this geographic coordinate system should be treated as having lat/long coordinate ordering.
> Currently this returns TRUE for all geographic coordinate systems with an EPSG code set, and axes set defining it as lat, long.
> FALSE will be returned for all coordinate systems that are not geographic, or that do not have an EPSG code set.
> Note
> Important change of behavior since GDAL 3.0. In previous versions, geographic CRS imported with importFromEPSG() would cause this method to return FALSE on them, whereas now it returns TRUE, since importFromEPSG() is now equivalent to importFromEPSGA().
- Parameters
input (CRS) – Coordinate reference system, as a rasterio CRS object Example: CRS({‘init’: ‘EPSG:4326’})
- Returns
- Return type
bool
-
rasterio.crs.epsg_treats_as_northingeasting(input)¶ Test if the CRS should be treated as having northing/easting coordinate ordering
From GDAL docs:
> This method returns TRUE if EPSG feels this projected coordinate system should be treated as having northing/easting coordinate ordering.
> Currently this returns TRUE for all projected coordinate systems with an EPSG code set, and axes set defining it as northing, easting.
> FALSE will be returned for all coordinate systems that are not projected, or that do not have an EPSG code set.
> Note
> Important change of behavior since GDAL 3.0. In previous versions, projected CRS with northing, easting axis order imported with importFromEPSG() would cause this method to return FALSE on them, whereas now it returns TRUE, since importFromEPSG() is now equivalent to importFromEPSGA().
- Parameters
input (CRS) – Coordinate reference system, as a rasterio CRS object Example: CRS({‘init’: ‘EPSG:4326’})
- Returns
- Return type
bool