gistools/proj/project/
mod.rs

1/// Albers Conic Equal Area Projection
2pub mod aea;
3/// Azimuthal Equidistant Projection
4pub mod aeqd;
5/// Airy Projection
6pub mod airy;
7/// Bonne Projection
8pub mod bonne;
9/// Cassini-Soldner Projection
10pub mod cass;
11/// Equal Area Cylindrical Projection
12pub mod cea;
13/// Equidistant Cylindrical Projection
14pub mod eqc;
15/// Equidistant Conic Projection
16pub mod eqdc;
17/// Equal Earth Projection
18pub mod eqearth;
19/// Gnomonic Projection
20pub mod gnom;
21/// Goode Homolosine Projection
22pub mod goode;
23/// Gauss-Schreiber Transverse Mercator (aka Gauss-Laborde Reunion) Projection
24pub mod gstmerc;
25/// Krovak Projections
26pub mod krovak;
27/// Laborde Projection
28pub mod labrd;
29/// Lambert Azimuthal Equal Area Projection
30pub mod laea;
31/// Lambert Conformal Conic Projection
32pub mod lcc;
33/// Lambert Conformal Conic Alternative Projection
34pub mod lcca;
35/// Mercator/Web Mercator Projection
36pub mod merc;
37/// Military Grid Reference System Projection
38pub mod mgrs;
39/// Miller Cylindrical Projection
40pub mod mill;
41/// Mollweide Projections
42pub mod moll;
43/// New Zealand Map Grid Projection
44pub mod nzmg;
45/// Oblique Cylindrical Equal Area Projection
46pub mod ocea;
47/// Oblated Equal Area Projection
48pub mod oea;
49/// Oblique Mercator Projection
50pub mod omerc;
51/// Orthographic Projection
52pub mod ortho;
53/// Polyconic (American) Projection
54pub mod poly;
55/// Robinson Projection
56pub mod robin;
57/// Sinusoidal Projections
58pub mod sinu;
59/// Swiss Oblique Cylindrical Projection
60pub mod somerc;
61/// Stereographic Projection
62pub mod stere;
63/// Oblique Stereographic Alternative Projection
64pub mod sterea;
65/// Transverse Central Cylindrical Projection
66pub mod tcc;
67/// Transverse Cylindrical Equal Area Projection
68pub mod tcea;
69/// Transverse Mercator implementations
70pub mod tmerc;
71/// Van der Grinten (I) Projection
72pub mod vandg;
73
74use super::{CoordinateStep, DatumType, Proj, Step, TransformCoordinates};
75pub use aea::*;
76pub use aeqd::*;
77pub use airy::*;
78use alloc::rc::Rc;
79pub use bonne::*;
80pub use cass::*;
81pub use cea::*;
82use core::cell::RefCell;
83pub use eqc::*;
84pub use eqdc::*;
85pub use eqearth::*;
86pub use gnom::*;
87pub use goode::*;
88pub use gstmerc::*;
89pub use krovak::*;
90pub use labrd::*;
91pub use laea::*;
92pub use lcc::*;
93pub use lcca::*;
94pub use merc::*;
95pub use mgrs::*;
96pub use mill::*;
97pub use moll::*;
98pub use nzmg::*;
99pub use ocea::*;
100pub use oea::*;
101pub use omerc::*;
102pub use ortho::*;
103pub use poly::*;
104pub use robin::*;
105pub use sinu::*;
106pub use somerc::*;
107pub use stere::*;
108pub use sterea::*;
109pub use tcc::*;
110pub use tcea::*;
111pub use tmerc::*;
112pub use vandg::*;
113
114/// Projection trait. All projections must implement this
115pub trait ProjectCoordinates {
116    /// ESPG code for this projection
117    fn code(&self) -> i64;
118    /// Projection name
119    fn name(&self) -> &'static str;
120    /// Returns the list of canonical names for this projection.
121    /// This is an associated function, similar to a static method.
122    fn names() -> &'static [&'static str];
123    /// get the datum type. Defaults to no datum
124    fn datum_type() -> u8 {
125        DatumType::NoDatum as u8
126    }
127}
128
129/// Projection trait. All projections must implement this
130pub type LonLatProjection = BaseProjection;
131
132/// Base class for all projections
133#[derive(Debug, Default, Clone, PartialEq)]
134pub struct BaseProjection {}
135impl BaseProjection {
136    /// Create a list of steps for the base projection
137    pub fn to_step() -> Step {
138        let base_proj = BaseProjection {};
139        base_proj.into()
140    }
141}
142impl ProjectCoordinates for BaseProjection {
143    fn code(&self) -> i64 {
144        0
145    }
146    fn name(&self) -> &'static str {
147        "longlat"
148    }
149    fn names() -> &'static [&'static str] {
150        &["longlat", "identity"]
151    }
152}
153impl CoordinateStep for BaseProjection {
154    fn new(_proj: Rc<RefCell<Proj>>) -> Self {
155        BaseProjection {}
156    }
157    /// Forward projection from x-y to lon-lat. In this case, radians to degrees.
158    /// Input point is a placeholder for a lon-lat WGS84 point in radians
159    fn forward<P: TransformCoordinates>(&self, p: &mut P) {
160        p.set_x(p.lam().to_degrees());
161        p.set_y(p.phi().to_degrees());
162    }
163    /// Inverse projection from lon-lat to x-y. In this case, degrees to radians.
164    /// Input point is a placeholder for a lon-lat WGS84 point in degrees
165    fn inverse<P: TransformCoordinates>(&self, p: &mut P) {
166        p.set_lam(p.x().to_radians());
167        p.set_phi(p.y().to_radians());
168    }
169}
170impl From<BaseProjection> for Step {
171    fn from(p: BaseProjection) -> Step {
172        Step::Base(p.into())
173    }
174}