miniproj/
projection_constructor.rs

1//This file is licensed under EUPL v1.2
2
3use miniproj_ops::albers_equal_area::AlbersEqualAreaProjection;
4use miniproj_ops::identity_projection::IdentityProjection;
5use miniproj_ops::lambert_azimuthal_equal_area::LambertAzimuthalEqualAreaProjection;
6use miniproj_ops::lambert_conic_conformal::{
7    LambertConic1SPAProjection, LambertConic2SPProjection,
8};
9use miniproj_ops::popvis_pseudo_mercator::PopVisPseudoMercatorProjection;
10use miniproj_ops::stereographic::{ObliqueStereographicProjection, PolarStereographicAProjection};
11use miniproj_ops::transverse_mercator::TransverseMercatorProjection;
12use miniproj_ops::Projection;
13
14include!(concat!(env!("OUT_DIR"), "/projection_constructors.rs"));
15
16/// Returns the Coordinate Reference System corresponding to the EPSG code passed as the argument.
17/// If the code refers to a projection that is not implemented, the method returns `None`
18pub fn get_projection(code: u32) -> Option<&'static dyn Projection> {
19    PROJECTIONS.get(&code).cloned()
20}
21
22/// Returns the EPSG code of the ellipsoid that is associated with the projection
23/// corresponding to `projection_code`. Returns `None` if the projection is
24/// unknown.
25pub fn get_ellipsoid_code(projection_code: u32) -> Option<u32> {
26    ELLIPSOIDS.get(&projection_code).copied()
27}
28
29/// Returns the Name of the Coordinate Reference System. This is a temporary method that will be removed.
30#[deprecated]
31pub fn get_reference_system_name(code: u32) -> Option<&'static str> {
32    NAMES.get(&code).copied()
33}
34
35/// Returns one or multiple geographic areas that the reference system applies to.
36/// Values are in `[east, north, west, south]`` order. This is a temporary method that will be removed.
37#[deprecated]
38pub fn get_reference_system_areas(code: u32) -> Option<&'static [[f64; 4]]> {
39    AREAS.get(&code).filter(|a| !a.is_empty()).copied()
40}
41
42#[deprecated]
43pub fn all_names() -> impl Iterator<Item = (u32, &'static str)> {
44    NAMES.entries().map(|(c, n)| (*c, *n))
45}
46
47/// Create the Projection corresponding to the EPSG code passed as the argument, using the passed ellipsoid.
48/// The `&Ellipsoid` is not held by the returned projection, if you want the projection for a different
49/// ellipsoid you need to construct it again.
50//pub fn create_projection(code: u32, ellipsoid: &Ellipsoid) -> Option<Box<dyn Projection>> {
51//    todo!()
52//}
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn dyn_projection_is_send_sync() {
60        fn is_send_sync<T: Send + Sync>(_: T) {}
61
62        is_send_sync(get_projection(4326));
63    }
64}