Skip to content

Commit 85568fa

Browse files
committed
Add Equidistant Cylindrical 'eqc' projection
1 parent 7127768 commit 85568fa

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

proj4rs/src/projections/eqc.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//!
2+
//! From proj/eqc.cpp
3+
//!
4+
//! See also <https://proj.org/operations/projections/eqc.html>
5+
//!
6+
//! Simplest of all projections
7+
//!
8+
//! eqc: "Equidistant Cylindrical (Plate Carree)"
9+
//!
10+
11+
use crate::ellps::Ellipsoid;
12+
use crate::errors::{Error, Result};
13+
use crate::parameters::ParamList;
14+
use crate::proj::ProjData;
15+
16+
// Projection stub
17+
super::projection! { eqc }
18+
19+
#[derive(Debug, Clone)]
20+
pub(crate) struct Projection {
21+
rc: f64,
22+
phi0: f64,
23+
}
24+
25+
impl Projection {
26+
pub fn eqc(p: &mut ProjData, params: &ParamList) -> Result<Self> {
27+
let rc = params.try_angular_value("lat_ts")?.unwrap_or(0.).cos();
28+
if rc <= 0. {
29+
return Err(Error::InvalidParameterValue("lat_ts should be <= 90°"));
30+
}
31+
p.ellps = Ellipsoid::sphere(p.ellps.a)?;
32+
Ok(Self { rc, phi0: p.phi0 })
33+
}
34+
35+
#[inline(always)]
36+
pub fn forward(&self, lam: f64, phi: f64, z: f64) -> Result<(f64, f64, f64)> {
37+
Ok((lam * self.rc, phi - self.phi0, z))
38+
}
39+
40+
#[inline(always)]
41+
pub fn inverse(&self, x: f64, y: f64, z: f64) -> Result<(f64, f64, f64)> {
42+
Ok((x / self.rc, y + self.phi0, z))
43+
}
44+
45+
pub const fn has_inverse() -> bool {
46+
true
47+
}
48+
49+
pub const fn has_forward() -> bool {
50+
true
51+
}
52+
}
53+
54+
55+
#[cfg(test)]
56+
mod tests {
57+
use crate::math::consts::EPS_10;
58+
use crate::proj::Proj;
59+
use crate::tests::utils::{test_proj_forward, test_proj_inverse};
60+
61+
#[test]
62+
fn proj_eqc_wgs84() {
63+
let p = Proj::from_proj_string("+proj=eqc +ellps=WGS84").unwrap();
64+
65+
println!("{:#?}", p.projection());
66+
67+
let inputs = [
68+
((2., 47., 0.), (222638.98158654713, 5232016.06728385761, 0.)),
69+
];
70+
71+
test_proj_forward(&p, &inputs, EPS_10);
72+
test_proj_inverse(&p, &inputs, EPS_10);
73+
}
74+
75+
#[test]
76+
fn proj_eqc_lat_ts() {
77+
let p = Proj::from_proj_string("+proj=eqc +lat_ts=30 +lon_0=-90").unwrap();
78+
79+
println!("{:#?}", p.projection());
80+
81+
let inputs = [
82+
((-88., 30., 0.), (192811.01392664597, 3339584.72379820701, 0.)),
83+
];
84+
85+
test_proj_forward(&p, &inputs, EPS_10);
86+
test_proj_inverse(&p, &inputs, EPS_10);
87+
}
88+
89+
}

proj4rs/src/projections/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ macro_rules! projection {
134134
use downcast;
135135
use projection;
136136

137-
const NUM_PROJECTIONS: usize = 21;
137+
const NUM_PROJECTIONS: usize = 22;
138138

139139
macro_rules! declare_projections {
140140
($(($name:ident $(,)? $($init:ident),*)),+ $(,)?) => {
@@ -161,6 +161,7 @@ macro_rules! declare_projections {
161161
// ---------------------------
162162

163163
pub mod aea;
164+
pub mod eqc;
164165
pub mod estmerc;
165166
pub mod etmerc;
166167
pub mod geocent;
@@ -190,6 +191,7 @@ declare_projections! [
190191
(laea),
191192
(moll, wag4, wag5),
192193
(geos),
194+
(eqc),
193195
];
194196

195197
///

projections.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
(laea),
1616
(moll, wag4, wag5),
1717
(geos),
18+
(eqc),
1819
]
1920
```
2021

@@ -25,7 +26,7 @@
2526
- [-] bonne
2627
- [-] cass
2728
- [-] cea
28-
- [-] eqc
29+
- [+] eqc
2930
- [-] eqdc
3031
- [-] eqearth
3132
- [-] equi

0 commit comments

Comments
 (0)