Back to home page

EIC code displayed by LXR

 
 

    


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

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_HAMMER_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_HAMMER_HPP
0042 
0043 #include <boost/geometry/srs/projections/impl/base_static.hpp>
0044 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
0045 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
0046 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
0047 #include <boost/geometry/srs/projections/impl/projects.hpp>
0048 
0049 namespace boost { namespace geometry
0050 {
0051 
0052 namespace projections
0053 {
0054     #ifndef DOXYGEN_NO_DETAIL
0055     namespace detail { namespace hammer
0056     {
0057             static const double epsilon = 1.0e-10;
0058 
0059             template <typename T>
0060             struct par_hammer
0061             {
0062                 T w;
0063                 T m, rm;
0064             };
0065 
0066             template <typename T, typename Parameters>
0067             struct base_hammer_spheroid
0068             {
0069                 par_hammer<T> m_proj_parm;
0070 
0071                 // FORWARD(s_forward)  spheroid
0072                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
0073                 inline void fwd(Parameters const& , T lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
0074                 {
0075                     T cosphi, d;
0076 
0077                     d = sqrt(2./(1. + (cosphi = cos(lp_lat)) * cos(lp_lon *= this->m_proj_parm.w)));
0078                     xy_x = this->m_proj_parm.m * d * cosphi * sin(lp_lon);
0079                     xy_y = this->m_proj_parm.rm * d * sin(lp_lat);
0080                 }
0081 
0082                 // INVERSE(s_inverse)  spheroid
0083                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
0084                 inline void inv(Parameters const& , T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
0085                 {
0086                     T z;
0087 
0088                     z = sqrt(1. - 0.25*this->m_proj_parm.w*this->m_proj_parm.w*xy_x*xy_x - 0.25*xy_y*xy_y);
0089                     if (geometry::math::abs(2.*z*z-1.) < epsilon) {
0090                         lp_lon = HUGE_VAL;
0091                         lp_lat = HUGE_VAL;
0092                         BOOST_THROW_EXCEPTION( projection_exception(error_lat_or_lon_exceed_limit) );
0093                     } else {
0094                         lp_lon = aatan2(this->m_proj_parm.w * xy_x * z,2. * z * z - 1)/this->m_proj_parm.w;
0095                         lp_lat = aasin(z * xy_y);
0096                     }
0097                 }
0098 
0099                 static inline std::string get_name()
0100                 {
0101                     return "hammer_spheroid";
0102                 }
0103 
0104             };
0105 
0106             // Hammer & Eckert-Greifendorff
0107             template <typename Params, typename Parameters, typename T>
0108             inline void setup_hammer(Params const& params, Parameters& par, par_hammer<T>& proj_parm)
0109             {
0110                 T tmp;
0111 
0112                 if (pj_param_f<srs::spar::w>(params, "W", srs::dpar::w, tmp)) {
0113                     if ((proj_parm.w = fabs(tmp)) <= 0.)
0114                         BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
0115                 } else
0116                     proj_parm.w = .5;
0117                 if (pj_param_f<srs::spar::m>(params, "M", srs::dpar::m, tmp)) {
0118                     if ((proj_parm.m = fabs(tmp)) <= 0.)
0119                         BOOST_THROW_EXCEPTION( projection_exception(error_w_or_m_zero_or_less) );
0120                 } else
0121                     proj_parm.m = 1.;
0122 
0123                 proj_parm.rm = 1. / proj_parm.m;
0124                 proj_parm.m /= proj_parm.w;
0125 
0126                 par.es = 0.;
0127             }
0128 
0129     }} // namespace detail::hammer
0130     #endif // doxygen
0131 
0132     /*!
0133         \brief Hammer & Eckert-Greifendorff projection
0134         \ingroup projections
0135         \tparam Geographic latlong point type
0136         \tparam Cartesian xy point type
0137         \tparam Parameters parameter type
0138         \par Projection characteristics
0139          - Miscellaneous
0140          - Spheroid
0141          - no inverse
0142         \par Projection parameters
0143          - W (real)
0144          - M (real)
0145         \par Example
0146         \image html ex_hammer.gif
0147     */
0148     template <typename T, typename Parameters>
0149     struct hammer_spheroid : public detail::hammer::base_hammer_spheroid<T, Parameters>
0150     {
0151         template <typename Params>
0152         inline hammer_spheroid(Params const& params, Parameters & par)
0153         {
0154             detail::hammer::setup_hammer(params, par, this->m_proj_parm);
0155         }
0156     };
0157 
0158     #ifndef DOXYGEN_NO_DETAIL
0159     namespace detail
0160     {
0161 
0162         // Static projection
0163         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_hammer, hammer_spheroid)
0164 
0165         // Factory entry(s)
0166         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(hammer_entry, hammer_spheroid)
0167 
0168         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(hammer_init)
0169         {
0170             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(hammer, hammer_entry)
0171         }
0172 
0173     } // namespace detail
0174     #endif // doxygen
0175 
0176 } // namespace projections
0177 
0178 }} // namespace boost::geometry
0179 
0180 #endif // BOOST_GEOMETRY_PROJECTIONS_HAMMER_HPP
0181