Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:41

0001 // Boost.Geometry - gis-projections (based on PROJ4)
0002 
0003 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // This file was modified by Oracle on 2017, 2018, 2019.
0006 // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
0008 
0009 // Use, modification and distribution is subject to the Boost Software License,
0010 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
0012 
0013 // This file is converted from PROJ4, http://trac.osgeo.org/proj
0014 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
0015 // PROJ4 is maintained by Frank Warmerdam
0016 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
0017 
0018 // Last updated version of proj: 5.0.0
0019 
0020 // Original copyright notice:
0021 
0022 // Permission is hereby granted, free of charge, to any person obtaining a
0023 // copy of this software and associated documentation files (the "Software"),
0024 // to deal in the Software without restriction, including without limitation
0025 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
0026 // and/or sell copies of the Software, and to permit persons to whom the
0027 // Software is furnished to do so, subject to the following conditions:
0028 
0029 // The above copyright notice and this permission notice shall be included
0030 // in all copies or substantial portions of the Software.
0031 
0032 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0033 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0034 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0035 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0036 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0037 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0038 // DEALINGS IN THE SOFTWARE.
0039 
0040 #ifndef BOOST_GEOMETRY_PROJECTIONS_FOUC_S_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_FOUC_S_HPP
0042 
0043 #include <boost/geometry/srs/projections/impl/aasincos.hpp>
0044 #include <boost/geometry/srs/projections/impl/base_static.hpp>
0045 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
0046 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
0047 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
0048 #include <boost/geometry/srs/projections/impl/projects.hpp>
0049 
0050 #include <boost/geometry/util/math.hpp>
0051 
0052 namespace boost { namespace geometry
0053 {
0054 
0055 namespace projections
0056 {
0057     #ifndef DOXYGEN_NO_DETAIL
0058     namespace detail { namespace fouc_s
0059     {
0060 
0061             static const int max_iter = 10;
0062             static const double loop_tol = 1e-7;
0063 
0064             template <typename T>
0065             struct par_fouc_s
0066             {
0067                 T n, n1;
0068             };
0069 
0070             template <typename T, typename Parameters>
0071             struct base_fouc_s_spheroid
0072             {
0073                 par_fouc_s<T> m_proj_parm;
0074 
0075                 // FORWARD(s_forward)  spheroid
0076                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
0077                 inline void fwd(Parameters const& , T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
0078                 {
0079                     T t;
0080 
0081                     t = cos(lp_lat);
0082                     xy_x = lp_lon * t / (this->m_proj_parm.n + this->m_proj_parm.n1 * t);
0083                     xy_y = this->m_proj_parm.n * lp_lat + this->m_proj_parm.n1 * sin(lp_lat);
0084                 }
0085 
0086                 // INVERSE(s_inverse)  spheroid
0087                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
0088                 inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
0089                 {
0090                     static T const half_pi = detail::half_pi<T>();
0091 
0092                     T V;
0093                     int i;
0094 
0095                     if (this->m_proj_parm.n != 0.0) {
0096                         lp_lat = xy_y;
0097                         for (i = max_iter; i ; --i) {
0098                             lp_lat -= V = (this->m_proj_parm.n * lp_lat + this->m_proj_parm.n1 * sin(lp_lat) - xy_y ) /
0099                                 (this->m_proj_parm.n + this->m_proj_parm.n1 * cos(lp_lat));
0100                             if (fabs(V) < loop_tol)
0101                                 break;
0102                         }
0103                         if (!i)
0104                             lp_lat = xy_y < 0. ? -half_pi : half_pi;
0105                     } else
0106                         lp_lat = aasin(xy_y);
0107                     V = cos(lp_lat);
0108                     lp_lon = xy_x * (this->m_proj_parm.n + this->m_proj_parm.n1 * V) / V;
0109                 }
0110 
0111                 static inline std::string get_name()
0112                 {
0113                     return "fouc_s_spheroid";
0114                 }
0115 
0116             };
0117 
0118             // Foucaut Sinusoidal
0119             template <typename Params, typename Parameters, typename T>
0120             inline void setup_fouc_s(Params const& params, Parameters& par, par_fouc_s<T>& proj_parm)
0121             {
0122                 proj_parm.n = pj_get_param_f<T, srs::spar::n>(params, "n", srs::dpar::n);
0123                 if ((proj_parm.n < 0.) || (proj_parm.n > 1.))
0124                     BOOST_THROW_EXCEPTION( projection_exception(error_n_out_of_range) );
0125 
0126                 proj_parm.n1 = 1. - proj_parm.n;
0127                 par.es = 0;
0128             }
0129 
0130     }} // namespace detail::fouc_s
0131     #endif // doxygen
0132 
0133     /*!
0134         \brief Foucaut Sinusoidal projection
0135         \ingroup projections
0136         \tparam Geographic latlong point type
0137         \tparam Cartesian xy point type
0138         \tparam Parameters parameter type
0139         \par Projection characteristics
0140          - Pseudocylindrical
0141          - Spheroid
0142         \par Projection parameters
0143          - n (real)
0144         \par Example
0145         \image html ex_fouc_s.gif
0146     */
0147     template <typename T, typename Parameters>
0148     struct fouc_s_spheroid : public detail::fouc_s::base_fouc_s_spheroid<T, Parameters>
0149     {
0150         template <typename Params>
0151         inline fouc_s_spheroid(Params const& params, Parameters & par)
0152         {
0153             detail::fouc_s::setup_fouc_s(params, par, this->m_proj_parm);
0154         }
0155     };
0156 
0157     #ifndef DOXYGEN_NO_DETAIL
0158     namespace detail
0159     {
0160 
0161         // Static projection
0162         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_fouc_s, fouc_s_spheroid)
0163 
0164         // Factory entry(s)
0165         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(fouc_s_entry, fouc_s_spheroid)
0166 
0167         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(fouc_s_init)
0168         {
0169             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(fouc_s, fouc_s_entry);
0170         }
0171 
0172     } // namespace detail
0173     #endif // doxygen
0174 
0175 } // namespace projections
0176 
0177 }} // namespace boost::geometry
0178 
0179 #endif // BOOST_GEOMETRY_PROJECTIONS_FOUC_S_HPP
0180