1 #ifndef BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP
2 #define BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP
4 // Boost.Geometry - extensions-gis-projections (based on PROJ4)
5 // This file is automatically generated. DO NOT EDIT.
7 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
9 // This file was modified by Oracle on 2017.
10 // Modifications copyright (c) 2017, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // This file is converted from PROJ4, http://trac.osgeo.org/proj
18 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
19 // PROJ4 is maintained by Frank Warmerdam
20 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
22 // Last updated version of proj: 4.9.1
24 // Original copyright notice:
26 // Purpose: Implementation of the airy (Airy) projection.
27 // Author: Gerald Evenden
28 // Copyright (c) 1995, Gerald Evenden
30 // Permission is hereby granted, free of charge, to any person obtaining a
31 // copy of this software and associated documentation files (the "Software"),
32 // to deal in the Software without restriction, including without limitation
33 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 // and/or sell copies of the Software, and to permit persons to whom the
35 // Software is furnished to do so, subject to the following conditions:
37 // The above copyright notice and this permission notice shall be included
38 // in all copies or substantial portions of the Software.
40 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
41 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
43 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
46 // DEALINGS IN THE SOFTWARE.
48 #include <boost/geometry/util/math.hpp>
50 #include <boost/geometry/srs/projections/impl/base_static.hpp>
51 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
52 #include <boost/geometry/srs/projections/impl/projects.hpp>
53 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
55 #include <boost/geometry/srs/projections/par4.hpp> // airy tag
57 namespace boost { namespace geometry
60 namespace srs { namespace par4
62 // already defined in par4.hpp as ellps name
65 }} //namespace srs::par4
69 #ifndef DOXYGEN_NO_DETAIL
70 namespace detail { namespace airy
73 static const double EPS = 1.e-10;
74 static const int N_POLE = 0;
75 static const int S_POLE = 1;
76 static const int EQUIT = 2;
77 static const int OBLIQ = 3;
87 int no_cut; /* do not cut at hemisphere limit */
90 // template class, using CRTP to implement forward/inverse
91 template <typename CalculationType, typename Parameters>
92 struct base_airy_spheroid : public base_t_f<base_airy_spheroid<CalculationType, Parameters>,
93 CalculationType, Parameters>
96 typedef CalculationType geographic_type;
97 typedef CalculationType cartesian_type;
99 par_airy<CalculationType> m_proj_parm;
101 inline base_airy_spheroid(const Parameters& par)
102 : base_t_f<base_airy_spheroid<CalculationType, Parameters>,
103 CalculationType, Parameters>(*this, par) {}
105 // FORWARD(s_forward) spheroid
106 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
107 inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
109 static const CalculationType HALFPI = detail::HALFPI<CalculationType>();
111 CalculationType sinlam, coslam, cosphi, sinphi, t, s, Krho, cosz;
113 sinlam = sin(lp_lon);
114 coslam = cos(lp_lon);
115 switch (this->m_proj_parm.mode) {
118 sinphi = sin(lp_lat);
119 cosphi = cos(lp_lat);
120 cosz = cosphi * coslam;
121 if (this->m_proj_parm.mode == OBLIQ)
122 cosz = this->m_proj_parm.sinph0 * sinphi + this->m_proj_parm.cosph0 * cosz;
123 if (!this->m_proj_parm.no_cut && cosz < -EPS)
124 BOOST_THROW_EXCEPTION( projection_exception(-20) );
125 if (fabs(s = 1. - cosz) > EPS) {
126 t = 0.5 * (1. + cosz);
127 Krho = -log(t)/s - this->m_proj_parm.Cb / t;
129 Krho = 0.5 - this->m_proj_parm.Cb;
130 xy_x = Krho * cosphi * sinlam;
131 if (this->m_proj_parm.mode == OBLIQ)
132 xy_y = Krho * (this->m_proj_parm.cosph0 * sinphi -
133 this->m_proj_parm.sinph0 * cosphi * coslam);
135 xy_y = Krho * sinphi;
139 lp_lat = fabs(this->m_proj_parm.p_halfpi - lp_lat);
140 if (!this->m_proj_parm.no_cut && (lp_lat - EPS) > HALFPI)
141 BOOST_THROW_EXCEPTION( projection_exception(-20) );
142 if ((lp_lat *= 0.5) > EPS) {
144 Krho = -2.*(log(cos(lp_lat)) / t + t * this->m_proj_parm.Cb);
145 xy_x = Krho * sinlam;
146 xy_y = Krho * coslam;
147 if (this->m_proj_parm.mode == N_POLE)
154 static inline std::string get_name()
156 return "airy_spheroid";
162 template <typename Parameters, typename T>
163 inline void setup_airy(Parameters& par, par_airy<T>& proj_parm)
165 static const T HALFPI = detail::HALFPI<T>();
169 proj_parm.no_cut = pj_param(par.params, "bno_cut").i;
170 beta = 0.5 * (HALFPI - pj_param(par.params, "rlat_b").f);
171 if (fabs(beta) < EPS)
174 proj_parm.Cb = 1./tan(beta);
175 proj_parm.Cb *= proj_parm.Cb * log(cos(beta));
177 if (fabs(fabs(par.phi0) - HALFPI) < EPS)
179 proj_parm.p_halfpi = -HALFPI;
180 proj_parm.mode = S_POLE;
182 proj_parm.p_halfpi = HALFPI;
183 proj_parm.mode = N_POLE;
186 if (fabs(par.phi0) < EPS)
187 proj_parm.mode = EQUIT;
189 proj_parm.mode = OBLIQ;
190 proj_parm.sinph0 = sin(par.phi0);
191 proj_parm.cosph0 = cos(par.phi0);
197 }} // namespace detail::airy
201 \brief Airy projection
203 \tparam Geographic latlong point type
204 \tparam Cartesian xy point type
205 \tparam Parameters parameter type
206 \par Projection characteristics
210 \par Projection parameters
211 - no_cut: Do not cut at hemisphere limit (boolean)
214 \image html ex_airy.gif
216 template <typename CalculationType, typename Parameters>
217 struct airy_spheroid : public detail::airy::base_airy_spheroid<CalculationType, Parameters>
219 inline airy_spheroid(const Parameters& par) : detail::airy::base_airy_spheroid<CalculationType, Parameters>(par)
221 detail::airy::setup_airy(this->m_par, this->m_proj_parm);
225 #ifndef DOXYGEN_NO_DETAIL
230 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::airy, airy_spheroid, airy_spheroid)
233 template <typename CalculationType, typename Parameters>
234 class airy_entry : public detail::factory_entry<CalculationType, Parameters>
237 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
239 return new base_v_f<airy_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
243 template <typename CalculationType, typename Parameters>
244 inline void airy_init(detail::base_factory<CalculationType, Parameters>& factory)
246 factory.add_to_factory("airy", new airy_entry<CalculationType, Parameters>);
249 } // namespace detail
252 } // namespace projections
254 }} // namespace boost::geometry
256 #endif // BOOST_GEOMETRY_PROJECTIONS_AIRY_HPP