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.
6 // Modifications copyright (c) 2017-2018, 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_MBTFPP_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_MBTFPP_HPP
42 
43 #include <boost/geometry/util/math.hpp>
44 
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 
50 namespace boost { namespace geometry
51 {
52 
53 namespace projections
54 {
55     #ifndef DOXYGEN_NO_DETAIL
56     namespace detail { namespace mbtfpp
57     {
58 
59             static const double CS_ = .95257934441568037152;
60             static const double FXC = .92582009977255146156;
61             static const double FYC = 3.40168025708304504493;
62             //static const double C23 = .66666666666666666666;
63             //static const double C13 = .33333333333333333333;
64             static const double one_plus_eps = 1.0000001;
65 
66             // template class, using CRTP to implement forward/inverse
67             template <typename T, typename Parameters>
68             struct base_mbtfpp_spheroid
69                 : public base_t_fi<base_mbtfpp_spheroid<T, Parameters>, T, Parameters>
70             {
base_mbtfpp_spheroidboost::geometry::projections::detail::mbtfpp::base_mbtfpp_spheroid71                 inline base_mbtfpp_spheroid(const Parameters& par)
72                     : base_t_fi<base_mbtfpp_spheroid<T, Parameters>, T, Parameters>(*this, par)
73                 {}
74 
75                 // FORWARD(s_forward)  spheroid
76                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
fwdboost::geometry::projections::detail::mbtfpp::base_mbtfpp_spheroid77                 inline void fwd(T const& lp_lon, T lp_lat, T& xy_x, T& xy_y) const
78                 {
79                     static const T C23 = detail::two_thirds<T>();
80                     static const T C13 = detail::third<T>();
81 
82                     lp_lat = asin(CS_ * sin(lp_lat));
83                     xy_x = FXC * lp_lon * (2. * cos(C23 * lp_lat) - 1.);
84                     xy_y = FYC * sin(C13 * lp_lat);
85                 }
86 
87                 // INVERSE(s_inverse)  spheroid
88                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
invboost::geometry::projections::detail::mbtfpp::base_mbtfpp_spheroid89                 inline void inv(T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
90                 {
91                     static const T half_pi = detail::half_pi<T>();
92                     static const T C23 = detail::two_thirds<T>();
93 
94                     lp_lat = xy_y / FYC;
95                     if (fabs(lp_lat) >= 1.) {
96                         if (fabs(lp_lat) > one_plus_eps) {
97                             BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
98                         } else {
99                             lp_lat = (lp_lat < 0.) ? -half_pi : half_pi;
100                         }
101                     } else
102                         lp_lat = asin(lp_lat);
103 
104                     lp_lon = xy_x / ( FXC * (2. * cos(C23 * (lp_lat *= 3.)) - 1.) );
105                     if (fabs(lp_lat = sin(lp_lat) / CS_) >= 1.) {
106                         if (fabs(lp_lat) > one_plus_eps) {
107                             BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
108                         } else {
109                             lp_lat = (lp_lat < 0.) ? -half_pi : half_pi;
110                         }
111                     } else
112                         lp_lat = asin(lp_lat);
113                 }
114 
get_nameboost::geometry::projections::detail::mbtfpp::base_mbtfpp_spheroid115                 static inline std::string get_name()
116                 {
117                     return "mbtfpp_spheroid";
118                 }
119 
120             };
121 
122             // McBride-Thomas Flat-Polar Parabolic
123             template <typename Parameters>
setup_mbtfpp(Parameters & par)124             inline void setup_mbtfpp(Parameters& par)
125             {
126                 par.es = 0.;
127             }
128 
129     }} // namespace detail::mbtfpp
130     #endif // doxygen
131 
132     /*!
133         \brief McBride-Thomas Flat-Polar Parabolic projection
134         \ingroup projections
135         \tparam Geographic latlong point type
136         \tparam Cartesian xy point type
137         \tparam Parameters parameter type
138         \par Projection characteristics
139          - Cylindrical
140          - Spheroid
141         \par Example
142         \image html ex_mbtfpp.gif
143     */
144     template <typename T, typename Parameters>
145     struct mbtfpp_spheroid : public detail::mbtfpp::base_mbtfpp_spheroid<T, Parameters>
146     {
147         template <typename Params>
mbtfpp_spheroidboost::geometry::projections::mbtfpp_spheroid148         inline mbtfpp_spheroid(Params const& , Parameters const& par)
149             : detail::mbtfpp::base_mbtfpp_spheroid<T, Parameters>(par)
150         {
151             detail::mbtfpp::setup_mbtfpp(this->m_par);
152         }
153     };
154 
155     #ifndef DOXYGEN_NO_DETAIL
156     namespace detail
157     {
158 
159         // Static projection
BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::spar::proj_mbtfpp,mbtfpp_spheroid,mbtfpp_spheroid)160         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::spar::proj_mbtfpp, mbtfpp_spheroid, mbtfpp_spheroid)
161 
162         // Factory entry(s)
163         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(mbtfpp_entry, mbtfpp_spheroid)
164 
165         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(mbtfpp_init)
166         {
167             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(mbtfpp, mbtfpp_entry)
168         }
169 
170     } // namespace detail
171     #endif // doxygen
172 
173 } // namespace projections
174 
175 }} // namespace boost::geometry
176 
177 #endif // BOOST_GEOMETRY_PROJECTIONS_MBTFPP_HPP
178 
179