CRS¶
CRS¶
- class pyproj.crs.CRS(projparams: Any | None = None, **kwargs)[source]¶
A pythonic Coordinate Reference System manager.
Added in version 2.0.0.
See:
proj_create()
The functionality is based on other fantastic projects:
rasterio # noqa: E501
opendatacube # noqa: E501
- __init__(projparams: Any | None = None, **kwargs) None [source]¶
- Initialize a CRS class instance with:
PROJ string
Dictionary of PROJ parameters
PROJ keyword arguments for parameters
JSON string with PROJ parameters
CRS WKT string
An authority string [i.e. ‘epsg:4326’]
An EPSG integer code [i.e. 4326]
A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]
An object with a to_wkt method.
A
pyproj.crs.CRS
class
Example usage:
>>> from pyproj import CRS >>> crs_utm = CRS.from_user_input(26915) >>> crs_utm <Projected CRS: EPSG:26915> Name: NAD83 / UTM zone 15N Axis Info [cartesian]: - E[east]: Easting (metre) - N[north]: Northing (metre) Area of Use: - name: North America - 96°W to 90°W and NAD83 by country - bounds: (-96.0, 25.61, -90.0, 84.0) Coordinate Operation: - name: UTM zone 15N - method: Transverse Mercator Datum: North American Datum 1983 - Ellipsoid: GRS 1980 - Prime Meridian: Greenwich >>> crs_utm.area_of_use.bounds (-96.0, 25.61, -90.0, 84.0) >>> crs_utm.ellipsoid ELLIPSOID["GRS 1980",6378137,298.257222101, LENGTHUNIT["metre",1], ID["EPSG",7019]] >>> crs_utm.ellipsoid.inverse_flattening 298.257222101 >>> crs_utm.ellipsoid.semi_major_metre 6378137.0 >>> crs_utm.ellipsoid.semi_minor_metre 6356752.314140356 >>> crs_utm.prime_meridian PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8901]] >>> crs_utm.prime_meridian.unit_name 'degree' >>> crs_utm.prime_meridian.unit_conversion_factor 0.017453292519943295 >>> crs_utm.prime_meridian.longitude 0.0 >>> crs_utm.datum DATUM["North American Datum 1983", ELLIPSOID["GRS 1980",6378137,298.257222101, LENGTHUNIT["metre",1]], ID["EPSG",6269]] >>> crs_utm.coordinate_system CS[Cartesian,2], AXIS["(E)",east, ORDER[1], LENGTHUNIT["metre",1, ID["EPSG",9001]]], AXIS["(N)",north, ORDER[2], LENGTHUNIT["metre",1, ID["EPSG",9001]]] >>> print(crs_utm.coordinate_operation.to_wkt(pretty=True)) CONVERSION["UTM zone 15N", METHOD["Transverse Mercator", ID["EPSG",9807]], PARAMETER["Latitude of natural origin",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8801]], PARAMETER["Longitude of natural origin",-93, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8802]], PARAMETER["Scale factor at natural origin",0.9996, SCALEUNIT["unity",1], ID["EPSG",8805]], PARAMETER["False easting",500000, LENGTHUNIT["metre",1], ID["EPSG",8806]], PARAMETER["False northing",0, LENGTHUNIT["metre",1], ID["EPSG",8807]], ID["EPSG",16015]] >>> crs = CRS(proj='utm', zone=10, ellps='WGS84') >>> print(crs.to_wkt(pretty=True)) PROJCRS["unknown", BASEGEOGCRS["unknown", DATUM["Unknown based on WGS84 ellipsoid", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1], ID["EPSG",7030]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8901]]], CONVERSION["UTM zone 10N", METHOD["Transverse Mercator", ID["EPSG",9807]], PARAMETER["Latitude of natural origin",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8801]], PARAMETER["Longitude of natural origin",-123, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8802]], PARAMETER["Scale factor at natural origin",0.9996, SCALEUNIT["unity",1], ID["EPSG",8805]], PARAMETER["False easting",500000, LENGTHUNIT["metre",1], ID["EPSG",8806]], PARAMETER["False northing",0, LENGTHUNIT["metre",1], ID["EPSG",8807]], ID["EPSG",16010]], CS[Cartesian,2], AXIS["(E)",east, ORDER[1], LENGTHUNIT["metre",1, ID["EPSG",9001]]], AXIS["(N)",north, ORDER[2], LENGTHUNIT["metre",1, ID["EPSG",9001]]]] >>> geod = crs.get_geod() >>> f"+a={geod.a:.0f} +f={geod.f:.8f}" '+a=6378137 +f=0.00335281' >>> crs.is_projected True >>> crs.is_geographic False
- property area_of_use: AreaOfUse | None¶
returns: The area of use object with associated attributes. :rtype: AreaOfUse
- property axis_info: list[Axis]¶
Retrieves all relevant axis information in the CRS. If it is a Bound CRS, it gets the axis list from the Source CRS. If it is a Compound CRS, it gets the axis list from the Sub CRS list.
- property coordinate_operation: CoordinateOperation | None¶
Added in version 2.2.0.
- Return type:
- property coordinate_system: CoordinateSystem | None¶
Added in version 2.2.0.
- Return type:
- cs_to_cf() list[dict] [source]¶
Added in version 3.0.0.
This converts all coordinate systems (cs) in the CRS to a list of Climate and Forecast (CF) Version 1.8 dicts.
- property ellipsoid: Ellipsoid | None¶
Added in version 2.2.0.
- Returns:
The ellipsoid object with associated attributes.
- Return type:
- equals(other: Any, ignore_axis_order: bool = False) bool [source]¶
Added in version 2.5.0.
Check if the CRS objects are equivalent.
- Parameters:
other (Any) – Check if the other object is equivalent to this object. If the other object is not a CRS, it will try to create one. On Failure, it will return False.
ignore_axis_order (bool, default=False) – If True, it will compare the CRS class and ignore the axis order.
- Return type:
- classmethod from_authority(auth_name: str, code: str | int) CRS [source]¶
Added in version 2.2.0.
Make a CRS from an authority name and authority code
- static from_cf(in_cf: dict, ellipsoidal_cs: Any | None = None, cartesian_cs: Any | None = None, vertical_cs: Any | None = None) CRS [source]¶
Added in version 2.2.0.
Added in version 3.0.0: ellipsoidal_cs, cartesian_cs, vertical_cs
This converts a Climate and Forecast (CF) Grid Mapping Version 1.8 dict to a
pyproj.crs.CRS
object.- Parameters:
in_cf (dict) – CF version of the projection.
ellipsoidal_cs (Any, optional) – Input to create an Ellipsoidal Coordinate System. Anything accepted by
pyproj.crs.CoordinateSystem.from_user_input()
or an Ellipsoidal Coordinate System created from Coordinate Systems.cartesian_cs (Any, optional) – Input to create a Cartesian Coordinate System. Anything accepted by
pyproj.crs.CoordinateSystem.from_user_input()
orpyproj.crs.coordinate_system.Cartesian2DCS
.vertical_cs (Any, optional) – Input to create a Vertical Coordinate System accepted by
pyproj.crs.CoordinateSystem.from_user_input()
orpyproj.crs.coordinate_system.VerticalCS
- Return type:
- classmethod from_dict(proj_dict: dict) CRS [source]¶
Added in version 2.2.0.
Make a CRS from a dictionary of PROJ parameters.
- classmethod from_json(crs_json: str) CRS [source]¶
Added in version 2.4.0.
Create CRS from a CRS JSON string.
- classmethod from_json_dict(crs_dict: dict) CRS [source]¶
Added in version 2.4.0.
Create CRS from a JSON dictionary.
- classmethod from_proj4(in_proj_string: str) CRS [source]¶
Added in version 2.2.0.
Make a CRS from a PROJ string
- classmethod from_string(in_crs_string: str) CRS [source]¶
Make a CRS from:
- Initialize a CRS class instance with:
PROJ string
JSON string with PROJ parameters
CRS WKT string
An authority string [i.e. ‘epsg:4326’]
- classmethod from_user_input(value: Any, **kwargs) CRS [source]¶
- Initialize a CRS class instance with:
PROJ string
Dictionary of PROJ parameters
PROJ keyword arguments for parameters
JSON string with PROJ parameters
CRS WKT string
An authority string [i.e. ‘epsg:4326’]
An EPSG integer code [i.e. 4326]
A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]
An object with a to_wkt method.
A
pyproj.crs.CRS
class
- Parameters:
value (obj) – A Python int, dict, or str.
- Return type:
- classmethod from_wkt(in_wkt_string: str) CRS [source]¶
Added in version 2.2.0.
Make a CRS from a WKT string
- property geodetic_crs: CRS | None¶
Added in version 2.2.0.
- Returns:
The geodeticCRS / geographicCRS from the CRS.
- Return type:
- get_non_deprecated() list[CRS] [source]¶
Added in version 3.7.0.
Return a list of non-deprecated objects related to this.
- property is_derived¶
Added in version 3.2.0.
- Returns:
True if CRS is a Derived CRS.
- Return type:
- property is_engineering: bool¶
Added in version 2.2.0.
- Returns:
True if CRS is local/engineering.
- Return type:
- is_exact_same(other: Any) bool [source]¶
Check if the CRS objects are the exact same.
- Parameters:
other (Any) – Check if the other CRS is the exact same to this object. If the other object is not a CRS, it will try to create one. On Failure, it will return False.
- Return type:
- property is_geocentric: bool¶
This checks if the CRS is geocentric and takes into account if the CRS is bound.
- Returns:
True if CRS is in geocentric (x/y) coordinates.
- Return type:
- property is_geographic: bool¶
This checks if the CRS is geographic. It will check if it has a geographic CRS in the sub CRS if it is a compound CRS and will check if the source CRS is geographic if it is a bound CRS.
- Returns:
True if the CRS is in geographic (lon/lat) coordinates.
- Return type:
- property is_projected: bool¶
This checks if the CRS is projected. It will check if it has a projected CRS in the sub CRS if it is a compound CRS and will check if the source CRS is projected if it is a bound CRS.
- Returns:
True if CRS is projected.
- Return type:
- property is_vertical: bool¶
Added in version 2.2.0.
This checks if the CRS is vertical. It will check if it has a vertical CRS in the sub CRS if it is a compound CRS and will check if the source CRS is vertical if it is a bound CRS.
- Returns:
True if CRS is vertical.
- Return type:
- list_authority(auth_name: str | None = None, min_confidence: int = 70) list[AuthorityMatchInfo] [source]¶
Added in version 3.2.0.
Return the authority names and codes best matching the CRS.
Example:
>>> from pyproj import CRS >>> ccs = CRS("EPSG:4328") >>> ccs.list_authority() [AuthorityMatchInfo(auth_name='EPSG', code='4326', confidence=100)]
If the CRS is bound, you can get an authority from the source CRS:
>>> from pyproj import CRS >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0") >>> ccs.list_authority() [] >>> ccs.source_crs.list_authority() [AuthorityMatchInfo(auth_name='EPSG', code='4978', confidence=70)] >>> ccs == CRS.from_authorty('EPSG', '4978') False
- Parameters:
auth_name (str, optional) – The name of the authority to filter by.
min_confidence (int, default=70) – A value between 0-100 where 100 is the most confident. Why does the EPSG code return when using EPSG:xxxx and not with +init=EPSG:xxxx?
- Returns:
List of authority matches for the CRS.
- Return type:
list[AuthorityMatchInfo]
- property prime_meridian: PrimeMeridian | None¶
Added in version 2.2.0.
- Returns:
The prime meridian object with associated attributes.
- Return type:
- property source_crs: CRS | None¶
The base CRS of a BoundCRS or a DerivedCRS/ProjectedCRS, or the source CRS of a CoordinateOperation.
- Return type:
- property sub_crs_list: list[CRS]¶
If the CRS is a compound CRS, it will return a list of sub CRS objects.
- property target_crs: CRS | None¶
Added in version 2.2.0.
- Returns:
The hub CRS of a BoundCRS or the target CRS of a CoordinateOperation.
- Return type:
- to_2d(name: str | None = None) CRS [source]¶
Added in version 3.6.0.
Convert the current CRS to the 2D version if it makes sense.
- to_3d(name: str | None = None) CRS [source]¶
Added in version 3.1.0.
Convert the current CRS to the 3D version if it makes sense.
- New vertical axis attributes:
ellipsoidal height
oriented upwards
metre units
- to_authority(auth_name: str | None = None, min_confidence: int = 70)[source]¶
Added in version 2.2.0.
Return the authority name and code best matching the CRS or None if it a match is not found.
Example:
>>> from pyproj import CRS >>> ccs = CRS("EPSG:4328") >>> ccs.to_authority() ('EPSG', '4328')
If the CRS is bound, you can get an authority from the source CRS:
>>> from pyproj import CRS >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0") >>> ccs.to_authority() >>> ccs.source_crs.to_authority() ('EPSG', '4978') >>> ccs == CRS.from_authorty('EPSG', '4978') False
- Parameters:
auth_name (str, optional) – The name of the authority to filter by.
min_confidence (int, default=70) – A value between 0-100 where 100 is the most confident. Why does the EPSG code return when using EPSG:xxxx and not with +init=EPSG:xxxx?
- Returns:
The best matching (<auth_name>, <code>) for the confidence level.
- Return type:
- to_cf(wkt_version: WktVersion | str = WktVersion.WKT2_2019, errcheck: bool = False) dict [source]¶
Added in version 2.2.0.
This converts a
pyproj.crs.CRS
object to a Climate and Forecast (CF) Grid Mapping Version 1.8 dict.- Parameters:
wkt_version (str or pyproj.enums.WktVersion) – Version of WKT supported by CRS.to_wkt. Default is
pyproj.enums.WktVersion.WKT2_2019
.errcheck (bool, default=False) – If True, will warn when parameters are ignored.
- Returns:
CF-1.8 version of the projection.
- Return type:
- to_dict() dict [source]¶
Added in version 2.2.0.
Converts the CRS to dictionary of PROJ parameters.
Warning
You will likely lose important projection information when converting to a PROJ string from another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems # noqa: E501
- Returns:
PROJ params in dict format.
- Return type:
- to_epsg(min_confidence: int = 70) int | None [source]¶
Return the EPSG code best matching the CRS or None if it a match is not found.
Example:
>>> from pyproj import CRS >>> ccs = CRS("EPSG:4328") >>> ccs.to_epsg() 4328
If the CRS is bound, you can attempt to get an epsg code from the source CRS:
>>> from pyproj import CRS >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0") >>> ccs.to_epsg() >>> ccs.source_crs.to_epsg() 4978 >>> ccs == CRS.from_epsg(4978) False
- Parameters:
min_confidence (int, default=70) – A value between 0-100 where 100 is the most confident. Why does the EPSG code return when using EPSG:xxxx and not with +init=EPSG:xxxx?
- Returns:
The best matching EPSG code matching the confidence level.
- Return type:
int | None
- to_json(pretty: bool = False, indentation: int = 2) str [source]¶
Added in version 2.4.0.
Convert the object to a JSON string.
- to_json_dict() dict [source]¶
Added in version 2.4.0.
Convert the object to a JSON dictionary.
- Return type:
- to_proj4(version: ProjVersion | int = ProjVersion.PROJ_5) str [source]¶
Convert the projection to a PROJ string.
Warning
You will likely lose important projection information when converting to a PROJ string from another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems # noqa: E501
- Parameters:
version (pyproj.enums.ProjVersion) – The version of the PROJ string output. Default is
pyproj.enums.ProjVersion.PROJ_4
.- Return type:
- to_string() str [source]¶
Added in version 2.2.0.
Convert the CRS to a string.
It attempts to convert it to the authority string. Otherwise, it uses the string format of the user input to create the CRS.
- Return type:
- to_wkt(version: WktVersion | str = WktVersion.WKT2_2019, pretty: bool = False, output_axis_rule: bool | None = None) str [source]¶
Convert the projection to a WKT string.
- Version options:
WKT2_2015
WKT2_2015_SIMPLIFIED
WKT2_2019
WKT2_2019_SIMPLIFIED
WKT1_GDAL
WKT1_ESRI
Added in version 3.6.0: output_axis_rule
- Parameters:
version (pyproj.enums.WktVersion, optional) – The version of the WKT output. Default is
pyproj.enums.WktVersion.WKT2_2019
.pretty (bool, default=False) – If True, it will set the output to be a multiline string.
output_axis_rule (bool, optional, default=None) – If True, it will set the axis rule on any case. If false, never. None for AUTO, that depends on the CRS and version.
- Return type:
GeographicCRS¶
- class pyproj.crs.GeographicCRS(name: str = 'undefined', datum: Any = 'urn:ogc:def:ensemble:EPSG::6326', ellipsoidal_cs: Any | None = None)[source]¶
Bases:
CustomConstructorCRS
Added in version 2.5.0.
This class is for building a Geographic CRS
- __init__(name: str = 'undefined', datum: Any = 'urn:ogc:def:ensemble:EPSG::6326', ellipsoidal_cs: Any | None = None) None [source]¶
- Parameters:
name (str, default="undefined") – Name of the CRS.
datum (Any, default=”urn:ogc:def:ensemble:EPSG::6326”) – Anything accepted by
pyproj.crs.Datum.from_user_input()
or apyproj.crs.datum.CustomDatum
.ellipsoidal_cs (Any, optional) – Input to create an Ellipsoidal Coordinate System. Anything accepted by
pyproj.crs.CoordinateSystem.from_user_input()
or an Ellipsoidal Coordinate System created from Coordinate Systems.
DerivedGeographicCRS¶
- class pyproj.crs.DerivedGeographicCRS(base_crs: Any, conversion: Any, ellipsoidal_cs: Any | None = None, name: str = 'undefined')[source]¶
Bases:
CustomConstructorCRS
Added in version 2.5.0.
This class is for building a Derived Geographic CRS
- __init__(base_crs: Any, conversion: Any, ellipsoidal_cs: Any | None = None, name: str = 'undefined') None [source]¶
- Parameters:
base_crs (Any) – Input to create the Geodetic CRS, a
GeographicCRS
or anything accepted bypyproj.crs.CRS.from_user_input()
.conversion (Any) – Anything accepted by
pyproj.crs.CoordinateSystem.from_user_input()
or a conversion from Coordinate Operations.ellipsoidal_cs (Any, optional) – Input to create an Ellipsoidal Coordinate System. Anything accepted by
pyproj.crs.CoordinateSystem.from_user_input()
or an Ellipsoidal Coordinate System created from Coordinate Systems.name (str, default="undefined") – Name of the CRS.
GeocentricCRS¶
- class pyproj.crs.GeocentricCRS(name: str = 'undefined', datum: Any = 'urn:ogc:def:datum:EPSG::6326')[source]¶
Bases:
CustomConstructorCRS
Added in version 3.2.0.
This class is for building a Geocentric CRS
- __init__(name: str = 'undefined', datum: Any = 'urn:ogc:def:datum:EPSG::6326') None [source]¶
- Parameters:
name (str, default="undefined") – Name of the CRS.
datum (Any, default=”urn:ogc:def:datum:EPSG::6326”) – Anything accepted by
pyproj.crs.Datum.from_user_input()
or apyproj.crs.datum.CustomDatum
.
ProjectedCRS¶
- class pyproj.crs.ProjectedCRS(conversion: Any, name: str = 'undefined', cartesian_cs: Any | None = None, geodetic_crs: Any | None = None)[source]¶
Bases:
CustomConstructorCRS
Added in version 2.5.0.
This class is for building a Projected CRS.
- __init__(conversion: Any, name: str = 'undefined', cartesian_cs: Any | None = None, geodetic_crs: Any | None = None) None [source]¶
- Parameters:
conversion (Any) – Anything accepted by
pyproj.crs.CoordinateSystem.from_user_input()
or a conversion from Coordinate Operations.name (str, optional) – The name of the Projected CRS. Default is undefined.
cartesian_cs (Any, optional) – Input to create a Cartesian Coordinate System. Anything accepted by
pyproj.crs.CoordinateSystem.from_user_input()
orpyproj.crs.coordinate_system.Cartesian2DCS
.geodetic_crs (Any, optional) – Input to create the Geodetic CRS, a
GeographicCRS
or anything accepted bypyproj.crs.CRS.from_user_input()
.
VerticalCRS¶
- class pyproj.crs.VerticalCRS(name: str, datum: Any, vertical_cs: Any | None = None, geoid_model: str | None = None)[source]¶
Bases:
CustomConstructorCRS
Added in version 2.5.0.
This class is for building a Vertical CRS.
Warning
geoid_model support only exists in PROJ >= 6.3.0
- __init__(name: str, datum: Any, vertical_cs: Any | None = None, geoid_model: str | None = None) None [source]¶
- Parameters:
name (str) – The name of the Vertical CRS (e.g. NAVD88 height).
datum (Any) – Anything accepted by
pyproj.crs.Datum.from_user_input()
vertical_cs (Any, optional) – Input to create a Vertical Coordinate System accepted by
pyproj.crs.CoordinateSystem.from_user_input()
orpyproj.crs.coordinate_system.VerticalCS
geoid_model (str, optional) – The name of the GEOID Model (e.g. GEOID12B).
BoundCRS¶
CompoundCRS¶
CustomConstructorCRS¶
- class pyproj.crs.CustomConstructorCRS(projparams: Any | None = None, **kwargs)[source]¶
Bases:
CRS
This class is a base class for CRS classes that use a different constructor than the main CRS class.
Added in version 3.2.0.
See: https://github.com/pyproj4/pyproj/issues/847
- classmethod from_user_input(value: Any, **kwargs) CRS [source]¶
- Initialize a CRS class instance with:
PROJ string
Dictionary of PROJ parameters
PROJ keyword arguments for parameters
JSON string with PROJ parameters
CRS WKT string
An authority string [i.e. ‘epsg:4326’]
An EPSG integer code [i.e. 4326]
A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)]
An object with a to_wkt method.
A
pyproj.crs.CRS
class
- Parameters:
value (obj) – A Python int, dict, or str.
- Return type:
- property geodetic_crs: CRS | None¶
Added in version 2.2.0.
- Returns:
The geodeticCRS / geographicCRS from the CRS.
- Return type:
- property source_crs: CRS | None¶
The base CRS of a BoundCRS or a DerivedCRS/ProjectedCRS, or the source CRS of a CoordinateOperation.
- Return type:
- property sub_crs_list: list[CRS]¶
If the CRS is a compound CRS, it will return a list of sub CRS objects.
- property target_crs: CRS | None¶
Added in version 2.2.0.
- Returns:
The hub CRS of a BoundCRS or the target CRS of a CoordinateOperation.
- Return type: