Back to home page

EIC code displayed by LXR

 
 

    


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

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_LABRD_HPP
0041 #define BOOST_GEOMETRY_PROJECTIONS_LABRD_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 labrd
0056     {
0057             static const double epsilon = 1.e-10;
0058 
0059             template <typename T>
0060             struct par_labrd
0061             {
0062                 T    Az, kRg, p0s, A, C, Ca, Cb, Cc, Cd;
0063             };
0064 
0065             template <typename T, typename Parameters>
0066             struct base_labrd_ellipsoid
0067             {
0068                 par_labrd<T> m_proj_parm;
0069 
0070                 // FORWARD(e_forward)
0071                 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
0072                 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
0073                 {
0074                     static const T fourth_pi = detail::fourth_pi<T>();
0075 
0076                     T V1, V2, ps, sinps, cosps, sinps2, cosps2;
0077                     T I1, I2, I3, I4, I5, I6, x2, y2, t;
0078 
0079                     V1 = this->m_proj_parm.A * log( tan(fourth_pi + .5 * lp_lat) );
0080                     t = par.e * sin(lp_lat);
0081                     V2 = .5 * par.e * this->m_proj_parm.A * log ((1. + t)/(1. - t));
0082                     ps = 2. * (atan(exp(V1 - V2 + this->m_proj_parm.C)) - fourth_pi);
0083                     I1 = ps - this->m_proj_parm.p0s;
0084                     cosps = cos(ps);    cosps2 = cosps * cosps;
0085                     sinps = sin(ps);    sinps2 = sinps * sinps;
0086                     I4 = this->m_proj_parm.A * cosps;
0087                     I2 = .5 * this->m_proj_parm.A * I4 * sinps;
0088                     I3 = I2 * this->m_proj_parm.A * this->m_proj_parm.A * (5. * cosps2 - sinps2) / 12.;
0089                     I6 = I4 * this->m_proj_parm.A * this->m_proj_parm.A;
0090                     I5 = I6 * (cosps2 - sinps2) / 6.;
0091                     I6 *= this->m_proj_parm.A * this->m_proj_parm.A *
0092                         (5. * cosps2 * cosps2 + sinps2 * (sinps2 - 18. * cosps2)) / 120.;
0093                     t = lp_lon * lp_lon;
0094                     xy_x = this->m_proj_parm.kRg * lp_lon * (I4 + t * (I5 + t * I6));
0095                     xy_y = this->m_proj_parm.kRg * (I1 + t * (I2 + t * I3));
0096                     x2 = xy_x * xy_x;
0097                     y2 = xy_y * xy_y;
0098                     V1 = 3. * xy_x * y2 - xy_x * x2;
0099                     V2 = xy_y * y2 - 3. * x2 * xy_y;
0100                     xy_x += this->m_proj_parm.Ca * V1 + this->m_proj_parm.Cb * V2;
0101                     xy_y += this->m_proj_parm.Ca * V2 - this->m_proj_parm.Cb * V1;
0102                 }
0103 
0104                 // INVERSE(e_inverse)  ellipsoid & spheroid
0105                 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
0106                 inline void inv(Parameters const& par, T xy_x, T xy_y, T& lp_lon, T& lp_lat) const
0107                 {
0108                     static const T fourth_pi = detail::fourth_pi<T>();
0109 
0110                     /* t = 0.0 optimization is to avoid a false positive cppcheck warning */
0111                     /* (cppcheck git beaf29c15867984aa3c2a15cf15bd7576ccde2b3). Might no */
0112                     /* longer be necessary with later versions. */
0113                     T x2, y2, V1, V2, V3, V4, t = 0.0, t2, ps, pe, tpe, s;
0114                     T I7, I8, I9, I10, I11, d, Re;
0115                     int i;
0116 
0117                     x2 = xy_x * xy_x;
0118                     y2 = xy_y * xy_y;
0119                     V1 = 3. * xy_x * y2 - xy_x * x2;
0120                     V2 = xy_y * y2 - 3. * x2 * xy_y;
0121                     V3 = xy_x * (5. * y2 * y2 + x2 * (-10. * y2 + x2 ));
0122                     V4 = xy_y * (5. * x2 * x2 + y2 * (-10. * x2 + y2 ));
0123                     xy_x += - this->m_proj_parm.Ca * V1 - this->m_proj_parm.Cb * V2 + this->m_proj_parm.Cc * V3 + this->m_proj_parm.Cd * V4;
0124                     xy_y +=   this->m_proj_parm.Cb * V1 - this->m_proj_parm.Ca * V2 - this->m_proj_parm.Cd * V3 + this->m_proj_parm.Cc * V4;
0125                     ps = this->m_proj_parm.p0s + xy_y / this->m_proj_parm.kRg;
0126                     pe = ps + par.phi0 - this->m_proj_parm.p0s;
0127 
0128                     for ( i = 20; i; --i) {
0129                         V1 = this->m_proj_parm.A * log(tan(fourth_pi + .5 * pe));
0130                         tpe = par.e * sin(pe);
0131                         V2 = .5 * par.e * this->m_proj_parm.A * log((1. + tpe)/(1. - tpe));
0132                         t = ps - 2. * (atan(exp(V1 - V2 + this->m_proj_parm.C)) - fourth_pi);
0133                         pe += t;
0134                         if (fabs(t) < epsilon)
0135                             break;
0136                     }
0137 
0138                     t = par.e * sin(pe);
0139                     t = 1. - t * t;
0140                     Re = par.one_es / ( t * sqrt(t) );
0141                     t = tan(ps);
0142                     t2 = t * t;
0143                     s = this->m_proj_parm.kRg * this->m_proj_parm.kRg;
0144                     d = Re * par.k0 * this->m_proj_parm.kRg;
0145                     I7 = t / (2. * d);
0146                     I8 = t * (5. + 3. * t2) / (24. * d * s);
0147                     d = cos(ps) * this->m_proj_parm.kRg * this->m_proj_parm.A;
0148                     I9 = 1. / d;
0149                     d *= s;
0150                     I10 = (1. + 2. * t2) / (6. * d);
0151                     I11 = (5. + t2 * (28. + 24. * t2)) / (120. * d * s);
0152                     x2 = xy_x * xy_x;
0153                     lp_lat = pe + x2 * (-I7 + I8 * x2);
0154                     lp_lon = xy_x * (I9 + x2 * (-I10 + x2 * I11));
0155                 }
0156 
0157                 static inline std::string get_name()
0158                 {
0159                     return "labrd_ellipsoid";
0160                 }
0161 
0162             };
0163 
0164             // Laborde
0165             template <typename Params, typename Parameters, typename T>
0166             inline void setup_labrd(Params const& params, Parameters const& par, par_labrd<T>& proj_parm)
0167             {
0168                 static const T fourth_pi = detail::fourth_pi<T>();
0169 
0170                 T Az, sinp, R, N, t;
0171 
0172                 Az = pj_get_param_r<T, srs::spar::azi>(params, "azi", srs::dpar::azi);
0173                 sinp = sin(par.phi0);
0174                 t = 1. - par.es * sinp * sinp;
0175                 N = 1. / sqrt(t);
0176                 R = par.one_es * N / t;
0177                 proj_parm.kRg = par.k0 * sqrt( N * R );
0178                 proj_parm.p0s = atan( sqrt(R / N) * tan(par.phi0) );
0179                 proj_parm.A = sinp / sin(proj_parm.p0s);
0180                 t = par.e * sinp;
0181                 proj_parm.C = .5 * par.e * proj_parm.A * log((1. + t)/(1. - t)) +
0182                     - proj_parm.A * log( tan(fourth_pi + .5 * par.phi0))
0183                     + log( tan(fourth_pi + .5 * proj_parm.p0s));
0184                 t = Az + Az;
0185                 proj_parm.Ca = (1. - cos(t)) * ( proj_parm.Cb = 1. / (12. * proj_parm.kRg * proj_parm.kRg) );
0186                 proj_parm.Cb *= sin(t);
0187                 proj_parm.Cc = 3. * (proj_parm.Ca * proj_parm.Ca - proj_parm.Cb * proj_parm.Cb);
0188                 proj_parm.Cd = 6. * proj_parm.Ca * proj_parm.Cb;
0189             }
0190 
0191     }} // namespace detail::labrd
0192     #endif // doxygen
0193 
0194     /*!
0195         \brief Laborde projection
0196         \ingroup projections
0197         \tparam Geographic latlong point type
0198         \tparam Cartesian xy point type
0199         \tparam Parameters parameter type
0200         \par Projection characteristics
0201          - Cylindrical
0202          - Spheroid
0203          - Special for Madagascar
0204         \par Projection parameters
0205          - no_rot: No rotation (boolean)
0206          - azi: Azimuth (or Gamma) (degrees)
0207         \par Example
0208         \image html ex_labrd.gif
0209     */
0210     template <typename T, typename Parameters>
0211     struct labrd_ellipsoid : public detail::labrd::base_labrd_ellipsoid<T, Parameters>
0212     {
0213         template <typename Params>
0214         inline labrd_ellipsoid(Params const& params, Parameters const& par)
0215         {
0216             detail::labrd::setup_labrd(params, par, this->m_proj_parm);
0217         }
0218     };
0219 
0220     #ifndef DOXYGEN_NO_DETAIL
0221     namespace detail
0222     {
0223 
0224         // Static projection
0225         BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_labrd, labrd_ellipsoid)
0226 
0227         // Factory entry(s)
0228         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(labrd_entry, labrd_ellipsoid)
0229 
0230         BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(labrd_init)
0231         {
0232             BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(labrd, labrd_entry)
0233         }
0234 
0235     } // namespace detail
0236     #endif // doxygen
0237 
0238 } // namespace projections
0239 
0240 }} // namespace boost::geometry
0241 
0242 #endif // BOOST_GEOMETRY_PROJECTIONS_LABRD_HPP
0243