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_SOMERC_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_SOMERC_HPP
43 #include <boost/geometry/util/math.hpp>
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/projects.hpp>
48 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
49 #include <boost/geometry/srs/projections/impl/aasincos.hpp>
51 namespace boost { namespace geometry
56 #ifndef DOXYGEN_NO_DETAIL
57 namespace detail { namespace somerc
59 static const double epsilon = 1.e-10;
60 static const int n_iter = 6;
65 T K, c, hlf_e, kR, cosp0, sinp0;
68 template <typename T, typename Parameters>
69 struct base_somerc_ellipsoid
71 par_somerc<T> m_proj_parm;
74 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
75 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
77 static const T fourth_pi = detail::fourth_pi<T>();
78 static const T half_pi = detail::half_pi<T>();
80 T phip, lamp, phipp, lampp, sp, cp;
82 sp = par.e * sin(lp_lat);
83 phip = 2.* atan( exp( this->m_proj_parm.c * (
84 log(tan(fourth_pi + 0.5 * lp_lat)) - this->m_proj_parm.hlf_e * log((1. + sp)/(1. - sp)))
85 + this->m_proj_parm.K)) - half_pi;
86 lamp = this->m_proj_parm.c * lp_lon;
88 phipp = aasin(this->m_proj_parm.cosp0 * sin(phip) - this->m_proj_parm.sinp0 * cp * cos(lamp));
89 lampp = aasin(cp * sin(lamp) / cos(phipp));
90 xy_x = this->m_proj_parm.kR * lampp;
91 xy_y = this->m_proj_parm.kR * log(tan(fourth_pi + 0.5 * phipp));
94 // INVERSE(e_inverse) ellipsoid & spheroid
95 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
96 inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
98 static const T fourth_pi = detail::fourth_pi<T>();
100 T phip, lamp, phipp, lampp, cp, esp, con, delp;
103 phipp = 2. * (atan(exp(xy_y / this->m_proj_parm.kR)) - fourth_pi);
104 lampp = xy_x / this->m_proj_parm.kR;
106 phip = aasin(this->m_proj_parm.cosp0 * sin(phipp) + this->m_proj_parm.sinp0 * cp * cos(lampp));
107 lamp = aasin(cp * sin(lampp) / cos(phip));
108 con = (this->m_proj_parm.K - log(tan(fourth_pi + 0.5 * phip)))/this->m_proj_parm.c;
109 for (i = n_iter; i ; --i) {
110 esp = par.e * sin(phip);
111 delp = (con + log(tan(fourth_pi + 0.5 * phip)) - this->m_proj_parm.hlf_e *
112 log((1. + esp)/(1. - esp)) ) *
113 (1. - esp * esp) * cos(phip) * par.rone_es;
115 if (fabs(delp) < epsilon)
120 lp_lon = lamp / this->m_proj_parm.c;
122 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
126 static inline std::string get_name()
128 return "somerc_ellipsoid";
133 // Swiss. Obl. Mercator
134 template <typename Parameters, typename T>
135 inline void setup_somerc(Parameters const& par, par_somerc<T>& proj_parm)
137 static const T fourth_pi = detail::fourth_pi<T>();
141 proj_parm.hlf_e = 0.5 * par.e;
144 proj_parm.c = sqrt(1 + par.es * cp * cp * par.rone_es);
146 proj_parm.cosp0 = cos( phip0 = aasin(proj_parm.sinp0 = sp / proj_parm.c) );
148 proj_parm.K = log(tan(fourth_pi + 0.5 * phip0)) - proj_parm.c * (
149 log(tan(fourth_pi + 0.5 * par.phi0)) - proj_parm.hlf_e *
150 log((1. + sp) / (1. - sp)));
151 proj_parm.kR = par.k0 * sqrt(par.one_es) / (1. - sp * sp);
154 }} // namespace detail::somerc
158 \brief Swiss. Obl. Mercator projection
160 \tparam Geographic latlong point type
161 \tparam Cartesian xy point type
162 \tparam Parameters parameter type
163 \par Projection characteristics
168 \image html ex_somerc.gif
170 template <typename T, typename Parameters>
171 struct somerc_ellipsoid : public detail::somerc::base_somerc_ellipsoid<T, Parameters>
173 template <typename Params>
174 inline somerc_ellipsoid(Params const& , Parameters const& par)
176 detail::somerc::setup_somerc(par, this->m_proj_parm);
180 #ifndef DOXYGEN_NO_DETAIL
185 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_somerc, somerc_ellipsoid)
188 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(somerc_entry, somerc_ellipsoid)
190 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(somerc_init)
192 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(somerc, somerc_entry)
195 } // namespace detail
198 } // namespace projections
200 }} // namespace boost::geometry
202 #endif // BOOST_GEOMETRY_PROJECTIONS_SOMERC_HPP