| 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, 2022. |
| 6 |
// Modifications Copyright (c) 2017, 2026, Oracle and/or its affiliates. |
| 7 |
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle. |
| 8 |
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle. |
| 9 |
|
| 10 |
// Use, modification and distribution is subject to the Boost Software License, |
| 11 |
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 12 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 13 |
|
| 14 |
// This file is converted from PROJ4, http://trac.osgeo.org/proj |
| 15 |
// PROJ4 is originally written by Gerald Evenden (then of the USGS) |
| 16 |
// PROJ4 is maintained by Frank Warmerdam |
| 17 |
// PROJ4 is converted to Boost.Geometry by Barend Gehrels |
| 18 |
|
| 19 |
// Last updated version of proj: 9.0.0 |
| 20 |
|
| 21 |
// Original copyright notice: |
| 22 |
|
| 23 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 24 |
// copy of this software and associated documentation files (the "Software"), |
| 25 |
// to deal in the Software without restriction, including without limitation |
| 26 |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 27 |
// and/or sell copies of the Software, and to permit persons to whom the |
| 28 |
// Software is furnished to do so, subject to the following conditions: |
| 29 |
|
| 30 |
// The above copyright notice and this permission notice shall be included |
| 31 |
// in all copies or substantial portions of the Software. |
| 32 |
|
| 33 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 34 |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 35 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 36 |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 37 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 38 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 39 |
// DEALINGS IN THE SOFTWARE. |
| 40 |
|
| 41 |
#ifndef BOOST_GEOMETRY_PROJECTIONS_CASS_HPP |
| 42 |
#define BOOST_GEOMETRY_PROJECTIONS_CASS_HPP |
| 43 |
|
| 44 |
#include <boost/geometry/srs/projections/impl/base_static.hpp> |
| 45 |
#include <boost/geometry/srs/projections/impl/base_dynamic.hpp> |
| 46 |
#include <boost/geometry/srs/projections/impl/projects.hpp> |
| 47 |
#include <boost/geometry/srs/projections/impl/factory_entry.hpp> |
| 48 |
#include <boost/geometry/srs/projections/impl/pj_generic_inverse.hpp> |
| 49 |
#include <boost/geometry/srs/projections/impl/pj_mlfn.hpp> |
| 50 |
|
| 51 |
namespace boost { namespace geometry |
| 52 |
{ |
| 53 |
|
| 54 |
namespace projections |
| 55 |
{ |
| 56 |
#ifndef DOXYGEN_NO_DETAIL |
| 57 |
namespace detail { namespace cass |
| 58 |
{ |
| 59 |
|
| 60 |
//static const double epsilon10 = 1e-10; |
| 61 |
//static const double C1 = .16666666666666666666; |
| 62 |
//static const double C2 = .00833333333333333333; |
| 63 |
//static const double C3 = .04166666666666666666; |
| 64 |
//static const double C4 = .33333333333333333333; |
| 65 |
//static const double C5 = .06666666666666666666; |
| 66 |
|
| 67 |
template <typename T> |
| 68 |
inline T C1() { return .16666666666666666666666666666666666666; } |
| 69 |
template <typename T> |
| 70 |
inline T C2() { return .00833333333333333333333333333333333333; } |
| 71 |
template <typename T> |
| 72 |
inline T C3() { return .04166666666666666666666666666666666666; } |
| 73 |
template <typename T> |
| 74 |
inline T C4() { return .33333333333333333333333333333333333333; } |
| 75 |
template <typename T> |
| 76 |
inline T C5() { return .06666666666666666666666666666666666666; } |
| 77 |
|
| 78 |
template <typename T> |
| 79 |
struct par_cass |
| 80 |
{ |
| 81 |
T m0; |
| 82 |
detail::en<T> en; |
| 83 |
bool hyperbolic; |
| 84 |
}; |
| 85 |
|
| 86 |
template <typename T, typename Parameters> |
| 87 |
struct base_cass_ellipsoid |
| 88 |
{ |
| 89 |
par_cass<T> m_proj_parm; |
| 90 |
|
| 91 |
// FORWARD(e_forward) ellipsoid |
| 92 |
// Project coordinates from geographic (lon, lat) to cartesian (x, y) |
| 93 |
inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, |
| 94 |
T& xy_x, T& xy_y) const |
| 95 |
{ |
| 96 |
static T const C1 = cass::C1<T>(); |
| 97 |
static T const C2 = cass::C2<T>(); |
| 98 |
static T const C3 = cass::C3<T>(); |
| 99 |
|
| 100 |
T sinlplat = sin(lp_lat); |
| 101 |
T c = cos(lp_lat); |
| 102 |
xy_y = pj_mlfn(lp_lat, sinlplat, c, this->m_proj_parm.en); |
| 103 |
T n_square = 1./(1. - par.es * sinlplat * sinlplat); |
| 104 |
T n = sqrt(n_square); |
| 105 |
T tn = tan(lp_lat); |
| 106 |
T t = tn * tn; |
| 107 |
T a1 = lp_lon * c; |
| 108 |
c *= par.es * c / (1 - par.es); |
| 109 |
T a2 = a1 * a1; |
| 110 |
xy_x = n * a1 * (1. - a2 * t * |
| 111 |
(C1 - (8. - t + 8. * c) * a2 * C2)); |
| 112 |
xy_y -= this->m_proj_parm.m0 - n * tn * a2 * |
| 113 |
(.5 + (5. - t + 6. * c) * a2 * C3); |
| 114 |
if ( this->m_proj_parm.hyperbolic ) |
| 115 |
{ |
| 116 |
T const rho = n_square * (1. - par.es) * n; |
| 117 |
xy_y -= xy_y * xy_y * xy_y / (6 * rho * n); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
// INVERSE(e_inverse) ellipsoid |
| 122 |
// Project coordinates from cartesian (x, y) to geographic (lon, lat) |
| 123 |
inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, |
| 124 |
T& lp_lon, T& lp_lat) const |
| 125 |
{ |
| 126 |
static const T C3 = cass::C3<T>(); |
| 127 |
static const T C4 = cass::C4<T>(); |
| 128 |
static const T C5 = cass::C5<T>(); |
| 129 |
|
| 130 |
T ph1; |
| 131 |
|
| 132 |
ph1 = pj_inv_mlfn(this->m_proj_parm.m0 + xy_y, par.es, this->m_proj_parm.en); |
| 133 |
T tn = tan(ph1); T t = tn * tn; |
| 134 |
T n = sin(ph1); |
| 135 |
T r = 1. / (1. - par.es * n * n); |
| 136 |
n = sqrt(r); |
| 137 |
r *= (1. - par.es) * n; |
| 138 |
T dd = xy_x / n; |
| 139 |
T d2 = dd * dd; |
| 140 |
lp_lat = ph1 - (n * tn / r) * d2 * |
| 141 |
(.5 - (1. + 3. * t) * d2 * C3); |
| 142 |
lp_lon = dd * (1. + t * d2 * |
| 143 |
(-C4 + (1. + 3. * t) * d2 * C5)) / cos(ph1); |
| 144 |
if ( this->m_proj_parm.hyperbolic ) |
| 145 |
{ |
| 146 |
// EPSG guidance note 7-2 suggests a custom approximation for the |
| 147 |
// 'Vanua Levu 1915 / Vanua Levu Grid' case, but better use the |
| 148 |
// generic inversion method |
| 149 |
pj_generic_inverse_2d(xy_x, xy_y, par, this, lp_lat, lp_lon); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
static inline std::string get_name() |
| 154 |
{ |
| 155 |
return "cass_ellipsoid"; |
| 156 |
} |
| 157 |
|
| 158 |
}; |
| 159 |
|
| 160 |
template <typename T, typename Parameters> |
| 161 |
struct base_cass_spheroid |
| 162 |
{ |
| 163 |
par_cass<T> m_proj_parm; |
| 164 |
|
| 165 |
// FORWARD(s_forward) spheroid |
| 166 |
// Project coordinates from geographic (lon, lat) to cartesian (x, y) |
| 167 |
inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, |
| 168 |
T& xy_x, T& xy_y) const |
| 169 |
{ |
| 170 |
xy_x = asin(cos(lp_lat) * sin(lp_lon)); |
| 171 |
xy_y = atan2(tan(lp_lat) , cos(lp_lon)) - par.phi0; |
| 172 |
} |
| 173 |
|
| 174 |
// INVERSE(s_inverse) spheroid |
| 175 |
// Project coordinates from cartesian (x, y) to geographic (lon, lat) |
| 176 |
inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, |
| 177 |
T& lp_lon, T& lp_lat) const |
| 178 |
{ |
| 179 |
T dd = xy_y + par.phi0; |
| 180 |
lp_lat = asin(sin(dd) * cos(xy_x)); |
| 181 |
lp_lon = atan2(tan(xy_x), cos(dd)); |
| 182 |
} |
| 183 |
|
| 184 |
static inline std::string get_name() |
| 185 |
{ |
| 186 |
return "cass_spheroid"; |
| 187 |
} |
| 188 |
|
| 189 |
}; |
| 190 |
|
| 191 |
// Cassini |
| 192 |
template <typename Params, typename Parameters, typename T> |
| 193 |
inline void setup_cass(Params const& params, Parameters& par, par_cass<T>& proj_parm) |
| 194 |
{ |
| 195 |
if (par.es) { |
| 196 |
proj_parm.en = pj_enfn<T>(par.es); |
| 197 |
proj_parm.m0 = pj_mlfn(par.phi0, sin(par.phi0), cos(par.phi0), proj_parm.en); |
| 198 |
} else { |
| 199 |
} |
| 200 |
proj_parm.hyperbolic = false; |
| 201 |
if (pj_param_exists<srs::spar::hyperbolic>(params, "hyperbolic", srs::dpar::hyperbolic)) |
| 202 |
proj_parm.hyperbolic = true; |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
}} // namespace detail::cass |
| 207 |
#endif // doxygen |
| 208 |
|
| 209 |
/*! |
| 210 |
\brief Cassini projection |
| 211 |
\ingroup projections |
| 212 |
\tparam Geographic latlong point type |
| 213 |
\tparam Cartesian xy point type |
| 214 |
\tparam Parameters parameter type |
| 215 |
\par Projection characteristics |
| 216 |
- Cylindrical |
| 217 |
- Spheroid |
| 218 |
- Ellipsoid |
| 219 |
\par Example |
| 220 |
\image html ex_cass.gif |
| 221 |
*/ |
| 222 |
template <typename T, typename Parameters> |
| 223 |
struct cass_ellipsoid : public detail::cass::base_cass_ellipsoid<T, Parameters> |
| 224 |
{ |
| 225 |
template <typename Params> |
| 226 |
inline cass_ellipsoid(Params const& params, Parameters const& par) |
| 227 |
{ |
| 228 |
detail::cass::setup_cass(params, par, this->m_proj_parm); |
| 229 |
} |
| 230 |
}; |
| 231 |
|
| 232 |
/*! |
| 233 |
\brief Cassini projection |
| 234 |
\ingroup projections |
| 235 |
\tparam Geographic latlong point type |
| 236 |
\tparam Cartesian xy point type |
| 237 |
\tparam Parameters parameter type |
| 238 |
\par Projection characteristics |
| 239 |
- Cylindrical |
| 240 |
- Spheroid |
| 241 |
- Ellipsoid |
| 242 |
\par Example |
| 243 |
\image html ex_cass.gif |
| 244 |
*/ |
| 245 |
template <typename T, typename Parameters> |
| 246 |
struct cass_spheroid : public detail::cass::base_cass_spheroid<T, Parameters> |
| 247 |
{ |
| 248 |
template <typename Params> |
| 249 |
inline cass_spheroid(Params const& params, Parameters const& par) |
| 250 |
{ |
| 251 |
detail::cass::setup_cass(params, par, this->m_proj_parm); |
| 252 |
} |
| 253 |
}; |
| 254 |
|
| 255 |
#ifndef DOXYGEN_NO_DETAIL |
| 256 |
namespace detail |
| 257 |
{ |
| 258 |
|
| 259 |
// Static projection |
| 260 |
BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI2(srs::spar::proj_cass, cass_spheroid, |
| 261 |
cass_ellipsoid) |
| 262 |
|
| 263 |
// Factory entry(s) |
| 264 |
BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI2(cass_entry, cass_spheroid, cass_ellipsoid) |
| 265 |
|
| 266 |
BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(cass_init) |
| 267 |
{ |
| 268 |
BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(cass, cass_entry); |
| 269 |
} |
| 270 |
|
| 271 |
} // namespace detail |
| 272 |
#endif // doxygen |
| 273 |
|
| 274 |
} // namespace projections |
| 275 |
|
| 276 |
}} // namespace boost::geometry |
| 277 |
|
| 278 |
#endif // BOOST_GEOMETRY_PROJECTIONS_CASS_HPP |
| 279 |
|