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_CASS_HPP
41 #define BOOST_GEOMETRY_PROJECTIONS_CASS_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/projects.hpp>
46 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
47 #include <boost/geometry/srs/projections/impl/pj_mlfn.hpp>
50 namespace boost { namespace geometry
55 #ifndef DOXYGEN_NO_DETAIL
56 namespace detail { namespace cass
59 //static const double epsilon10 = 1e-10;
60 //static const double C1 = .16666666666666666666;
61 //static const double C2 = .00833333333333333333;
62 //static const double C3 = .04166666666666666666;
63 //static const double C4 = .33333333333333333333;
64 //static const double C5 = .06666666666666666666;
67 inline T C1() { return .16666666666666666666666666666666666666; }
69 inline T C2() { return .00833333333333333333333333333333333333; }
71 inline T C3() { return .04166666666666666666666666666666666666; }
73 inline T C4() { return .33333333333333333333333333333333333333; }
75 inline T C5() { return .06666666666666666666666666666666666666; }
84 template <typename T, typename Parameters>
85 struct base_cass_ellipsoid
87 par_cass<T> m_proj_parm;
89 // FORWARD(e_forward) ellipsoid
90 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
91 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
93 static const T C1 = cass::C1<T>();
94 static const T C2 = cass::C2<T>();
95 static const T C3 = cass::C3<T>();
99 xy_y = pj_mlfn(lp_lat, n, c, this->m_proj_parm.en);
100 n = 1./sqrt(1. - par.es * n * n);
104 c *= par.es * c / (1 - par.es);
106 xy_x = n * a1 * (1. - a2 * t *
107 (C1 - (8. - t + 8. * c) * a2 * C2));
108 xy_y -= this->m_proj_parm.m0 - n * tn * a2 *
109 (.5 + (5. - t + 6. * c) * a2 * C3);
112 // INVERSE(e_inverse) ellipsoid
113 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
114 inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
116 static const T C3 = cass::C3<T>();
117 static const T C4 = cass::C4<T>();
118 static const T C5 = cass::C5<T>();
122 ph1 = pj_inv_mlfn(this->m_proj_parm.m0 + xy_y, par.es, this->m_proj_parm.en);
123 T tn = tan(ph1); T t = tn * tn;
125 T r = 1. / (1. - par.es * n * n);
127 r *= (1. - par.es) * n;
130 lp_lat = ph1 - (n * tn / r) * d2 *
131 (.5 - (1. + 3. * t) * d2 * C3);
132 lp_lon = dd * (1. + t * d2 *
133 (-C4 + (1. + 3. * t) * d2 * C5)) / cos(ph1);
136 static inline std::string get_name()
138 return "cass_ellipsoid";
143 template <typename T, typename Parameters>
144 struct base_cass_spheroid
146 par_cass<T> m_proj_parm;
148 // FORWARD(s_forward) spheroid
149 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
150 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
152 xy_x = asin(cos(lp_lat) * sin(lp_lon));
153 xy_y = atan2(tan(lp_lat) , cos(lp_lon)) - par.phi0;
156 // INVERSE(s_inverse) spheroid
157 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
158 inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
160 T dd = xy_y + par.phi0;
161 lp_lat = asin(sin(dd) * cos(xy_x));
162 lp_lon = atan2(tan(xy_x), cos(dd));
165 static inline std::string get_name()
167 return "cass_spheroid";
173 template <typename Parameters, typename T>
174 inline void setup_cass(Parameters& par, par_cass<T>& proj_parm)
177 proj_parm.en = pj_enfn<T>(par.es);
178 proj_parm.m0 = pj_mlfn(par.phi0, sin(par.phi0), cos(par.phi0), proj_parm.en);
183 }} // namespace detail::cass
187 \brief Cassini projection
189 \tparam Geographic latlong point type
190 \tparam Cartesian xy point type
191 \tparam Parameters parameter type
192 \par Projection characteristics
197 \image html ex_cass.gif
199 template <typename T, typename Parameters>
200 struct cass_ellipsoid : public detail::cass::base_cass_ellipsoid<T, Parameters>
202 template <typename Params>
203 inline cass_ellipsoid(Params const& , Parameters const& par)
205 detail::cass::setup_cass(par, this->m_proj_parm);
210 \brief Cassini projection
212 \tparam Geographic latlong point type
213 \tparam Cartesian xy point type
214 \tparam Parameters parameter type
215 \par Projection characteristics
220 \image html ex_cass.gif
222 template <typename T, typename Parameters>
223 struct cass_spheroid : public detail::cass::base_cass_spheroid<T, Parameters>
225 template <typename Params>
226 inline cass_spheroid(Params const& , Parameters const& par)
228 detail::cass::setup_cass(par, this->m_proj_parm);
232 #ifndef DOXYGEN_NO_DETAIL
237 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI2(srs::spar::proj_cass, cass_spheroid, cass_ellipsoid)
240 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI2(cass_entry, cass_spheroid, cass_ellipsoid)
242 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(cass_init)
244 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(cass, cass_entry);
247 } // namespace detail
250 } // namespace projections
252 }} // namespace boost::geometry
254 #endif // BOOST_GEOMETRY_PROJECTIONS_CASS_HPP