1 // Boost.Geometry - gis-projections (based on PROJ4)
3 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
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.
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)
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
18 // Last updated version of proj: 5.0.0
20 // Original copyright notice:
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:
29 // The above copyright notice and this permission notice shall be included
30 // in all copies or substantial portions of the Software.
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.
40 #ifndef BOOST_GEOMETRY_PROJECTIONS_BIPC_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_BIPC_HPP
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>
49 #include <boost/geometry/util/math.hpp>
51 #include <boost/math/special_functions/hypot.hpp>
53 namespace boost { namespace geometry
58 #ifndef DOXYGEN_NO_DETAIL
59 namespace detail { namespace bipc
62 static const double epsilon = 1e-10;
63 static const double epsilon10 = 1e-10;
64 static const double one_plus_eps = 1.000000001;
65 static const int n_iter = 10;
66 static const double lamB = -.34894976726250681539;
67 static const double n = .63055844881274687180;
68 static const double F = 1.89724742567461030582;
69 static const double Azab = .81650043674686363166;
70 static const double Azba = 1.82261843856185925133;
71 static const double const_T = 1.27246578267089012270;
72 static const double rhoc = 1.20709121521568721927;
73 static const double cAzc = .69691523038678375519;
74 static const double sAzc = .71715351331143607555;
75 static const double C45 = .70710678118654752469;
76 static const double S45 = .70710678118654752410;
77 static const double C20 = .93969262078590838411;
78 static const double S20 = -.34202014332566873287;
79 static const double R110 = 1.91986217719376253360;
80 static const double R104 = 1.81514242207410275904;
87 template <typename T, typename Parameters>
88 struct base_bipc_spheroid
92 // FORWARD(s_forward) spheroid
93 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
94 inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
96 static const T half_pi = detail::half_pi<T>();
97 static const T pi = detail::pi<T>();
99 T cphi, sphi, tphi, t, al, Az, z, Av, cdlam, sdlam, r;
104 cdlam = cos(sdlam = lamB - lp_lon);
106 if (fabs(fabs(lp_lat) - half_pi) < epsilon10) {
107 Az = lp_lat < 0. ? pi : 0.;
111 Az = atan2(sdlam , C45 * (tphi - cdlam));
113 if( (tag = (Az > Azba)) ) {
114 cdlam = cos(sdlam = lp_lon + R110);
116 z = S20 * sphi + C20 * cphi * cdlam;
118 if (fabs(z) > one_plus_eps)
119 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
121 z = z < 0. ? -1. : 1.;
124 if (tphi != HUGE_VAL)
125 Az = atan2(sdlam, (C20 * tphi - S20 * cdlam));
129 z = S45 * (sphi + cphi * cdlam);
131 if (fabs(z) > one_plus_eps)
132 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
134 z = z < 0. ? -1. : 1.;
141 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
143 r = F * (t = math::pow(tan(T(0.5) * z), n));
144 if ((al = .5 * (R104 - z)) < 0.) {
145 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
147 al = (t + math::pow(al, n)) / const_T;
149 if (fabs(al) > one_plus_eps)
150 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
152 al = al < 0. ? -1. : 1.;
155 if (fabs(t = n * (Av - Az)) < al)
156 r /= cos(al + (tag ? t : -t));
158 xy_y += (tag ? -r : r) * cos(t);
159 if (this->m_proj_parm.noskew) {
161 xy_x = -xy_x * cAzc - xy_y * sAzc;
162 xy_y = -xy_y * cAzc + t * sAzc;
166 // INVERSE(s_inverse) spheroid
167 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
168 inline void inv(Parameters const& , T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
170 T t, r, rp, rl, al, z, fAz, Az, s, c, Av;
173 if (this->m_proj_parm.noskew) {
175 xy_x = -xy_x * cAzc + xy_y * sAzc;
176 xy_y = -xy_y * cAzc - t * sAzc;
178 if( (neg = (xy_x < 0.)) ) {
189 rl = rp = r = boost::math::hypot(xy_x, xy_y);
190 fAz = fabs(Az = atan2(xy_x, xy_y));
191 for (i = n_iter; i ; --i) {
192 z = 2. * atan(math::pow(r / F,T(1) / n));
193 al = acos((math::pow(tan(T(0.5) * z), n) +
194 math::pow(tan(T(0.5) * (R104 - z)), n)) / const_T);
196 r = rp * cos(al + (neg ? Az : -Az));
197 if (fabs(rl - r) < epsilon)
202 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
204 lp_lat = asin(s * cos(z) + c * sin(z) * cos(Az));
205 lp_lon = atan2(sin(Az), c / tan(z) - s * cos(Az));
209 lp_lon = lamB - lp_lon;
212 static inline std::string get_name()
214 return "bipc_spheroid";
219 // Bipolar conic of western hemisphere
220 template <typename Params, typename Parameters>
221 inline void setup_bipc(Params const& params, Parameters& par, par_bipc& proj_parm)
223 proj_parm.noskew = pj_get_param_b<srs::spar::ns>(params, "ns", srs::dpar::ns);
227 }} // namespace detail::bipc
231 \brief Bipolar conic of western hemisphere projection
233 \tparam Geographic latlong point type
234 \tparam Cartesian xy point type
235 \tparam Parameters parameter type
236 \par Projection characteristics
239 \par Projection parameters
242 \image html ex_bipc.gif
244 template <typename T, typename Parameters>
245 struct bipc_spheroid : public detail::bipc::base_bipc_spheroid<T, Parameters>
247 template <typename Params>
248 inline bipc_spheroid(Params const& params, Parameters & par)
250 detail::bipc::setup_bipc(params, par, this->m_proj_parm);
254 #ifndef DOXYGEN_NO_DETAIL
259 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_bipc, bipc_spheroid)
262 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(bipc_entry, bipc_spheroid)
264 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(bipc_init)
266 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(bipc, bipc_entry)
269 } // namespace detail
272 } // namespace projections
274 }} // namespace boost::geometry
276 #endif // BOOST_GEOMETRY_PROJECTIONS_BIPC_HPP