Expand description
Utilities for working with EPSG coordinate reference system definitions.
This crate provides three main capabilities:
- EPSG lookup – look up the WKT2 or PROJJSON representation of a CRS
by its EPSG code (via
epsg_to_wkt2andepsg_to_projjson). - Parsing – parse OGC WKT2 strings (
parse_wkt2) or PROJJSON strings (parse_projjson) into structured Rust types. - Conversion – convert between WKT2 and PROJJSON using
Crs::to_wkt2andCrs::to_projjson.
§Crate structure
The top-level Crs enum is the entry point for all parsed CRS data. It
dispatches to one of the concrete CRS types:
ProjectedCrs– a projected CRS (PROJCRS)GeogCrs– a geographic CRS (GEOGCRS)GeodCrs– a geodetic CRS (GEODCRS)VertCrs– a vertical CRS (VERTCRS)CompoundCrs– a compound CRS (COMPOUNDCRS)
These types and their components (datums, coordinate systems, ellipsoids,
etc.) live in the crs module and are all publicly accessible.
§Features
wkt2-definitions(enabled by default) – embeds compressed WKT2 strings for all supported EPSG codes, enablingepsg_to_wkt2.projjson-definitions(enabled by default) – embeds compressed PROJJSON strings for all supported EPSG codes, enablingepsg_to_projjson.
§Examples
§Look up an EPSG code
let wkt = epsg_utils::epsg_to_wkt2(6678).unwrap();
let projjson = epsg_utils::epsg_to_projjson(6678).unwrap();§Parse WKT2
let crs = epsg_utils::parse_wkt2(r#"PROJCRS["WGS 84 / UTM zone 31N",
BASEGEOGCRS["WGS 84", DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84", 6378137, 298.257223563]]],
CONVERSION["UTM zone 31N", METHOD["Transverse Mercator"]],
CS[Cartesian, 2],
ID["EPSG", 32631]]"#).unwrap();
assert_eq!(crs.to_epsg(), Some(32631));§Parse PROJJSON
let projjson = epsg_utils::epsg_to_projjson(6678).unwrap();
let crs = epsg_utils::parse_projjson(projjson).unwrap();
assert_eq!(crs.name, "JGD2011 / Japan Plane Rectangular CS X");§Convert between WKT2 and PROJJSON
let crs = epsg_utils::parse_wkt2(wkt).unwrap();
// To PROJJSON (serde_json::Value)
let projjson_value = crs.to_projjson();
// Back to WKT2
let wkt2 = crs.to_wkt2();§EPSG Dataset
The definitions in this crate are based on the EPSG Dataset v12.054, and cover 99.5% (7365/7396) of the EPSG codes (engineering CRS and derived projected CRS are not supported).
The EPSG Dataset is owned by the International Association of Oil & Gas Producers (IOGP). The source definitions included in this crate were downloaded from https://epsg.org/download-dataset.html.
Re-exports§
pub use crs::CompoundCrs;pub use crs::Crs;pub use crs::GeodCrs;pub use crs::GeogCrs;pub use crs::ProjectedCrs;pub use crs::VertCrs;
Modules§
Enums§
Functions§
- epsg_
to_ projjson - Look up the PROJJSON string for an EPSG projected CRS code.
- epsg_
to_ wkt2 - Look up the WKT2 string for an EPSG projected CRS code.
- parse_
projjson - Parse a PROJJSON string into a
ProjectedCrs. - parse_
wkt2 - Parse a WKT2 string into a
Crs.