Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / srs / projections / proj / oea.hpp
1 // Boost.Geometry - gis-projections (based on PROJ4)
2
3 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2017, 2018, 2019.
6 // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
8
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12
13 // This file is converted from PROJ4, http://trac.osgeo.org/proj
14 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
15 // PROJ4 is maintained by Frank Warmerdam
16 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
17
18 // Last updated version of proj: 5.0.0
19
20 // Original copyright notice:
21
22 // Permission is hereby granted, free of charge, to any person obtaining a
23 // copy of this software and associated documentation files (the "Software"),
24 // to deal in the Software without restriction, including without limitation
25 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
26 // and/or sell copies of the Software, and to permit persons to whom the
27 // Software is furnished to do so, subject to the following conditions:
28
29 // The above copyright notice and this permission notice shall be included
30 // in all copies or substantial portions of the Software.
31
32 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
33 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
35 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
38 // DEALINGS IN THE SOFTWARE.
39
40 #ifndef BOOST_GEOMETRY_PROJECTIONS_OEA_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_OEA_HPP
42
43 #include <boost/math/special_functions/hypot.hpp>
44
45 #include <boost/geometry/srs/projections/impl/aasincos.hpp>
46 #include <boost/geometry/srs/projections/impl/base_static.hpp>
47 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
48 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
49 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
50 #include <boost/geometry/srs/projections/impl/projects.hpp>
51
52 namespace boost { namespace geometry
53 {
54
55 namespace projections
56 {
57     #ifndef DOXYGEN_NO_DETAIL
58     namespace detail { namespace oea
59     {
60             template <typename T>
61             struct par_oea
62             {
63                 T    theta;
64                 T    m, n;
65                 T    two_r_m, two_r_n, rm, rn, hm, hn;
66                 T    cp0, sp0;
67             };
68
69             template <typename T, typename Parameters>
70             struct base_oea_spheroid
71             {
72                 par_oea<T> m_proj_parm;
73
74                 // FORWARD(s_forward)  sphere
75                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
76                 inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
77                 {
78                     T Az, M, N, cp, sp, cl, shz;
79
80                     cp = cos(lp_lat);
81                     sp = sin(lp_lat);
82                     cl = cos(lp_lon);
83                     Az = aatan2(cp * sin(lp_lon), this->m_proj_parm.cp0 * sp - this->m_proj_parm.sp0 * cp * cl) + this->m_proj_parm.theta;
84                     shz = sin(0.5 * aacos(this->m_proj_parm.sp0 * sp + this->m_proj_parm.cp0 * cp * cl));
85                     M = aasin(shz * sin(Az));
86                     N = aasin(shz * cos(Az) * cos(M) / cos(M * this->m_proj_parm.two_r_m));
87                     xy_y = this->m_proj_parm.n * sin(N * this->m_proj_parm.two_r_n);
88                     xy_x = this->m_proj_parm.m * sin(M * this->m_proj_parm.two_r_m) * cos(N) / cos(N * this->m_proj_parm.two_r_n);
89                 }
90
91                 // INVERSE(s_inverse)  sphere
92                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
93                 inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
94                 {
95                     T N, M, xp, yp, z, Az, cz, sz, cAz;
96
97                     N = this->m_proj_parm.hn * aasin(xy_y * this->m_proj_parm.rn);
98                     M = this->m_proj_parm.hm * aasin(xy_x * this->m_proj_parm.rm * cos(N * this->m_proj_parm.two_r_n) / cos(N));
99                     xp = 2. * sin(M);
100                     yp = 2. * sin(N) * cos(M * this->m_proj_parm.two_r_m) / cos(M);
101                     cAz = cos(Az = aatan2(xp, yp) - this->m_proj_parm.theta);
102                     z = 2. * aasin(0.5 * boost::math::hypot(xp, yp));
103                     sz = sin(z);
104                     cz = cos(z);
105                     lp_lat = aasin(this->m_proj_parm.sp0 * cz + this->m_proj_parm.cp0 * sz * cAz);
106                     lp_lon = aatan2(sz * sin(Az),
107                         this->m_proj_parm.cp0 * cz - this->m_proj_parm.sp0 * sz * cAz);
108                 }
109
110                 static inline std::string get_name()
111                 {
112                     return "oea_spheroid";
113                 }
114
115             };
116
117             // Oblated Equal Area
118             template <typename Params, typename Parameters, typename T>
119             inline void setup_oea(Params const& params, Parameters& par, par_oea<T>& proj_parm)
120             {
121                 if (((proj_parm.n = pj_get_param_f<T, srs::spar::n>(params, "n", srs::dpar::n)) <= 0.) ||
122                     ((proj_parm.m = pj_get_param_f<T, srs::spar::m>(params, "m", srs::dpar::m)) <= 0.)) {
123                     BOOST_THROW_EXCEPTION( projection_exception(error_invalid_m_or_n) );
124                 } else {
125                     proj_parm.theta = pj_get_param_r<T, srs::spar::theta>(params, "theta", srs::dpar::theta);
126                     proj_parm.sp0 = sin(par.phi0);
127                     proj_parm.cp0 = cos(par.phi0);
128                     proj_parm.rn = 1./ proj_parm.n;
129                     proj_parm.rm = 1./ proj_parm.m;
130                     proj_parm.two_r_n = 2. * proj_parm.rn;
131                     proj_parm.two_r_m = 2. * proj_parm.rm;
132                     proj_parm.hm = 0.5 * proj_parm.m;
133                     proj_parm.hn = 0.5 * proj_parm.n;
134                     par.es = 0.;
135                 }
136             }
137
138     }} // namespace detail::oea
139     #endif // doxygen
140
141     /*!
142         \brief Oblated Equal Area projection
143         \ingroup projections
144         \tparam Geographic latlong point type
145         \tparam Cartesian xy point type
146         \tparam Parameters parameter type
147         \par Projection characteristics
148          - Miscellaneous
149          - Spheroid
150         \par Projection parameters
151          - n (real)
152          - m (real)
153          - theta: Theta (degrees)
154         \par Example
155         \image html ex_oea.gif
156     */
157     template <typename T, typename Parameters>
158     struct oea_spheroid : public detail::oea::base_oea_spheroid<T, Parameters>
159     {
160         template <typename Params>
161         inline oea_spheroid(Params const& params, Parameters & par)
162         {
163             detail::oea::setup_oea(params, par, this->m_proj_parm);
164         }
165     };
166
167     #ifndef DOXYGEN_NO_DETAIL
168     namespace detail
169     {
170
171         // Static projection
172         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_oea, oea_spheroid)
173
174         // Factory entry(s)
175         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(oea_entry, oea_spheroid)
176
177         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(oea_init)
178         {
179             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(oea, oea_entry)
180         }
181
182     } // namespace detail
183     #endif // doxygen
184
185 } // namespace projections
186
187 }} // namespace boost::geometry
188
189 #endif // BOOST_GEOMETRY_PROJECTIONS_OEA_HPP
190