gistools/proj/transform/
mod.rs1pub mod step;
3pub mod transformer;
5
6use super::{BaseProjection, Coords, Proj};
7use alloc::{boxed::Box, rc::Rc};
8use core::cell::RefCell;
9use s2json::VectorPoint;
10pub use step::*;
11pub use transformer::*;
12
13#[derive(Debug, Clone, PartialEq)]
16pub struct ProjectionTransform {
17 pub proj: Rc<RefCell<Proj>>,
19 pub method: Step,
21 pub axisswap: Option<Box<ProjectionTransform>>,
24 pub cart: Option<Box<ProjectionTransform>>,
26 pub cart_wgs84: Option<Box<ProjectionTransform>>,
28 pub helmert: Option<Box<ProjectionTransform>>,
30 pub hgridshift: Option<Box<ProjectionTransform>>,
32 pub vgridshift: Option<Box<ProjectionTransform>>,
34}
35impl Default for ProjectionTransform {
36 fn default() -> Self {
37 let proj = Rc::new(RefCell::new(Proj::default()));
38 let method = BaseProjection::new(proj.clone());
39 Self {
40 proj,
41 method: method.into(),
42 axisswap: None,
43 cart: None,
44 cart_wgs84: None,
45 helmert: None,
46 hgridshift: None,
47 vgridshift: None,
48 }
49 }
50}
51impl ProjectionTransform {
52 pub fn wgs84() -> Self {
54 Self {
55 proj: Rc::new(RefCell::new(Proj::default())),
56 method: BaseProjection::to_step(),
57 axisswap: None,
58 cart: None,
59 cart_wgs84: None,
60 helmert: None,
61 hgridshift: None,
62 vgridshift: None,
63 }
64 }
65}
66
67pub trait TransformCoordinates: Clone + Default {
71 fn x(&self) -> f64;
73 fn y(&self) -> f64;
75 fn z(&self) -> f64;
77 fn t(&self) -> f64;
79 fn set_x(&mut self, x: f64);
81 fn set_y(&mut self, y: f64);
83 fn set_z(&mut self, z: f64);
85 fn set_t(&mut self, t: f64);
87
88 fn get(&self, idx: usize) -> f64 {
91 match idx {
92 0 => self.x(),
93 1 => self.y(),
94 2 => self.z(),
95 3 => self.t(),
96 _ => panic!("Invalid index"),
97 }
98 }
99 fn set(&mut self, idx: usize, val: f64) {
101 match idx {
102 0 => self.set_x(val),
103 1 => self.set_y(val),
104 2 => self.set_z(val),
105 3 => self.set_t(val),
106 _ => panic!("Invalid index"),
107 }
108 }
109
110 fn u(&self) -> f64 {
114 self.x()
115 }
116 fn set_u(&mut self, u: f64) {
118 self.set_x(u)
119 }
120 fn lam(&self) -> f64 {
122 self.x()
123 }
124 fn set_lam(&mut self, lam: f64) {
126 self.set_x(lam)
127 }
128 fn s(&self) -> f64 {
130 self.x()
131 }
132 fn set_s(&mut self, s: f64) {
134 self.set_x(s)
135 }
136 fn o(&self) -> f64 {
138 self.x()
139 }
140 fn set_o(&mut self, o: f64) {
142 self.set_x(o)
143 }
144 fn e(&self) -> f64 {
146 self.x()
147 }
148 fn set_e(&mut self, e: f64) {
150 self.set_x(e)
151 }
152
153 fn v(&self) -> f64 {
157 self.y()
158 }
159 fn set_v(&mut self, v: f64) {
161 self.set_y(v)
162 }
163 fn phi(&self) -> f64 {
165 self.y()
166 }
167 fn set_phi(&mut self, phi: f64) {
169 self.set_y(phi)
170 }
171 fn a1(&self) -> f64 {
173 self.y()
174 }
175 fn set_a1(&mut self, t: f64) {
177 self.set_y(t)
178 }
179 fn p(&self) -> f64 {
181 self.y()
182 }
183 fn set_p(&mut self, t: f64) {
185 self.set_y(t)
186 }
187 fn n(&self) -> f64 {
189 self.y()
190 }
191 fn set_n(&mut self, n: f64) {
193 self.set_y(n)
194 }
195
196 fn has_z(&self) -> bool;
200
201 fn w(&self) -> f64 {
203 self.z()
204 }
205 fn set_w(&mut self, w: f64) {
207 self.set_z(w)
208 }
209 fn a2(&self) -> f64 {
211 self.z()
212 }
213 fn set_a2(&mut self, a2: f64) {
215 self.set_z(a2)
216 }
217 fn k(&self) -> f64 {
219 self.z()
220 }
221 fn set_k(&mut self, k: f64) {
223 self.set_z(k)
224 }
225 fn up(&self) -> f64 {
227 self.z()
228 }
229 fn set_up(&mut self, up: f64) {
231 self.set_z(up)
232 }
233}
234
235impl<M: Default + Clone> TransformCoordinates for VectorPoint<M> {
236 fn x(&self) -> f64 {
237 self.x
238 }
239 fn y(&self) -> f64 {
240 self.y
241 }
242 fn z(&self) -> f64 {
243 self.z.unwrap_or(0.)
244 }
245 fn t(&self) -> f64 {
246 0.
247 }
248 fn set_x(&mut self, x: f64) {
249 self.x = x
250 }
251 fn set_y(&mut self, y: f64) {
252 self.y = y
253 }
254 fn set_z(&mut self, z: f64) {
255 self.z = Some(z);
256 }
257 fn set_t(&mut self, t: f64) {
258 self.t = Some(t);
259 }
260
261 fn has_z(&self) -> bool {
262 self.z.is_some()
263 }
264}
265impl TransformCoordinates for Coords {
266 fn x(&self) -> f64 {
267 self.0
268 }
269 fn y(&self) -> f64 {
270 self.1
271 }
272 fn z(&self) -> f64 {
273 self.2
274 }
275 fn t(&self) -> f64 {
276 self.3
277 }
278 fn set_x(&mut self, x: f64) {
279 self.0 = x
280 }
281 fn set_y(&mut self, y: f64) {
282 self.1 = y
283 }
284 fn set_z(&mut self, z: f64) {
285 self.2 = z
286 }
287 fn set_t(&mut self, t: f64) {
288 self.3 = t
289 }
290
291 fn has_z(&self) -> bool {
292 self.z() != 0.
293 }
294}