proj_core/lib.rs
1#![forbid(unsafe_code)]
2
3//! Pure-Rust coordinate transformation library.
4//!
5//! No C dependencies, no unsafe, WASM-compatible.
6//!
7//! The primary type is [`Transform`], which provides CRS-to-CRS coordinate
8//! transformation using authority codes (e.g., `"EPSG:4326"`).
9//! For area-aware or policy-constrained selection, use
10//! [`Transform::with_selection_options`] and inspect
11//! [`Transform::selected_operation`] /
12//! [`Transform::selection_diagnostics`].
13//! Operation selection ranks only embedded registry/generated-registry
14//! operations, explicit custom horizontal operations supplied in
15//! [`SelectionOptions`] or by parsers such as `proj-wkt`, and internal
16//! identity/no-datum-operation behavior. It does not synthesize Helmert, grid,
17//! or WGS84-compatible identity operations from datum metadata.
18//! The [`registry`], [`operation`], and [`grid`] modules expose the embedded
19//! operation catalog, selection metadata, and NTv2 grid-provider interfaces.
20//! `convert_3d` preserves `z` when no explicit vertical CRS is present or when
21//! source and target compound CRS definitions have identical vertical
22//! components. It converts `z` units when both vertical components use the same
23//! vertical reference frame with different linear units. Registry-backed GTX
24//! geoid operations can be selected for supported ellipsoidal-to-gravity height
25//! CRS pairs, while grid files still resolve through caller-supplied grid
26//! providers.
27//! Geographic antimeridian AOIs use
28//! [`AreaOfInterest::geographic_wrapped_bounds`], while ordinary projected and
29//! source/target bounds keep strict `min <= max` validation.
30//! With the default `geo-types` feature, [`Transform::convert_geometry`]
31//! transforms whole 2D `geo-types` geometries and fails on the first invalid
32//! coordinate without returning partial results.
33//!
34//! # Example
35//!
36//! ```
37//! use proj_core::Transform;
38//!
39//! // Create a transform from WGS84 geographic to Web Mercator
40//! let t = Transform::new("EPSG:4326", "EPSG:3857").unwrap();
41//!
42//! // Transform NYC coordinates (lon, lat in degrees) → (x, y in meters)
43//! let (x, y) = t.convert((-74.006, 40.7128)).unwrap();
44//! assert!((x - (-8238310.0)).abs() < 100.0);
45//!
46//! // Inverse: Web Mercator → WGS84
47//! let inv = Transform::new("EPSG:3857", "EPSG:4326").unwrap();
48//! let (lon, lat) = inv.convert((x, y)).unwrap();
49//! assert!((lon - (-74.006)).abs() < 1e-6);
50//! ```
51
52pub mod coord;
53pub mod crs;
54pub mod datum;
55pub mod ellipsoid;
56mod epsg_db;
57pub mod error;
58mod geocentric;
59pub mod grid;
60mod helmert;
61pub mod operation;
62mod projection;
63pub mod registry;
64mod selector;
65pub mod transform;
66
67pub use coord::{
68 Bounds, Coord, Coord3D, Transformable, Transformable3D, MAX_BOUNDS_DENSIFY_POINTS,
69};
70pub use crs::{
71 CompoundCrsDef, CrsDef, GeographicCrsDef, HorizontalCrsDef, LinearUnit, ProjectedCrsDef,
72 ProjectionMethod, VerticalCrsDef, VerticalCrsKind,
73};
74pub use datum::{Datum, DatumGridShift, DatumGridShiftEntry, DatumToWgs84, HelmertParams};
75pub use ellipsoid::Ellipsoid;
76pub use error::{Error, Result};
77pub use grid::{
78 EmbeddedGridProvider, FilesystemGridProvider, GridDefinition, GridError, GridFormat,
79 GridHandle, GridProvider, GridSample, VerticalGridSample,
80};
81pub use operation::{
82 AreaOfInterest, AreaOfInterestCrs, AreaOfUse, CoordinateOperation, CoordinateOperationId,
83 CoordinateOperationMetadata, GridCoverageMiss, GridId, GridInterpolation, GridShiftDirection,
84 OperationAccuracy, OperationMatchKind, OperationMethod, OperationSelectionDiagnostics,
85 OperationStep, OperationStepDirection, SelectionOptions, SelectionPolicy, SelectionReason,
86 SkippedOperation, SkippedOperationReason, TransformOutcome, VerticalGridOffsetConvention,
87 VerticalGridOperation, VerticalGridProvenance, VerticalTransformAction,
88 VerticalTransformDiagnostics,
89};
90pub use registry::{
91 lookup_authority_code, lookup_datum_code_for_crs, lookup_datum_epsg,
92 lookup_ellipsoid_code_for_datum, lookup_epsg, lookup_operation, lookup_vertical_epsg,
93 lookup_vertical_grid_operation, operation_candidates_between,
94 operation_candidates_between_with_selection_options, operations_between,
95 vertical_grid_operations_between,
96};
97pub use transform::Transform;
98#[cfg(feature = "geo-types")]
99pub use transform::TransformableGeometry;