Back to home page

EIC code displayed by LXR

 
 

    


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

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_MOLL_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_MOLL_HPP
0042 
0043 #include <boost/geometry/util/math.hpp>
0044 
0045 #include <boost/geometry/srs/projections/impl/base_static.hpp>
0046 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
0047 #include <boost/geometry/srs/projections/impl/projects.hpp>
0048 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
0049 #include <boost/geometry/srs/projections/impl/aasincos.hpp>
0050 
0051 namespace boost { namespace geometry
0052 {
0053 
0054 namespace projections
0055 {
0056     #ifndef DOXYGEN_NO_DETAIL
0057     namespace detail { namespace moll
0058     {
0059 
0060             static const int max_iter = 10;
0061             static const double loop_tol = 1e-7;
0062 
0063             template <typename T>
0064             struct par_moll
0065             {
0066                 T    C_x, C_y, C_p;
0067             };
0068 
0069             template <typename T, typename Parameters>
0070             struct base_moll_spheroid
0071             {
0072                 par_moll<T> m_proj_parm;
0073 
0074                 // FORWARD(s_forward)  spheroid
0075                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
0076                 inline void fwd(Parameters const& , T const& lp_lon, T lp_lat, T& xy_x, T& xy_y) const
0077                 {
0078                     static const T half_pi = detail::half_pi<T>();
0079 
0080                     T k, V;
0081                     int i;
0082 
0083                     k = this->m_proj_parm.C_p * sin(lp_lat);
0084                     for (i = max_iter; i ; --i) {
0085                         lp_lat -= V = (lp_lat + sin(lp_lat) - k) /
0086                             (1. + cos(lp_lat));
0087                         if (fabs(V) < loop_tol)
0088                             break;
0089                     }
0090                     if (!i)
0091                         lp_lat = (lp_lat < 0.) ? -half_pi : half_pi;
0092                     else
0093                         lp_lat *= 0.5;
0094                     xy_x = this->m_proj_parm.C_x * lp_lon * cos(lp_lat);
0095                     xy_y = this->m_proj_parm.C_y * sin(lp_lat);
0096                 }
0097 
0098                 // INVERSE(s_inverse)  spheroid
0099                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
0100                 inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
0101                 {
0102                     static const T pi = detail::pi<T>();
0103 
0104                     lp_lat = aasin(xy_y / this->m_proj_parm.C_y);
0105                     lp_lon = xy_x / (this->m_proj_parm.C_x * cos(lp_lat));
0106                     if (fabs(lp_lon) < pi) {
0107                         lp_lat += lp_lat;
0108                         lp_lat = aasin((lp_lat + sin(lp_lat)) / this->m_proj_parm.C_p);
0109                     } else {
0110                         lp_lon = lp_lat = HUGE_VAL;
0111                     }
0112                 }
0113 
0114                 static inline std::string get_name()
0115                 {
0116                     return "moll_spheroid";
0117                 }
0118 
0119             };
0120 
0121             template <typename Parameters, typename T>
0122             inline void setup(Parameters& par, par_moll<T>& proj_parm, T const& p)
0123             {
0124                 T r, sp, p2 = p + p;
0125 
0126                 par.es = 0;
0127                 sp = sin(p);
0128                 r = sqrt(geometry::math::two_pi<T>() * sp / (p2 + sin(p2)));
0129 
0130                 proj_parm.C_x = 2. * r / geometry::math::pi<T>();
0131                 proj_parm.C_y = r / sp;
0132                 proj_parm.C_p = p2 + sin(p2);
0133             }
0134 
0135 
0136             // Mollweide
0137             template <typename Parameters, typename T>
0138             inline void setup_moll(Parameters& par, par_moll<T>& proj_parm)
0139             {
0140                 setup(par, proj_parm, geometry::math::half_pi<T>());
0141             }
0142 
0143             // Wagner IV
0144             template <typename Parameters, typename T>
0145             inline void setup_wag4(Parameters& par, par_moll<T>& proj_parm)
0146             {
0147                 setup(par, proj_parm, geometry::math::pi<T>()/3.);
0148             }
0149 
0150             // Wagner V
0151             template <typename Parameters, typename T>
0152             inline void setup_wag5(Parameters& par, par_moll<T>& proj_parm)
0153             {
0154                 par.es = 0;
0155                 proj_parm.C_x = 0.90977;
0156                 proj_parm.C_y = 1.65014;
0157                 proj_parm.C_p = 3.00896;
0158             }
0159 
0160     }} // namespace detail::moll
0161     #endif // doxygen
0162 
0163     /*!
0164         \brief Mollweide projection
0165         \ingroup projections
0166         \tparam Geographic latlong point type
0167         \tparam Cartesian xy point type
0168         \tparam Parameters parameter type
0169         \par Projection characteristics
0170          - Pseudocylindrical
0171          - Spheroid
0172         \par Example
0173         \image html ex_moll.gif
0174     */
0175     template <typename T, typename Parameters>
0176     struct moll_spheroid : public detail::moll::base_moll_spheroid<T, Parameters>
0177     {
0178         template <typename Params>
0179         inline moll_spheroid(Params const& , Parameters & par)
0180         {
0181             detail::moll::setup_moll(par, this->m_proj_parm);
0182         }
0183     };
0184 
0185     /*!
0186         \brief Wagner IV projection
0187         \ingroup projections
0188         \tparam Geographic latlong point type
0189         \tparam Cartesian xy point type
0190         \tparam Parameters parameter type
0191         \par Projection characteristics
0192          - Pseudocylindrical
0193          - Spheroid
0194         \par Example
0195         \image html ex_wag4.gif
0196     */
0197     template <typename T, typename Parameters>
0198     struct wag4_spheroid : public detail::moll::base_moll_spheroid<T, Parameters>
0199     {
0200         template <typename Params>
0201         inline wag4_spheroid(Params const& , Parameters & par)
0202         {
0203             detail::moll::setup_wag4(par, this->m_proj_parm);
0204         }
0205     };
0206 
0207     /*!
0208         \brief Wagner V projection
0209         \ingroup projections
0210         \tparam Geographic latlong point type
0211         \tparam Cartesian xy point type
0212         \tparam Parameters parameter type
0213         \par Projection characteristics
0214          - Pseudocylindrical
0215          - Spheroid
0216         \par Example
0217         \image html ex_wag5.gif
0218     */
0219     template <typename T, typename Parameters>
0220     struct wag5_spheroid : public detail::moll::base_moll_spheroid<T, Parameters>
0221     {
0222         template <typename Params>
0223         inline wag5_spheroid(Params const& , Parameters & par)
0224         {
0225             detail::moll::setup_wag5(par, this->m_proj_parm);
0226         }
0227     };
0228 
0229     #ifndef DOXYGEN_NO_DETAIL
0230     namespace detail
0231     {
0232 
0233         // Static projection
0234         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_moll, moll_spheroid)
0235         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_wag4, wag4_spheroid)
0236         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_wag5, wag5_spheroid)
0237 
0238         // Factory entry(s)
0239         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(moll_entry, moll_spheroid)
0240         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(wag4_entry, wag4_spheroid)
0241         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(wag5_entry, wag5_spheroid)
0242 
0243         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(moll_init)
0244         {
0245             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(moll, moll_entry);
0246             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(wag4, wag4_entry);
0247             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(wag5, wag5_entry);
0248         }
0249 
0250     } // namespace detail
0251     #endif // doxygen
0252 
0253 } // namespace projections
0254 
0255 }} // namespace boost::geometry
0256 
0257 #endif // BOOST_GEOMETRY_PROJECTIONS_MOLL_HPP
0258