1 #ifndef BOOST_GEOMETRY_PROJECTIONS_GNOM_HPP
2 #define BOOST_GEOMETRY_PROJECTIONS_GNOM_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, 2018.
10 // Modifications copyright (c) 2017-2018, 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 // Permission is hereby granted, free of charge, to any person obtaining a
27 // copy of this software and associated documentation files (the "Software"),
28 // to deal in the Software without restriction, including without limitation
29 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
30 // and/or sell copies of the Software, and to permit persons to whom the
31 // Software is furnished to do so, subject to the following conditions:
33 // The above copyright notice and this permission notice shall be included
34 // in all copies or substantial portions of the Software.
36 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
37 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
42 // DEALINGS IN THE SOFTWARE.
44 #include <boost/config.hpp>
45 #include <boost/geometry/util/math.hpp>
46 #include <boost/math/special_functions/hypot.hpp>
48 #include <boost/geometry/srs/projections/impl/base_static.hpp>
49 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
50 #include <boost/geometry/srs/projections/impl/projects.hpp>
51 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
53 namespace boost { namespace geometry
56 namespace srs { namespace par4
60 }} //namespace srs::par4
64 #ifndef DOXYGEN_NO_DETAIL
65 namespace detail { namespace gnom
68 static const double EPS10 = 1.e-10;
69 static const int N_POLE = 0;
70 static const int S_POLE = 1;
71 static const int EQUIT = 2;
72 static const int OBLIQ = 3;
82 // template class, using CRTP to implement forward/inverse
83 template <typename CalculationType, typename Parameters>
84 struct base_gnom_spheroid : public base_t_fi<base_gnom_spheroid<CalculationType, Parameters>,
85 CalculationType, Parameters>
88 typedef CalculationType geographic_type;
89 typedef CalculationType cartesian_type;
91 par_gnom<CalculationType> m_proj_parm;
93 inline base_gnom_spheroid(const Parameters& par)
94 : base_t_fi<base_gnom_spheroid<CalculationType, Parameters>,
95 CalculationType, Parameters>(*this, par) {}
97 // FORWARD(s_forward) spheroid
98 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
99 inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
101 CalculationType coslam, cosphi, sinphi;
103 sinphi = sin(lp_lat);
104 cosphi = cos(lp_lat);
105 coslam = cos(lp_lon);
106 switch (this->m_proj_parm.mode) {
108 xy_y = cosphi * coslam;
111 xy_y = this->m_proj_parm.sinph0 * sinphi + this->m_proj_parm.cosph0 * cosphi * coslam;
121 BOOST_THROW_EXCEPTION( projection_exception(-20) );
122 xy_x = (xy_y = 1. / xy_y) * cosphi * sin(lp_lon);
123 switch (this->m_proj_parm.mode) {
128 xy_y *= this->m_proj_parm.cosph0 * sinphi - this->m_proj_parm.sinph0 * cosphi * coslam;
134 xy_y *= cosphi * coslam;
139 // INVERSE(s_inverse) spheroid
140 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
141 inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
143 static const CalculationType HALFPI = detail::HALFPI<CalculationType>();
145 CalculationType rh, cosz, sinz;
147 rh = boost::math::hypot(xy_x, xy_y);
148 sinz = sin(lp_lat = atan(rh));
149 cosz = sqrt(1. - sinz * sinz);
150 if (fabs(rh) <= EPS10) {
151 lp_lat = this->m_par.phi0;
154 switch (this->m_proj_parm.mode) {
156 lp_lat = cosz * this->m_proj_parm.sinph0 + xy_y * sinz * this->m_proj_parm.cosph0 / rh;
157 if (fabs(lp_lat) >= 1.)
158 lp_lat = lp_lat > 0. ? HALFPI : -HALFPI;
160 lp_lat = asin(lp_lat);
161 xy_y = (cosz - this->m_proj_parm.sinph0 * sin(lp_lat)) * rh;
162 xy_x *= sinz * this->m_proj_parm.cosph0;
165 lp_lat = xy_y * sinz / rh;
166 if (fabs(lp_lat) >= 1.)
167 lp_lat = lp_lat > 0. ? HALFPI : -HALFPI;
169 lp_lat = asin(lp_lat);
177 lp_lat = HALFPI - lp_lat;
181 lp_lon = atan2(xy_x, xy_y);
185 static inline std::string get_name()
187 return "gnom_spheroid";
193 template <typename Parameters, typename T>
194 inline void setup_gnom(Parameters& par, par_gnom<T>& proj_parm)
196 static const T HALFPI = detail::HALFPI<T>();
198 if (fabs(fabs(par.phi0) - HALFPI) < EPS10)
199 proj_parm.mode = par.phi0 < 0. ? S_POLE : N_POLE;
200 else if (fabs(par.phi0) < EPS10)
201 proj_parm.mode = EQUIT;
203 proj_parm.mode = OBLIQ;
204 proj_parm.sinph0 = sin(par.phi0);
205 proj_parm.cosph0 = cos(par.phi0);
210 }} // namespace detail::gnom
214 \brief Gnomonic projection
216 \tparam Geographic latlong point type
217 \tparam Cartesian xy point type
218 \tparam Parameters parameter type
219 \par Projection characteristics
223 \image html ex_gnom.gif
225 template <typename CalculationType, typename Parameters>
226 struct gnom_spheroid : public detail::gnom::base_gnom_spheroid<CalculationType, Parameters>
228 inline gnom_spheroid(const Parameters& par) : detail::gnom::base_gnom_spheroid<CalculationType, Parameters>(par)
230 detail::gnom::setup_gnom(this->m_par, this->m_proj_parm);
234 #ifndef DOXYGEN_NO_DETAIL
239 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(srs::par4::gnom, gnom_spheroid, gnom_spheroid)
242 template <typename CalculationType, typename Parameters>
243 class gnom_entry : public detail::factory_entry<CalculationType, Parameters>
246 virtual base_v<CalculationType, Parameters>* create_new(const Parameters& par) const
248 return new base_v_fi<gnom_spheroid<CalculationType, Parameters>, CalculationType, Parameters>(par);
252 template <typename CalculationType, typename Parameters>
253 inline void gnom_init(detail::base_factory<CalculationType, Parameters>& factory)
255 factory.add_to_factory("gnom", new gnom_entry<CalculationType, Parameters>);
258 } // namespace detail
261 } // namespace projections
263 }} // namespace boost::geometry
265 #endif // BOOST_GEOMETRY_PROJECTIONS_GNOM_HPP