Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / srs / projections / proj / ocea.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_OCEA_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_OCEA_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/factory_entry.hpp>
48 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
49 #include <boost/geometry/srs/projections/impl/projects.hpp>
50
51 namespace boost { namespace geometry
52 {
53
54 namespace projections
55 {
56     #ifndef DOXYGEN_NO_DETAIL
57     namespace detail { namespace ocea
58     {
59             template <typename T>
60             struct par_ocea
61             {
62                 T    rok;
63                 T    rtk;
64                 T    sinphi;
65                 T    cosphi;
66                 T    singam;
67                 T    cosgam;
68             };
69
70             template <typename T, typename Parameters>
71             struct base_ocea_spheroid
72             {
73                 par_ocea<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& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
78                 {
79                     static const T pi = detail::pi<T>();
80
81                     T t;
82
83                     xy_y = sin(lp_lon);
84                     t = cos(lp_lon);
85                     xy_x = atan((tan(lp_lat) * this->m_proj_parm.cosphi + this->m_proj_parm.sinphi * xy_y) / t);
86                     if (t < 0.)
87                         xy_x += pi;
88                     xy_x *= this->m_proj_parm.rtk;
89                     xy_y = this->m_proj_parm.rok * (this->m_proj_parm.sinphi * sin(lp_lat) - this->m_proj_parm.cosphi * cos(lp_lat) * xy_y);
90                 }
91
92                 // INVERSE(s_inverse)  spheroid
93                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
94                 inline void inv(Parameters const& , T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
95                 {
96                     T t, s;
97
98                     xy_y /= this->m_proj_parm.rok;
99                     xy_x /= this->m_proj_parm.rtk;
100                     t = sqrt(1. - xy_y * xy_y);
101                     lp_lat = asin(xy_y * this->m_proj_parm.sinphi + t * this->m_proj_parm.cosphi * (s = sin(xy_x)));
102                     lp_lon = atan2(t * this->m_proj_parm.sinphi * s - xy_y * this->m_proj_parm.cosphi,
103                         t * cos(xy_x));
104                 }
105
106                 static inline std::string get_name()
107                 {
108                     return "ocea_spheroid";
109                 }
110
111             };
112
113             // Oblique Cylindrical Equal Area
114             template <typename Params, typename Parameters, typename T>
115             inline void setup_ocea(Params const& params, Parameters& par, par_ocea<T>& proj_parm)
116             {
117                 static const T half_pi = detail::half_pi<T>();
118
119                 T phi_0=0.0, phi_1, phi_2, lam_1, lam_2, lonz, alpha;
120
121                 proj_parm.rok = 1. / par.k0;
122                 proj_parm.rtk = par.k0;
123                 /*If the keyword "alpha" is found in the sentence then use 1point+1azimuth*/
124                 if ( pj_param_r<srs::spar::alpha>(params, "alpha", srs::dpar::alpha, alpha)) {
125                     /*Define Pole of oblique transformation from 1 point & 1 azimuth*/
126                     //alpha = pj_get_param_r(par.params, "alpha"); // set above
127                     lonz = pj_get_param_r<T, srs::spar::lonc>(params, "lonc", srs::dpar::lonc);
128                     /*Equation 9-8 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
129                     proj_parm.singam = atan(-cos(alpha)/(-sin(phi_0) * sin(alpha))) + lonz;
130                     /*Equation 9-7 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
131                     proj_parm.sinphi = asin(cos(phi_0) * sin(alpha));
132                 /*If the keyword "alpha" is NOT found in the sentence then use 2points*/
133                 } else {
134                     /*Define Pole of oblique transformation from 2 points*/
135                     phi_1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
136                     phi_2 = pj_get_param_r<T, srs::spar::lat_2>(params, "lat_2", srs::dpar::lat_2);
137                     lam_1 = pj_get_param_r<T, srs::spar::lon_1>(params, "lon_1", srs::dpar::lon_1);
138                     lam_2 = pj_get_param_r<T, srs::spar::lon_2>(params, "lon_2", srs::dpar::lon_2);
139                     /*Equation 9-1 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
140                     proj_parm.singam = atan2(cos(phi_1) * sin(phi_2) * cos(lam_1) -
141                         sin(phi_1) * cos(phi_2) * cos(lam_2),
142                         sin(phi_1) * cos(phi_2) * sin(lam_2) -
143                         cos(phi_1) * sin(phi_2) * sin(lam_1) );
144
145                     /* take care of P->lam0 wrap-around when +lam_1=-90*/
146                     if (lam_1 == -half_pi)
147                         proj_parm.singam = -proj_parm.singam;
148
149                     /*Equation 9-2 page 80 (http://pubs.usgs.gov/pp/1395/report.pdf)*/
150                     proj_parm.sinphi = atan(-cos(proj_parm.singam - lam_1) / tan(phi_1));
151                 }
152                 par.lam0 = proj_parm.singam + half_pi;
153                 proj_parm.cosphi = cos(proj_parm.sinphi);
154                 proj_parm.sinphi = sin(proj_parm.sinphi);
155                 proj_parm.cosgam = cos(proj_parm.singam);
156                 proj_parm.singam = sin(proj_parm.singam);
157                 par.es = 0.;
158             }
159
160     }} // namespace detail::ocea
161     #endif // doxygen
162
163     /*!
164         \brief Oblique Cylindrical Equal Area projection
165         \ingroup projections
166         \tparam Geographic latlong point type
167         \tparam Cartesian xy point type
168         \tparam Parameters parameter type
169         \par Projection characteristics
170          - Cylindrical
171          - Spheroid
172         \par Projection parameters
173          - lonc: Longitude (only used if alpha (or gamma) is specified) (degrees)
174          - alpha: Alpha (degrees)
175          - lat_1: Latitude of first standard parallel (degrees)
176          - lat_2: Latitude of second standard parallel (degrees)
177          - lon_1 (degrees)
178          - lon_2 (degrees)
179         \par Example
180         \image html ex_ocea.gif
181     */
182     template <typename T, typename Parameters>
183     struct ocea_spheroid : public detail::ocea::base_ocea_spheroid<T, Parameters>
184     {
185         template <typename Params>
186         inline ocea_spheroid(Params const& params, Parameters & par)
187         {
188             detail::ocea::setup_ocea(params, par, this->m_proj_parm);
189         }
190     };
191
192     #ifndef DOXYGEN_NO_DETAIL
193     namespace detail
194     {
195
196         // Static projection
197         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_ocea, ocea_spheroid)
198
199         // Factory entry(s)
200         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(ocea_entry, ocea_spheroid)
201
202         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(ocea_init)
203         {
204             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(ocea, ocea_entry)
205         }
206
207     } // namespace detail
208     #endif // doxygen
209
210 } // namespace projections
211
212 }} // namespace boost::geometry
213
214 #endif // BOOST_GEOMETRY_PROJECTIONS_OCEA_HPP
215