Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / srs / projections / proj / rpoly.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_RPOLY_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_RPOLY_HPP
42
43 #include <boost/geometry/srs/projections/impl/base_static.hpp>
44 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
45 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
46 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
47 #include <boost/geometry/srs/projections/impl/projects.hpp>
48
49 namespace boost { namespace geometry
50 {
51
52 namespace projections
53 {
54     #ifndef DOXYGEN_NO_DETAIL
55     namespace detail { namespace rpoly
56     {
57
58             static const double epsilon = 1e-9;
59
60             template <typename T>
61             struct par_rpoly
62             {
63                 T    phi1;
64                 T    fxa;
65                 T    fxb;
66                 bool mode; // TODO: Not really needed
67             };
68
69             template <typename T, typename Parameters>
70             struct base_rpoly_spheroid
71             {
72                 par_rpoly<T> m_proj_parm;
73
74                 // FORWARD(s_forward)  spheroid
75                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
76                 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
77                 {
78                     T fa;
79
80                     if (this->m_proj_parm.mode)
81                         fa = tan(lp_lon * this->m_proj_parm.fxb) * this->m_proj_parm.fxa;
82                     else
83                         fa = 0.5 * lp_lon;
84                     if (fabs(lp_lat) < epsilon) {
85                         xy_x = fa + fa;
86                         xy_y = - par.phi0;
87                     } else {
88                         xy_y = 1. / tan(lp_lat);
89                         xy_x = sin(fa = 2. * atan(fa * sin(lp_lat))) * xy_y;
90                         xy_y = lp_lat - par.phi0 + (1. - cos(fa)) * xy_y;
91                     }
92                 }
93
94                 static inline std::string get_name()
95                 {
96                     return "rpoly_spheroid";
97                 }
98
99             };
100
101             // Rectangular Polyconic
102             template <typename Params, typename Parameters, typename T>
103             inline void setup_rpoly(Params const& params, Parameters& par, par_rpoly<T>& proj_parm)
104             {
105                 proj_parm.phi1 = fabs(pj_get_param_r<T, srs::spar::lat_ts>(params, "lat_ts", srs::dpar::lat_ts));
106                 if ((proj_parm.mode = (proj_parm.phi1 > epsilon)))
107                 {
108                     proj_parm.fxb = 0.5 * sin(proj_parm.phi1);
109                     proj_parm.fxa = 0.5 / proj_parm.fxb;
110                 }
111                 par.es = 0.;
112             }
113
114     }} // namespace detail::rpoly
115     #endif // doxygen
116
117     /*!
118         \brief Rectangular Polyconic projection
119         \ingroup projections
120         \tparam Geographic latlong point type
121         \tparam Cartesian xy point type
122         \tparam Parameters parameter type
123         \par Projection characteristics
124          - Conic
125          - Spheroid
126          - no inverse
127         \par Projection parameters
128          - lat_ts: Latitude of true scale (degrees)
129         \par Example
130         \image html ex_rpoly.gif
131     */
132     template <typename T, typename Parameters>
133     struct rpoly_spheroid : public detail::rpoly::base_rpoly_spheroid<T, Parameters>
134     {
135         template <typename Params>
136         inline rpoly_spheroid(Params const& params, Parameters & par)
137         {
138             detail::rpoly::setup_rpoly(params, par, this->m_proj_parm);
139         }
140     };
141
142     #ifndef DOXYGEN_NO_DETAIL
143     namespace detail
144     {
145
146         // Static projection
147         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_rpoly, rpoly_spheroid)
148
149         // Factory entry(s)
150         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(rpoly_entry, rpoly_spheroid)
151
152         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(rpoly_init)
153         {
154             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(rpoly, rpoly_entry)
155         }
156
157     } // namespace detail
158     #endif // doxygen
159
160 } // namespace projections
161
162 }} // namespace boost::geometry
163
164 #endif // BOOST_GEOMETRY_PROJECTIONS_RPOLY_HPP
165