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_EQDC_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_EQDC_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_mlfn.hpp>
0047 #include <boost/geometry/srs/projections/impl/pj_msfn.hpp>
0048 #include <boost/geometry/srs/projections/impl/pj_param.hpp>
0049 #include <boost/geometry/srs/projections/impl/projects.hpp>
0050 
0051 #include <boost/geometry/util/math.hpp>
0052 
0053 #include <boost/math/special_functions/hypot.hpp>
0054 
0055 namespace boost { namespace geometry
0056 {
0057 
0058 namespace projections
0059 {
0060     #ifndef DOXYGEN_NO_DETAIL
0061     namespace detail { namespace eqdc
0062     {
0063 
0064             static const double epsilon10 = 1.e-10;
0065 
0066             template <typename T>
0067             struct par_eqdc
0068             {
0069                 T    phi1;
0070                 T    phi2;
0071                 T    n;
0072                 T    rho0;
0073                 T    c;
0074                 detail::en<T> en;
0075                 bool ellips;
0076             };
0077 
0078             template <typename T, typename Parameters>
0079             struct base_eqdc_ellipsoid
0080             {
0081                 par_eqdc<T> m_proj_parm;
0082 
0083                 // FORWARD(e_forward)  sphere & ellipsoid
0084                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
0085                 inline void fwd(Parameters const& , T lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
0086                 {
0087                     T rho = 0.0;
0088 
0089                     rho = this->m_proj_parm.c - (this->m_proj_parm.ellips ? pj_mlfn(lp_lat, sin(lp_lat),
0090                         cos(lp_lat), this->m_proj_parm.en) : lp_lat);
0091                     xy_x = rho * sin( lp_lon *= this->m_proj_parm.n );
0092                     xy_y = this->m_proj_parm.rho0 - rho * cos(lp_lon);
0093                 }
0094 
0095                 // INVERSE(e_inverse)  sphere & ellipsoid
0096                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
0097                 inline void inv(Parameters const& par, T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
0098                 {
0099                     static T const half_pi = detail::half_pi<T>();
0100 
0101                     T rho = 0.0;
0102 
0103                     if ((rho = boost::math::hypot(xy_x, xy_y = this->m_proj_parm.rho0 - xy_y)) != 0.0 ) {
0104                         if (this->m_proj_parm.n < 0.) {
0105                             rho = -rho;
0106                             xy_x = -xy_x;
0107                             xy_y = -xy_y;
0108                         }
0109                         lp_lat = this->m_proj_parm.c - rho;
0110                         if (this->m_proj_parm.ellips)
0111                             lp_lat = pj_inv_mlfn(lp_lat, par.es, this->m_proj_parm.en);
0112                         lp_lon = atan2(xy_x, xy_y) / this->m_proj_parm.n;
0113                     } else {
0114                         lp_lon = 0.;
0115                         lp_lat = this->m_proj_parm.n > 0. ? half_pi : -half_pi;
0116                     }
0117                 }
0118 
0119                 static inline std::string get_name()
0120                 {
0121                     return "eqdc_ellipsoid";
0122                 }
0123 
0124             };
0125 
0126             // Equidistant Conic
0127             template <typename Params, typename Parameters, typename T>
0128             inline void setup_eqdc(Params const& params, Parameters& par, par_eqdc<T>& proj_parm)
0129             {
0130                 T cosphi, sinphi;
0131                 int secant;
0132 
0133                 proj_parm.phi1 = pj_get_param_r<T, srs::spar::lat_1>(params, "lat_1", srs::dpar::lat_1);
0134                 proj_parm.phi2 = pj_get_param_r<T, srs::spar::lat_2>(params, "lat_2", srs::dpar::lat_2);
0135 
0136                 if (fabs(proj_parm.phi1 + proj_parm.phi2) < epsilon10)
0137                     BOOST_THROW_EXCEPTION( projection_exception(error_conic_lat_equal) );
0138 
0139                 proj_parm.en = pj_enfn<T>(par.es);
0140 
0141                 proj_parm.n = sinphi = sin(proj_parm.phi1);
0142                 cosphi = cos(proj_parm.phi1);
0143                 secant = fabs(proj_parm.phi1 - proj_parm.phi2) >= epsilon10;
0144                 if( (proj_parm.ellips = (par.es > 0.)) ) {
0145                     double ml1, m1;
0146 
0147                     m1 = pj_msfn(sinphi, cosphi, par.es);
0148                     ml1 = pj_mlfn(proj_parm.phi1, sinphi, cosphi, proj_parm.en);
0149                     if (secant) { /* secant cone */
0150                         sinphi = sin(proj_parm.phi2);
0151                         cosphi = cos(proj_parm.phi2);
0152                         proj_parm.n = (m1 - pj_msfn(sinphi, cosphi, par.es)) /
0153                             (pj_mlfn(proj_parm.phi2, sinphi, cosphi, proj_parm.en) - ml1);
0154                     }
0155                     proj_parm.c = ml1 + m1 / proj_parm.n;
0156                     proj_parm.rho0 = proj_parm.c - pj_mlfn(par.phi0, sin(par.phi0),
0157                         cos(par.phi0), proj_parm.en);
0158                 } else {
0159                     if (secant)
0160                         proj_parm.n = (cosphi - cos(proj_parm.phi2)) / (proj_parm.phi2 - proj_parm.phi1);
0161                     proj_parm.c = proj_parm.phi1 + cos(proj_parm.phi1) / proj_parm.n;
0162                     proj_parm.rho0 = proj_parm.c - par.phi0;
0163                 }
0164             }
0165 
0166     }} // namespace detail::eqdc
0167     #endif // doxygen
0168 
0169     /*!
0170         \brief Equidistant Conic projection
0171         \ingroup projections
0172         \tparam Geographic latlong point type
0173         \tparam Cartesian xy point type
0174         \tparam Parameters parameter type
0175         \par Projection characteristics
0176          - Conic
0177          - Spheroid
0178          - Ellipsoid
0179         \par Projection parameters
0180          - lat_1: Latitude of first standard parallel (degrees)
0181          - lat_2: Latitude of second standard parallel (degrees)
0182         \par Example
0183         \image html ex_eqdc.gif
0184     */
0185     template <typename T, typename Parameters>
0186     struct eqdc_ellipsoid : public detail::eqdc::base_eqdc_ellipsoid<T, Parameters>
0187     {
0188         template <typename Params>
0189         inline eqdc_ellipsoid(Params const& params, Parameters const& par)
0190         {
0191             detail::eqdc::setup_eqdc(params, par, this->m_proj_parm);
0192         }
0193     };
0194 
0195     #ifndef DOXYGEN_NO_DETAIL
0196     namespace detail
0197     {
0198 
0199         // Static projection
0200         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_eqdc, eqdc_ellipsoid)
0201 
0202         // Factory entry(s)
0203         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(eqdc_entry, eqdc_ellipsoid)
0204 
0205         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(eqdc_init)
0206         {
0207             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(eqdc, eqdc_entry);
0208         }
0209 
0210     } // namespace detail
0211     #endif // doxygen
0212 
0213 } // namespace projections
0214 
0215 }} // namespace boost::geometry
0216 
0217 #endif // BOOST_GEOMETRY_PROJECTIONS_EQDC_HPP
0218