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_MOLL_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_MOLL_HPP
43 #include <boost/geometry/util/math.hpp>
45 #include <boost/geometry/srs/projections/impl/base_static.hpp>
46 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
47 #include <boost/geometry/srs/projections/impl/projects.hpp>
48 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
49 #include <boost/geometry/srs/projections/impl/aasincos.hpp>
51 namespace boost { namespace geometry
56 #ifndef DOXYGEN_NO_DETAIL
57 namespace detail { namespace moll
60 static const int max_iter = 10;
61 static const double loop_tol = 1e-7;
69 template <typename T, typename Parameters>
70 struct base_moll_spheroid
72 par_moll<T> m_proj_parm;
74 // FORWARD(s_forward) spheroid
75 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
76 inline void fwd(Parameters const& , T const& lp_lon, T lp_lat, T& xy_x, T& xy_y) const
78 static const T half_pi = detail::half_pi<T>();
83 k = this->m_proj_parm.C_p * sin(lp_lat);
84 for (i = max_iter; i ; --i) {
85 lp_lat -= V = (lp_lat + sin(lp_lat) - k) /
87 if (fabs(V) < loop_tol)
91 lp_lat = (lp_lat < 0.) ? -half_pi : half_pi;
94 xy_x = this->m_proj_parm.C_x * lp_lon * cos(lp_lat);
95 xy_y = this->m_proj_parm.C_y * sin(lp_lat);
98 // INVERSE(s_inverse) spheroid
99 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
100 inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
102 static const T pi = detail::pi<T>();
104 lp_lat = aasin(xy_y / this->m_proj_parm.C_y);
105 lp_lon = xy_x / (this->m_proj_parm.C_x * cos(lp_lat));
106 if (fabs(lp_lon) < pi) {
108 lp_lat = aasin((lp_lat + sin(lp_lat)) / this->m_proj_parm.C_p);
110 lp_lon = lp_lat = HUGE_VAL;
114 static inline std::string get_name()
116 return "moll_spheroid";
121 template <typename Parameters, typename T>
122 inline void setup(Parameters& par, par_moll<T>& proj_parm, T const& p)
128 r = sqrt(geometry::math::two_pi<T>() * sp / (p2 + sin(p2)));
130 proj_parm.C_x = 2. * r / geometry::math::pi<T>();
131 proj_parm.C_y = r / sp;
132 proj_parm.C_p = p2 + sin(p2);
137 template <typename Parameters, typename T>
138 inline void setup_moll(Parameters& par, par_moll<T>& proj_parm)
140 setup(par, proj_parm, geometry::math::half_pi<T>());
144 template <typename Parameters, typename T>
145 inline void setup_wag4(Parameters& par, par_moll<T>& proj_parm)
147 setup(par, proj_parm, geometry::math::pi<T>()/3.);
151 template <typename Parameters, typename T>
152 inline void setup_wag5(Parameters& par, par_moll<T>& proj_parm)
155 proj_parm.C_x = 0.90977;
156 proj_parm.C_y = 1.65014;
157 proj_parm.C_p = 3.00896;
160 }} // namespace detail::moll
164 \brief Mollweide projection
166 \tparam Geographic latlong point type
167 \tparam Cartesian xy point type
168 \tparam Parameters parameter type
169 \par Projection characteristics
173 \image html ex_moll.gif
175 template <typename T, typename Parameters>
176 struct moll_spheroid : public detail::moll::base_moll_spheroid<T, Parameters>
178 template <typename Params>
179 inline moll_spheroid(Params const& , Parameters & par)
181 detail::moll::setup_moll(par, this->m_proj_parm);
186 \brief Wagner IV projection
188 \tparam Geographic latlong point type
189 \tparam Cartesian xy point type
190 \tparam Parameters parameter type
191 \par Projection characteristics
195 \image html ex_wag4.gif
197 template <typename T, typename Parameters>
198 struct wag4_spheroid : public detail::moll::base_moll_spheroid<T, Parameters>
200 template <typename Params>
201 inline wag4_spheroid(Params const& , Parameters & par)
203 detail::moll::setup_wag4(par, this->m_proj_parm);
208 \brief Wagner V projection
210 \tparam Geographic latlong point type
211 \tparam Cartesian xy point type
212 \tparam Parameters parameter type
213 \par Projection characteristics
217 \image html ex_wag5.gif
219 template <typename T, typename Parameters>
220 struct wag5_spheroid : public detail::moll::base_moll_spheroid<T, Parameters>
222 template <typename Params>
223 inline wag5_spheroid(Params const& , Parameters & par)
225 detail::moll::setup_wag5(par, this->m_proj_parm);
229 #ifndef DOXYGEN_NO_DETAIL
234 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_moll, moll_spheroid)
235 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_wag4, wag4_spheroid)
236 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_wag5, wag5_spheroid)
239 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(moll_entry, moll_spheroid)
240 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(wag4_entry, wag4_spheroid)
241 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(wag5_entry, wag5_spheroid)
243 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(moll_init)
245 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(moll, moll_entry);
246 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(wag4, wag4_entry);
247 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(wag5, wag5_entry);
250 } // namespace detail
253 } // namespace projections
255 }} // namespace boost::geometry
257 #endif // BOOST_GEOMETRY_PROJECTIONS_MOLL_HPP