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_STS_HPP 41 #define BOOST_GEOMETRY_PROJECTIONS_STS_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/projects.hpp> 46 #include <boost/geometry/srs/projections/impl/factory_entry.hpp> 47 #include <boost/geometry/srs/projections/impl/aasincos.hpp> 48 49 namespace boost { namespace geometry 50 { 51 52 namespace projections 53 { 54 #ifndef DOXYGEN_NO_DETAIL 55 namespace detail { namespace sts 56 { 57 template <typename T> 58 struct par_sts 59 { 60 T C_x, C_y, C_p; 61 bool tan_mode; 62 }; 63 64 template <typename T, typename Parameters> 65 struct base_sts_spheroid 66 { 67 par_sts<T> m_proj_parm; 68 69 // FORWARD(s_forward) spheroid 70 // Project coordinates from geographic (lon, lat) to cartesian (x, y) fwdboost::geometry::projections::detail::sts::base_sts_spheroid71 inline void fwd(Parameters const& , T const& lp_lon, T lp_lat, T& xy_x, T& xy_y) const 72 { 73 T c; 74 75 xy_x = this->m_proj_parm.C_x * lp_lon * cos(lp_lat); 76 xy_y = this->m_proj_parm.C_y; 77 lp_lat *= this->m_proj_parm.C_p; 78 c = cos(lp_lat); 79 if (this->m_proj_parm.tan_mode) { 80 xy_x *= c * c; 81 xy_y *= tan(lp_lat); 82 } else { 83 xy_x /= c; 84 xy_y *= sin(lp_lat); 85 } 86 } 87 88 // INVERSE(s_inverse) spheroid 89 // Project coordinates from cartesian (x, y) to geographic (lon, lat) invboost::geometry::projections::detail::sts::base_sts_spheroid90 inline void inv(Parameters const& , T const& xy_x, T xy_y, T& lp_lon, T& lp_lat) const 91 { 92 T c; 93 94 xy_y /= this->m_proj_parm.C_y; 95 c = cos(lp_lat = this->m_proj_parm.tan_mode ? atan(xy_y) : aasin(xy_y)); 96 lp_lat /= this->m_proj_parm.C_p; 97 lp_lon = xy_x / (this->m_proj_parm.C_x * cos(lp_lat)); 98 if (this->m_proj_parm.tan_mode) 99 lp_lon /= c * c; 100 else 101 lp_lon *= c; 102 } 103 get_nameboost::geometry::projections::detail::sts::base_sts_spheroid104 static inline std::string get_name() 105 { 106 return "sts_spheroid"; 107 } 108 109 }; 110 111 template <typename Parameters, typename T> setup(Parameters & par,par_sts<T> & proj_parm,T const & p,T const & q,bool mode)112 inline void setup(Parameters& par, par_sts<T>& proj_parm, T const& p, T const& q, bool mode) 113 { 114 par.es = 0.; 115 proj_parm.C_x = q / p; 116 proj_parm.C_y = p; 117 proj_parm.C_p = 1/ q; 118 proj_parm.tan_mode = mode; 119 } 120 121 122 // Foucaut 123 template <typename Parameters, typename T> setup_fouc(Parameters & par,par_sts<T> & proj_parm)124 inline void setup_fouc(Parameters& par, par_sts<T>& proj_parm) 125 { 126 setup(par, proj_parm, 2., 2., true); 127 } 128 129 // Kavraisky V 130 template <typename Parameters, typename T> setup_kav5(Parameters & par,par_sts<T> & proj_parm)131 inline void setup_kav5(Parameters& par, par_sts<T>& proj_parm) 132 { 133 setup(par, proj_parm, 1.50488, 1.35439, false); 134 } 135 136 // Quartic Authalic 137 template <typename Parameters, typename T> setup_qua_aut(Parameters & par,par_sts<T> & proj_parm)138 inline void setup_qua_aut(Parameters& par, par_sts<T>& proj_parm) 139 { 140 setup(par, proj_parm, 2., 2., false); 141 } 142 143 // McBryde-Thomas Flat-Polar Sine (No. 1) 144 template <typename Parameters, typename T> setup_mbt_s(Parameters & par,par_sts<T> & proj_parm)145 inline void setup_mbt_s(Parameters& par, par_sts<T>& proj_parm) 146 { 147 setup(par, proj_parm, 1.48875, 1.36509, false); 148 } 149 150 }} // namespace detail::sts 151 #endif // doxygen 152 153 /*! 154 \brief Kavraisky V projection 155 \ingroup projections 156 \tparam Geographic latlong point type 157 \tparam Cartesian xy point type 158 \tparam Parameters parameter type 159 \par Projection characteristics 160 - Pseudocylindrical 161 - Spheroid 162 \par Example 163 \image html ex_kav5.gif 164 */ 165 template <typename T, typename Parameters> 166 struct kav5_spheroid : public detail::sts::base_sts_spheroid<T, Parameters> 167 { 168 template <typename Params> kav5_spheroidboost::geometry::projections::kav5_spheroid169 inline kav5_spheroid(Params const& , Parameters & par) 170 { 171 detail::sts::setup_kav5(par, this->m_proj_parm); 172 } 173 }; 174 175 /*! 176 \brief Quartic Authalic projection 177 \ingroup projections 178 \tparam Geographic latlong point type 179 \tparam Cartesian xy point type 180 \tparam Parameters parameter type 181 \par Projection characteristics 182 - Pseudocylindrical 183 - Spheroid 184 \par Example 185 \image html ex_qua_aut.gif 186 */ 187 template <typename T, typename Parameters> 188 struct qua_aut_spheroid : public detail::sts::base_sts_spheroid<T, Parameters> 189 { 190 template <typename Params> qua_aut_spheroidboost::geometry::projections::qua_aut_spheroid191 inline qua_aut_spheroid(Params const& , Parameters & par) 192 { 193 detail::sts::setup_qua_aut(par, this->m_proj_parm); 194 } 195 }; 196 197 /*! 198 \brief McBryde-Thomas Flat-Polar Sine (No. 1) projection 199 \ingroup projections 200 \tparam Geographic latlong point type 201 \tparam Cartesian xy point type 202 \tparam Parameters parameter type 203 \par Projection characteristics 204 - Pseudocylindrical 205 - Spheroid 206 \par Example 207 \image html ex_mbt_s.gif 208 */ 209 template <typename T, typename Parameters> 210 struct mbt_s_spheroid : public detail::sts::base_sts_spheroid<T, Parameters> 211 { 212 template <typename Params> mbt_s_spheroidboost::geometry::projections::mbt_s_spheroid213 inline mbt_s_spheroid(Params const& , Parameters & par) 214 { 215 detail::sts::setup_mbt_s(par, this->m_proj_parm); 216 } 217 }; 218 219 /*! 220 \brief Foucaut projection 221 \ingroup projections 222 \tparam Geographic latlong point type 223 \tparam Cartesian xy point type 224 \tparam Parameters parameter type 225 \par Projection characteristics 226 - Pseudocylindrical 227 - Spheroid 228 \par Example 229 \image html ex_fouc.gif 230 */ 231 template <typename T, typename Parameters> 232 struct fouc_spheroid : public detail::sts::base_sts_spheroid<T, Parameters> 233 { 234 template <typename Params> fouc_spheroidboost::geometry::projections::fouc_spheroid235 inline fouc_spheroid(Params const& , Parameters & par) 236 { 237 detail::sts::setup_fouc(par, this->m_proj_parm); 238 } 239 }; 240 241 #ifndef DOXYGEN_NO_DETAIL 242 namespace detail 243 { 244 245 // Static projection BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_kav5,kav5_spheroid)246 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_kav5, kav5_spheroid) 247 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_qua_aut, qua_aut_spheroid) 248 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_mbt_s, mbt_s_spheroid) 249 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(srs::spar::proj_fouc, fouc_spheroid) 250 251 // Factory entry(s) 252 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(kav5_entry, kav5_spheroid) 253 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(qua_aut_entry, qua_aut_spheroid) 254 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(mbt_s_entry, mbt_s_spheroid) 255 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI(fouc_entry, fouc_spheroid) 256 257 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(sts_init) 258 { 259 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(kav5, kav5_entry) 260 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(qua_aut, qua_aut_entry) 261 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(mbt_s, mbt_s_entry) 262 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(fouc, fouc_entry) 263 } 264 265 } // namespace detail 266 #endif // doxygen 267 268 } // namespace projections 269 270 }} // namespace boost::geometry 271 272 #endif // BOOST_GEOMETRY_PROJECTIONS_STS_HPP 273 274