CoordinateReferenceSystem

class geodetic_engine.geodesy.CoordinateReferenceSystem[source]

Bases: object

A resolved CRS together with the axis roles and units it declares.

Wraps pyproj.CRS so that a caller never has to read PROJ’s source to find out how many axes a CRS has, what they mean, or what units they are in. Construction is cached, since resolving a CRS is expensive relative to transforming a point.

Example

>>> crs = CoordinateReferenceSystem.from_user_input("EPSG:4326")
>>> crs.axis_abbreviations
('Lat', 'Lon')
>>> crs.axis_units
('degree', 'degree')
>>> crs.dimension
2

The declared order above is EPSG’s. Coordinate values for this CRS are still ordered (lon, lat) everywhere in this package.

Wrap an already-resolved pyproj.CRS.

Prefer from_user_input(), which caches. This constructor exists for the case where a pyproj.CRS is already in hand.

Parameters:
  • crs (CRS) – The resolved CRS.

  • definition (str) – The input it was resolved from, kept for error messages and for repr().

__init__(crs, definition)[source]

Wrap an already-resolved pyproj.CRS.

Prefer from_user_input(), which caches. This constructor exists for the case where a pyproj.CRS is already in hand.

Parameters:
  • crs (CRS) – The resolved CRS.

  • definition (str) – The input it was resolved from, kept for error messages and for repr().

classmethod from_user_input(value)[source]

Resolve a CRS from an EPSG code, WKT, PROJ string or CRS object.

Parameters:

value (Any) – An authority code such as "EPSG:4326" or 4326, a WKT string, a PROJ string, a PROJJSON string, an OSDU persistableReference payload, an OSDU record id such as "opendes:reference-data--CoordinateReferenceSystem:Projected:EPSG::23031" (see from_osdu_id()), or an existing pyproj.CRS or CoordinateReferenceSystem.

Return type:

CoordinateReferenceSystem

Returns:

The resolved CRS.

Raises:

UnresolvableCRSError – If PROJ cannot construct a CRS from the input.

Example

>>> CoordinateReferenceSystem.from_user_input(4326).authority_code
'EPSG:4326'
classmethod from_persistable_reference(payload)[source]

Resolve a CRS from an OSDU persistableReference payload.

The payload carries its own definition, so the CRS is built from the ESRI WKT it states rather than from the authority code beside it. A payload that binds a transformation resolves to a bound CRS, which settles the datum shift that would otherwise be a choice. See geodetic_engine.persistablereference.

from_user_input() accepts these too, so a payload can be passed anywhere a CRS can. This is for when a caller wants the input read as a reference and nothing else.

Parameters:

payload (str) – The payload, plain or URL-encoded JSON.

Return type:

CoordinateReferenceSystem

Returns:

The resolved CRS.

Raises:

UnresolvableCRSError – If the payload is not a readable persistableReference, states something other than a CRS, or states a definition this package will not translate.

classmethod from_osdu_id(value)[source]

Resolve a CRS from the id of the OSDU record that publishes it.

The data partition and any version separator are dropped, and what remains is looked up exactly in the identifiers the active proj.db records. Those are written by geodetic_engine.osdudb from an OSDU catalogue, so the database has to have been built with geodetic-osdudb. A bound CRS’s id resolves to the bound CRS, transformation and all.

The id is never decoded from its spelling and never matched approximately, so an id that differs from a recorded one by a single character is refused rather than resolved to a near miss. See geodetic_engine.geodesy.osdu_id.

from_user_input() recognises full ids too. This also accepts a bare data.ID such as "Projected:EPSG::23031", since it can only mean a CRS here.

Parameters:

value (str) – The record id, with or without its partition, or the record’s data.ID.

Return type:

CoordinateReferenceSystem

Returns:

The resolved CRS.

Raises:

UnresolvableCRSError – If value is not an OSDU CRS record id, or the active proj.db records no such id.

Example

>>> CoordinateReferenceSystem.from_osdu_id(
...     "opendes:reference-data--CoordinateReferenceSystem:"
...     "BoundProjected:EPSG::23031_EPSG::1133"
... ).crs.is_bound
True
classmethod from_authority(auth_name, code)[source]

Resolve a CRS strictly by authority name and code.

Unlike from_user_input(), this never accepts WKT, PROJ strings, OSDU ids or persistableReferences: both tokens are validated before PROJ sees them so trailing text cannot turn an authority lookup into a PROJ string.

Parameters:
  • auth_name (str) – Authority name, for example "EPSG" or "OGC".

  • code (str | int) – Code within that authority, for example 4326 or "CRS84".

Return type:

CoordinateReferenceSystem

Returns:

The resolved CRS.

Raises:

UnresolvableCRSError – If either token is malformed or PROJ cannot resolve the authority and code as a CRS.

Example

>>> CoordinateReferenceSystem.from_authority("EPSG", 4326).authority_code
'EPSG:4326'
property crs: CRS

The underlying pyproj.CRS.

property definition: str

The input this CRS was resolved from.

property name: str

Human readable CRS name, for example "WGS 84".

property axes: tuple[AxisSpec, ...]

The CRS’s axes in EPSG-declared order, not in coordinate value order.

property axis_abbreviations: tuple[str, ...]

Axis abbreviations in EPSG-declared order, for example ("Lat", "Lon").

property axis_units: tuple[str, ...]

Axis unit names in EPSG-declared order, ("degree", "degree") for 4326.

property dimension: int

Number of axes the CRS declares.

property is_geographic: bool

Whether this CRS expresses position as latitude and longitude.

True through a bound CRS wrapping a geographic one, and through a compound CRS whose horizontal part is geographic.

property authority_code: str | None

"AUTH:CODE" if the CRS is identified in an authority, else None.

persistable_reference_from_catalog(*, database=None)[source]

The persistableReference an OSDU catalogue publishes for this CRS.

Read from a proj.db built by geodetic_engine.osdudb, which records it verbatim against the id of the record that publishes it, for EPSG CRSs the base proj.db defines as much as for those the build adds. The CRS is looked up by the OSDU id or authority code it was resolved from, so a bound CRS named by its id gets the bound CRS’s reference rather than that of the CRS it wraps. A CRS defined by WKT or PROJJSON is looked up by its authority code only when PROJ is certain of it.

This is the catalogue’s own string, to write into an OSDU record that names this CRS. To generate one from the definition instead, use to_persistable_reference().

Parameters:

database (Path | None, default: None) – The proj.db to read; the first on PROJ’s data path by default.

Return type:

CatalogPersistableReference | None

Returns:

The reference, or None when none is recorded – see missing_reference_reason().

Raises:

AmbiguousCatalogReferenceError – If records publishing different references name this CRS’s authority code.

Example

>>> crs = CoordinateReferenceSystem.from_osdu_id(
...     "BoundProjected:EPSG::23031_EPSG::1612"
... )
>>> crs.persistable_reference_from_catalog().kind
<Kind.EARLY_BOUND_CRS: 'EBC'>
property is_dynamic: bool

Whether any datum in this CRS is a dynamic reference frame.

Coordinates in a dynamic frame require a coordinate epoch to be meaningful, so this drives the epoch requirement in geodetic_engine.geodesy.transformation.

property value_axis_order: tuple[int, ...]

Indices of the declared axes, in coordinate value order.

Element i is the position, among axes, of the axis whose value comes i-th in the xy ordering this package uses. This is the bridge between what the EPSG dataset declares and the order values are actually in, and it is the thing a caller needs in order to label a coordinate correctly.

Axes are identified by direction, falling back to the abbreviation for polar CRSs whose axes share a direction: EPSG:32661 declares both of its axes pointing south, and only the N and E abbreviations distinguish them.

Returns:

A permutation of range(self.dimension).

Example

>>> crs = CoordinateReferenceSystem.from_user_input("EPSG:4326")
>>> crs.axis_abbreviations
('Lat', 'Lon')
>>> crs.value_axis_order
(1, 0)

So the first coordinate value is the axis at declared index 1, longitude.

property value_axis_abbreviations: tuple[str, ...]

Axis abbreviations in coordinate value order, ("Lon", "Lat") for 4326.