Back to home page

EIC code displayed by LXR

 
 

    


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

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 // Copyright (c) 2003   Gerald I. Evenden
0023 
0024 // Permission is hereby granted, free of charge, to any person obtaining a
0025 // copy of this software and associated documentation files (the "Software"),
0026 // to deal in the Software without restriction, including without limitation
0027 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
0028 // and/or sell copies of the Software, and to permit persons to whom the
0029 // Software is furnished to do so, subject to the following conditions:
0030 
0031 // The above copyright notice and this permission notice shall be included
0032 // in all copies or substantial portions of the Software.
0033 
0034 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0035 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0036 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0037 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0038 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0039 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0040 // DEALINGS IN THE SOFTWARE.
0041 
0042 #ifndef BOOST_GEOMETRY_PROJECTIONS_STEREA_HPP
0043 #define BOOST_GEOMETRY_PROJECTIONS_STEREA_HPP
0044 
0045 #include <boost/math/special_functions/hypot.hpp>
0046 
0047 #include <boost/geometry/srs/projections/impl/base_static.hpp>
0048 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
0049 #include <boost/geometry/srs/projections/impl/projects.hpp>
0050 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
0051 #include <boost/geometry/srs/projections/impl/pj_gauss.hpp>
0052 
0053 
0054 namespace boost { namespace geometry
0055 {
0056 
0057 namespace projections
0058 {
0059     #ifndef DOXYGEN_NO_DETAIL
0060     namespace detail { namespace sterea
0061     {
0062 
0063             template <typename T>
0064             struct par_sterea
0065             {
0066                 T phic0;
0067                 T cosc0, sinc0;
0068                 T R2;
0069                 gauss<T> en;
0070             };
0071 
0072             template <typename T, typename Parameters>
0073             struct base_sterea_ellipsoid
0074             {
0075                 par_sterea<T> m_proj_parm;
0076 
0077                 // FORWARD(e_forward)  ellipsoid
0078                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
0079                 inline void fwd(Parameters const& par, T lp_lon, T lp_lat, T& xy_x, T& xy_y) const
0080                 {
0081                     T cosc, sinc, cosl_, k;
0082 
0083                     detail::gauss_fwd(m_proj_parm.en, lp_lon, lp_lat);
0084                     sinc = sin(lp_lat);
0085                     cosc = cos(lp_lat);
0086                     cosl_ = cos(lp_lon);
0087                     k = par.k0 * this->m_proj_parm.R2 / (1. + this->m_proj_parm.sinc0 * sinc + this->m_proj_parm.cosc0 * cosc * cosl_);
0088                     xy_x = k * cosc * sin(lp_lon);
0089                     xy_y = k * (this->m_proj_parm.cosc0 * sinc - this->m_proj_parm.sinc0 * cosc * cosl_);
0090                 }
0091 
0092                 // INVERSE(e_inverse)  ellipsoid
0093                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
0094                 inline void inv(Parameters const& par, T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
0095                 {
0096                     T rho, c, sinc, cosc;
0097 
0098                     xy_x /= par.k0;
0099                     xy_y /= par.k0;
0100                     if((rho = boost::math::hypot(xy_x, xy_y)) != 0.0) {
0101                         c = 2. * atan2(rho, this->m_proj_parm.R2);
0102                         sinc = sin(c);
0103                         cosc = cos(c);
0104                         lp_lat = asin(cosc * this->m_proj_parm.sinc0 + xy_y * sinc * this->m_proj_parm.cosc0 / rho);
0105                         lp_lon = atan2(xy_x * sinc, rho * this->m_proj_parm.cosc0 * cosc -
0106                                         xy_y * this->m_proj_parm.sinc0 * sinc);
0107                     } else {
0108                         lp_lat = this->m_proj_parm.phic0;
0109                         lp_lon = 0.;
0110                     }
0111                     detail::gauss_inv(m_proj_parm.en, lp_lon, lp_lat);
0112                 }
0113 
0114                 static inline std::string get_name()
0115                 {
0116                     return "sterea_ellipsoid";
0117                 }
0118 
0119             };
0120 
0121             // Oblique Stereographic Alternative
0122             template <typename Parameters, typename T>
0123             inline void setup_sterea(Parameters const& par, par_sterea<T>& proj_parm)
0124             {
0125                 T R;
0126 
0127                 proj_parm.en = detail::gauss_ini(par.e, par.phi0, proj_parm.phic0, R);
0128                 proj_parm.sinc0 = sin(proj_parm.phic0);
0129                 proj_parm.cosc0 = cos(proj_parm.phic0);
0130                 proj_parm.R2 = 2. * R;
0131             }
0132 
0133     }} // namespace detail::sterea
0134     #endif // doxygen
0135 
0136     /*!
0137         \brief Oblique Stereographic Alternative projection
0138         \ingroup projections
0139         \tparam Geographic latlong point type
0140         \tparam Cartesian xy point type
0141         \tparam Parameters parameter type
0142         \par Projection characteristics
0143          - Azimuthal
0144          - Spheroid
0145          - Ellipsoid
0146         \par Example
0147         \image html ex_sterea.gif
0148     */
0149     template <typename T, typename Parameters>
0150     struct sterea_ellipsoid : public detail::sterea::base_sterea_ellipsoid<T, Parameters>
0151     {
0152         template <typename Params>
0153         inline sterea_ellipsoid(Params const& , Parameters const& par)
0154         {
0155             detail::sterea::setup_sterea(par, this->m_proj_parm);
0156         }
0157     };
0158 
0159     #ifndef DOXYGEN_NO_DETAIL
0160     namespace detail
0161     {
0162 
0163         // Static projection
0164         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_sterea, sterea_ellipsoid)
0165 
0166         // Factory entry(s)
0167         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(sterea_entry, sterea_ellipsoid)
0168 
0169         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(sterea_init)
0170         {
0171             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(sterea, sterea_entry)
0172         }
0173 
0174     } // namespace detail
0175     #endif // doxygen
0176 
0177 } // namespace projections
0178 
0179 }} // namespace boost::geometry
0180 
0181 #endif // BOOST_GEOMETRY_PROJECTIONS_STEREA_HPP
0182