1 // Boost.Geometry - gis-projections (based on PROJ4)
3 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
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.
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)
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
18 // Last updated version of proj: 5.0.0
20 // Original copyright notice:
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:
29 // The above copyright notice and this permission notice shall be included
30 // in all copies or substantial portions of the Software.
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.
40 #ifndef BOOST_GEOMETRY_PROJECTIONS_OEA_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_OEA_HPP
43 #include <boost/math/special_functions/hypot.hpp>
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>
52 namespace boost { namespace geometry
57 #ifndef DOXYGEN_NO_DETAIL
58 namespace detail { namespace oea
65 T two_r_m, two_r_n, rm, rn, hm, hn;
69 template <typename T, typename Parameters>
70 struct base_oea_spheroid
72 par_oea<T> m_proj_parm;
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
78 T Az, M, N, cp, sp, cl, shz;
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);
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
95 T N, M, xp, yp, z, Az, cz, sz, cAz;
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));
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));
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);
110 static inline std::string get_name()
112 return "oea_spheroid";
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)
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) );
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;
138 }} // namespace detail::oea
142 \brief Oblated Equal Area projection
144 \tparam Geographic latlong point type
145 \tparam Cartesian xy point type
146 \tparam Parameters parameter type
147 \par Projection characteristics
150 \par Projection parameters
153 - theta: Theta (degrees)
155 \image html ex_oea.gif
157 template <typename T, typename Parameters>
158 struct oea_spheroid : public detail::oea::base_oea_spheroid<T, Parameters>
160 template <typename Params>
161 inline oea_spheroid(Params const& params, Parameters & par)
163 detail::oea::setup_oea(params, par, this->m_proj_parm);
167 #ifndef DOXYGEN_NO_DETAIL
172 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_oea, oea_spheroid)
175 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(oea_entry, oea_spheroid)
177 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(oea_init)
179 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(oea, oea_entry)
182 } // namespace detail
185 } // namespace projections
187 }} // namespace boost::geometry
189 #endif // BOOST_GEOMETRY_PROJECTIONS_OEA_HPP