]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/srs/projections/proj/lagrng.hpp
439b5747141d64442cfb0398aa907b536317fa3a
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / proj / lagrng.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_LAGRNG_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_LAGRNG_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 #include <boost/geometry/util/math.hpp>
50
51 namespace boost { namespace geometry
52 {
53
54 namespace projections
55 {
56 #ifndef DOXYGEN_NO_DETAIL
57 namespace detail { namespace lagrng
58 {
59
60 static const double tolerance = 1e-10;
61
62 template <typename T>
63 struct par_lagrng
64 {
65 T a1;
66 T rw;
67 T hrw;
68 };
69
70 template <typename T, typename Parameters>
71 struct base_lagrng_spheroid
72 {
73 par_lagrng<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 lp_lon, T lp_lat, T& xy_x, T& xy_y) const
78 {
79 static const T half_pi = detail::half_pi<T>();
80
81 T v, c;
82
83 if (fabs(fabs(lp_lat) - half_pi) < tolerance) {
84 xy_x = 0;
85 xy_y = lp_lat < 0 ? -2. : 2.;
86 } else {
87 lp_lat = sin(lp_lat);
88 v = this->m_proj_parm.a1 * math::pow((T(1) + lp_lat)/(T(1) - lp_lat), this->m_proj_parm.hrw);
89 if ((c = 0.5 * (v + 1./v) + cos(lp_lon *= this->m_proj_parm.rw)) < tolerance) {
90 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
91 }
92 xy_x = 2. * sin(lp_lon) / c;
93 xy_y = (v - 1./v) / c;
94 }
95 }
96
97 static inline std::string get_name()
98 {
99 return "lagrng_spheroid";
100 }
101
102 };
103
104 // Lagrange
105 template <typename Params, typename Parameters, typename T>
106 inline void setup_lagrng(Params const& params, Parameters& par, par_lagrng<T>& proj_parm)
107 {
108 T phi1;
109
110 proj_parm.rw = 0.0;
111 bool is_w_set = pj_param_f<srs::spar::w>(params, "W", srs::dpar::w, proj_parm.rw);
112
113 // Boost.Geometry specific, set default parameters manually
114 if (! is_w_set) {
115 bool const use_defaults = ! pj_get_param_b<srs::spar::no_defs>(params, "no_defs", srs::dpar::no_defs);
116 if (use_defaults) {
117 proj_parm.rw = 2;
118 }
119 }
120
121 if (proj_parm.rw <= 0)
122 BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
123
124 proj_parm.rw = 1. / proj_parm.rw;
125 proj_parm.hrw = 0.5 * proj_parm.rw;
126 phi1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
127 if (fabs(fabs(phi1 = sin(phi1)) - 1.) < tolerance)
128 BOOST_THROW_EXCEPTION( projection_exception(error_lat_larger_than_90) );
129
130 proj_parm.a1 = math::pow((T(1) - phi1)/(T(1) + phi1), proj_parm.hrw);
131
132 par.es = 0.;
133 }
134
135 }} // namespace detail::lagrng
136 #endif // doxygen
137
138 /*!
139 \brief Lagrange projection
140 \ingroup projections
141 \tparam Geographic latlong point type
142 \tparam Cartesian xy point type
143 \tparam Parameters parameter type
144 \par Projection characteristics
145 - Miscellaneous
146 - Spheroid
147 - no inverse
148 \par Projection parameters
149 - W (real)
150 - lat_1: Latitude of first standard parallel (degrees)
151 \par Example
152 \image html ex_lagrng.gif
153 */
154 template <typename T, typename Parameters>
155 struct lagrng_spheroid : public detail::lagrng::base_lagrng_spheroid<T, Parameters>
156 {
157 template <typename Params>
158 inline lagrng_spheroid(Params const& params, Parameters & par)
159 {
160 detail::lagrng::setup_lagrng(params, par, this->m_proj_parm);
161 }
162 };
163
164 #ifndef DOXYGEN_NO_DETAIL
165 namespace detail
166 {
167
168 // Static projection
169 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(srs::spar::proj_lagrng, lagrng_spheroid)
170
171 // Factory entry(s)
172 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_F(lagrng_entry, lagrng_spheroid)
173
174 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(lagrng_init)
175 {
176 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(lagrng, lagrng_entry);
177 }
178
179 } // namespace detail
180 #endif // doxygen
181
182 } // namespace projections
183
184 }} // namespace boost::geometry
185
186 #endif // BOOST_GEOMETRY_PROJECTIONS_LAGRNG_HPP
187