Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / srs / projections / proj / gstmerc.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_GSTMERC_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_GSTMERC_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/projects.hpp>
46 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
47 #include <boost/geometry/srs/projections/impl/pj_phi2.hpp>
48 #include <boost/geometry/srs/projections/impl/pj_tsfn.hpp>
49
50 namespace boost { namespace geometry
51 {
52
53 namespace projections
54 {
55     #ifndef DOXYGEN_NO_DETAIL
56     namespace detail { namespace gstmerc
57     {
58             template <typename T>
59             struct par_gstmerc
60             {
61                 T lamc;
62                 T phic;
63                 T c;
64                 T n1;
65                 T n2;
66                 T XS;
67                 T YS;
68             };
69
70             template <typename T, typename Parameters>
71             struct base_gstmerc_spheroid
72             {
73                 par_gstmerc<T> m_proj_parm;
74
75                 // FORWARD(s_forward)  spheroid
76                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
77                 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
78                 {
79                     T L, Ls, sinLs1, Ls1;
80
81                     L= this->m_proj_parm.n1*lp_lon;
82                     Ls= this->m_proj_parm.c+this->m_proj_parm.n1*log(pj_tsfn(-1.0*lp_lat,-1.0*sin(lp_lat), par.e));
83                     sinLs1= sin(L)/cosh(Ls);
84                     Ls1= log(pj_tsfn(-1.0*asin(sinLs1),0.0,0.0));
85                     xy_x= (this->m_proj_parm.XS + this->m_proj_parm.n2*Ls1) * par.ra;
86                     xy_y= (this->m_proj_parm.YS + this->m_proj_parm.n2*atan(sinh(Ls)/cos(L))) * par.ra;
87                 }
88
89                 // INVERSE(s_inverse)  spheroid
90                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
91                 inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
92                 {
93                     T L, LC, sinC;
94
95                     L= atan(sinh((xy_x * par.a - this->m_proj_parm.XS)/this->m_proj_parm.n2)/cos((xy_y * par.a - this->m_proj_parm.YS)/this->m_proj_parm.n2));
96                     sinC= sin((xy_y * par.a - this->m_proj_parm.YS)/this->m_proj_parm.n2)/cosh((xy_x * par.a - this->m_proj_parm.XS)/this->m_proj_parm.n2);
97                     LC= log(pj_tsfn(-1.0*asin(sinC),0.0,0.0));
98                     lp_lon= L/this->m_proj_parm.n1;
99                     lp_lat= -1.0*pj_phi2(exp((LC-this->m_proj_parm.c)/this->m_proj_parm.n1), par.e);
100                 }
101
102                 static inline std::string get_name()
103                 {
104                     return "gstmerc_spheroid";
105                 }
106
107             };
108
109             // Gauss-Schreiber Transverse Mercator (aka Gauss-Laborde Reunion)
110             template <typename Parameters, typename T>
111             inline void setup_gstmerc(Parameters const& par, par_gstmerc<T>& proj_parm)
112             {
113                 proj_parm.lamc= par.lam0;
114                 proj_parm.n1= sqrt(T(1)+par.es*math::pow(cos(par.phi0),4)/(T(1)-par.es));
115                 proj_parm.phic= asin(sin(par.phi0)/proj_parm.n1);
116                 proj_parm.c= log(pj_tsfn(-1.0*proj_parm.phic,0.0,0.0))
117                            - proj_parm.n1*log(pj_tsfn(-1.0*par.phi0,-1.0*sin(par.phi0),par.e));
118                 proj_parm.n2= par.k0*par.a*sqrt(1.0-par.es)/(1.0-par.es*sin(par.phi0)*sin(par.phi0));
119                 proj_parm.XS= 0;/* -par.x0 */
120                 proj_parm.YS= -1.0*proj_parm.n2*proj_parm.phic;/* -par.y0 */
121             }
122
123     }} // namespace detail::gstmerc
124     #endif // doxygen
125
126     /*!
127         \brief Gauss-Schreiber Transverse Mercator (aka Gauss-Laborde Reunion) projection
128         \ingroup projections
129         \tparam Geographic latlong point type
130         \tparam Cartesian xy point type
131         \tparam Parameters parameter type
132         \par Projection characteristics
133          - Cylindrical
134          - Spheroid
135          - Ellipsoid
136         \par Projection parameters
137          - lat_0: Latitude of origin
138          - lon_0: Central meridian
139          - k_0: Scale factor
140         \par Example
141         \image html ex_gstmerc.gif
142     */
143     template <typename T, typename Parameters>
144     struct gstmerc_spheroid : public detail::gstmerc::base_gstmerc_spheroid<T, Parameters>
145     {
146         template <typename Params>
147         inline gstmerc_spheroid(Params const& , Parameters const& par)
148         {
149             detail::gstmerc::setup_gstmerc(par, this->m_proj_parm);
150         }
151     };
152
153     #ifndef DOXYGEN_NO_DETAIL
154     namespace detail
155     {
156
157         // Static projection
158         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_gstmerc, gstmerc_spheroid)
159
160         // Factory entry(s)
161         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(gstmerc_entry, gstmerc_spheroid)
162         
163         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(gstmerc_init)
164         {
165             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(gstmerc, gstmerc_entry);
166         }
167
168     } // namespace detail
169     #endif // doxygen
170
171 } // namespace projections
172
173 }} // namespace boost::geometry
174
175 #endif // BOOST_GEOMETRY_PROJECTIONS_GSTMERC_HPP
176