#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PointAxis {
pub index: usize,
pub cartesian: &'static str,
pub geographic: &'static str,
}
impl PointAxis {
pub fn names(self, key: &str) -> bool {
key == self.cartesian || key == self.geographic
}
pub fn key(self, geographic: bool) -> &'static str {
if geographic {
self.geographic
} else {
self.cartesian
}
}
}
pub const POINT_AXES: [PointAxis; 3] = [
PointAxis {
index: 0,
cartesian: "x",
geographic: "longitude",
},
PointAxis {
index: 1,
cartesian: "y",
geographic: "latitude",
},
PointAxis {
index: 2,
cartesian: "z",
geographic: "height",
},
];
pub fn point_axis(key: &str) -> Option<PointAxis> {
POINT_AXES.into_iter().find(|axis| axis.names(key))
}
pub fn point_axis_keys(geographic: bool) -> [&'static str; 3] {
[
POINT_AXES[0].key(geographic),
POINT_AXES[1].key(geographic),
POINT_AXES[2].key(geographic),
]
}
pub fn is_geographic(srid: i32) -> bool {
matches!(srid, 4326 | 4979)
}