1 // Boost.Geometry - gis-projections (based on PROJ4) 2 3 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands. 4 5 // This file was modified by Oracle on 2017, 2018, 2019. 6 // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates. 7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle. 8 9 // Use, modification and distribution is subject to the Boost Software License, 10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 11 // http://www.boost.org/LICENSE_1_0.txt) 12 13 // This file is converted from PROJ4, http://trac.osgeo.org/proj 14 // PROJ4 is originally written by Gerald Evenden (then of the USGS) 15 // PROJ4 is maintained by Frank Warmerdam 16 // PROJ4 is converted to Boost.Geometry by Barend Gehrels 17 18 // Last updated version of proj: 5.0.0 19 20 // Original copyright notice: 21 22 // Permission is hereby granted, free of charge, to any person obtaining a 23 // copy of this software and associated documentation files (the "Software"), 24 // to deal in the Software without restriction, including without limitation 25 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 26 // and/or sell copies of the Software, and to permit persons to whom the 27 // Software is furnished to do so, subject to the following conditions: 28 29 // The above copyright notice and this permission notice shall be included 30 // in all copies or substantial portions of the Software. 31 32 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 33 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 35 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 37 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 38 // DEALINGS IN THE SOFTWARE. 39 40 #ifndef BOOST_GEOMETRY_PROJECTIONS_LABRD_HPP 41 #define BOOST_GEOMETRY_PROJECTIONS_LABRD_HPP 42 43 #include <boost/geometry/srs/projections/impl/base_static.hpp> 44 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp> 45 #include <boost/geometry/srs/projections/impl/factory_entry.hpp> 46 #include <boost/geometry/srs/projections/impl/pj_param.hpp> 47 #include <boost/geometry/srs/projections/impl/projects.hpp> 48 49 namespace boost { namespace geometry 50 { 51 52 namespace projections 53 { 54 #ifndef DOXYGEN_NO_DETAIL 55 namespace detail { namespace labrd 56 { 57 static const double epsilon = 1.e-10; 58 59 template <typename T> 60 struct par_labrd 61 { 62 T Az, kRg, p0s, A, C, Ca, Cb, Cc, Cd; 63 }; 64 65 template <typename T, typename Parameters> 66 struct base_labrd_ellipsoid 67 { 68 par_labrd<T> m_proj_parm; 69 70 // FORWARD(e_forward) 71 // Project coordinates from geographic (lon, lat) to cartesian (x, y) fwdboost::geometry::projections::detail::labrd::base_labrd_ellipsoid72 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const 73 { 74 static const T fourth_pi = detail::fourth_pi<T>(); 75 76 T V1, V2, ps, sinps, cosps, sinps2, cosps2; 77 T I1, I2, I3, I4, I5, I6, x2, y2, t; 78 79 V1 = this->m_proj_parm.A * log( tan(fourth_pi + .5 * lp_lat) ); 80 t = par.e * sin(lp_lat); 81 V2 = .5 * par.e * this->m_proj_parm.A * log ((1. + t)/(1. - t)); 82 ps = 2. * (atan(exp(V1 - V2 + this->m_proj_parm.C)) - fourth_pi); 83 I1 = ps - this->m_proj_parm.p0s; 84 cosps = cos(ps); cosps2 = cosps * cosps; 85 sinps = sin(ps); sinps2 = sinps * sinps; 86 I4 = this->m_proj_parm.A * cosps; 87 I2 = .5 * this->m_proj_parm.A * I4 * sinps; 88 I3 = I2 * this->m_proj_parm.A * this->m_proj_parm.A * (5. * cosps2 - sinps2) / 12.; 89 I6 = I4 * this->m_proj_parm.A * this->m_proj_parm.A; 90 I5 = I6 * (cosps2 - sinps2) / 6.; 91 I6 *= this->m_proj_parm.A * this->m_proj_parm.A * 92 (5. * cosps2 * cosps2 + sinps2 * (sinps2 - 18. * cosps2)) / 120.; 93 t = lp_lon * lp_lon; 94 xy_x = this->m_proj_parm.kRg * lp_lon * (I4 + t * (I5 + t * I6)); 95 xy_y = this->m_proj_parm.kRg * (I1 + t * (I2 + t * I3)); 96 x2 = xy_x * xy_x; 97 y2 = xy_y * xy_y; 98 V1 = 3. * xy_x * y2 - xy_x * x2; 99 V2 = xy_y * y2 - 3. * x2 * xy_y; 100 xy_x += this->m_proj_parm.Ca * V1 + this->m_proj_parm.Cb * V2; 101 xy_y += this->m_proj_parm.Ca * V2 - this->m_proj_parm.Cb * V1; 102 } 103 104 // INVERSE(e_inverse) ellipsoid & spheroid 105 // Project coordinates from cartesian (x, y) to geographic (lon, lat) invboost::geometry::projections::detail::labrd::base_labrd_ellipsoid106 inline void inv(Parameters const& par, T xy_x, T xy_y, T& lp_lon, T& lp_lat) const 107 { 108 static const T fourth_pi = detail::fourth_pi<T>(); 109 110 /* t = 0.0 optimization is to avoid a false positive cppcheck warning */ 111 /* (cppcheck git beaf29c15867984aa3c2a15cf15bd7576ccde2b3). Might no */ 112 /* longer be necessary with later versions. */ 113 T x2, y2, V1, V2, V3, V4, t = 0.0, t2, ps, pe, tpe, s; 114 T I7, I8, I9, I10, I11, d, Re; 115 int i; 116 117 x2 = xy_x * xy_x; 118 y2 = xy_y * xy_y; 119 V1 = 3. * xy_x * y2 - xy_x * x2; 120 V2 = xy_y * y2 - 3. * x2 * xy_y; 121 V3 = xy_x * (5. * y2 * y2 + x2 * (-10. * y2 + x2 )); 122 V4 = xy_y * (5. * x2 * x2 + y2 * (-10. * x2 + y2 )); 123 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; 124 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; 125 ps = this->m_proj_parm.p0s + xy_y / this->m_proj_parm.kRg; 126 pe = ps + par.phi0 - this->m_proj_parm.p0s; 127 128 for ( i = 20; i; --i) { 129 V1 = this->m_proj_parm.A * log(tan(fourth_pi + .5 * pe)); 130 tpe = par.e * sin(pe); 131 V2 = .5 * par.e * this->m_proj_parm.A * log((1. + tpe)/(1. - tpe)); 132 t = ps - 2. * (atan(exp(V1 - V2 + this->m_proj_parm.C)) - fourth_pi); 133 pe += t; 134 if (fabs(t) < epsilon) 135 break; 136 } 137 138 t = par.e * sin(pe); 139 t = 1. - t * t; 140 Re = par.one_es / ( t * sqrt(t) ); 141 t = tan(ps); 142 t2 = t * t; 143 s = this->m_proj_parm.kRg * this->m_proj_parm.kRg; 144 d = Re * par.k0 * this->m_proj_parm.kRg; 145 I7 = t / (2. * d); 146 I8 = t * (5. + 3. * t2) / (24. * d * s); 147 d = cos(ps) * this->m_proj_parm.kRg * this->m_proj_parm.A; 148 I9 = 1. / d; 149 d *= s; 150 I10 = (1. + 2. * t2) / (6. * d); 151 I11 = (5. + t2 * (28. + 24. * t2)) / (120. * d * s); 152 x2 = xy_x * xy_x; 153 lp_lat = pe + x2 * (-I7 + I8 * x2); 154 lp_lon = xy_x * (I9 + x2 * (-I10 + x2 * I11)); 155 } 156 get_nameboost::geometry::projections::detail::labrd::base_labrd_ellipsoid157 static inline std::string get_name() 158 { 159 return "labrd_ellipsoid"; 160 } 161 162 }; 163 164 // Laborde 165 template <typename Params, typename Parameters, typename T> setup_labrd(Params const & params,Parameters const & par,par_labrd<T> & proj_parm)166 inline void setup_labrd(Params const& params, Parameters const& par, par_labrd<T>& proj_parm) 167 { 168 static const T fourth_pi = detail::fourth_pi<T>(); 169 170 T Az, sinp, R, N, t; 171 172 Az = pj_get_param_r<T, srs::spar::azi>(params, "azi", srs::dpar::azi); 173 sinp = sin(par.phi0); 174 t = 1. - par.es * sinp * sinp; 175 N = 1. / sqrt(t); 176 R = par.one_es * N / t; 177 proj_parm.kRg = par.k0 * sqrt( N * R ); 178 proj_parm.p0s = atan( sqrt(R / N) * tan(par.phi0) ); 179 proj_parm.A = sinp / sin(proj_parm.p0s); 180 t = par.e * sinp; 181 proj_parm.C = .5 * par.e * proj_parm.A * log((1. + t)/(1. - t)) + 182 - proj_parm.A * log( tan(fourth_pi + .5 * par.phi0)) 183 + log( tan(fourth_pi + .5 * proj_parm.p0s)); 184 t = Az + Az; 185 proj_parm.Ca = (1. - cos(t)) * ( proj_parm.Cb = 1. / (12. * proj_parm.kRg * proj_parm.kRg) ); 186 proj_parm.Cb *= sin(t); 187 proj_parm.Cc = 3. * (proj_parm.Ca * proj_parm.Ca - proj_parm.Cb * proj_parm.Cb); 188 proj_parm.Cd = 6. * proj_parm.Ca * proj_parm.Cb; 189 } 190 191 }} // namespace detail::labrd 192 #endif // doxygen 193 194 /*! 195 \brief Laborde projection 196 \ingroup projections 197 \tparam Geographic latlong point type 198 \tparam Cartesian xy point type 199 \tparam Parameters parameter type 200 \par Projection characteristics 201 - Cylindrical 202 - Spheroid 203 - Special for Madagascar 204 \par Projection parameters 205 - no_rot: No rotation (boolean) 206 - azi: Azimuth (or Gamma) (degrees) 207 \par Example 208 \image html ex_labrd.gif 209 */ 210 template <typename T, typename Parameters> 211 struct labrd_ellipsoid : public detail::labrd::base_labrd_ellipsoid<T, Parameters> 212 { 213 template <typename Params> labrd_ellipsoidboost::geometry::projections::labrd_ellipsoid214 inline labrd_ellipsoid(Params const& params, Parameters const& par) 215 { 216 detail::labrd::setup_labrd(params, par, this->m_proj_parm); 217 } 218 }; 219 220 #ifndef DOXYGEN_NO_DETAIL 221 namespace detail 222 { 223 224 // Static projection BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_labrd,labrd_ellipsoid)225 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_labrd, labrd_ellipsoid) 226 227 // Factory entry(s) 228 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(labrd_entry, labrd_ellipsoid) 229 230 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(labrd_init) 231 { 232 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(labrd, labrd_entry) 233 } 234 235 } // namespace detail 236 #endif // doxygen 237 238 } // namespace projections 239 240 }} // namespace boost::geometry 241 242 #endif // BOOST_GEOMETRY_PROJECTIONS_LABRD_HPP 243 244