1
#ifndef GGL_PROJECTIONS_GN_SINU_HPP
2
#define GGL_PROJECTIONS_GN_SINU_HPP
4
// Generic Geometry Library - projections (based on PROJ4)
5
// This file is automatically generated. DO NOT EDIT.
7
// Copyright Barend Gehrels (1995-2009), Geodan Holding B.V. Amsterdam, the Netherlands.
8
// Copyright Bruno Lalande (2008-2009)
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)
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 Geometry Library by Barend Gehrels (Geodan, Amsterdam)
18
// Original copyright notice:
20
// Permission is hereby granted, free of charge, to any person obtaining a
21
// copy of this software and associated documentation files (the "Software"),
22
// to deal in the Software without restriction, including without limitation
23
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
24
// and/or sell copies of the Software, and to permit persons to whom the
25
// Software is furnished to do so, subject to the following conditions:
27
// The above copyright notice and this permission notice shall be included
28
// in all copies or substantial portions of the Software.
30
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
33
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
36
// DEALINGS IN THE SOFTWARE.
38
#include <boost/concept_check.hpp>
39
#include <boost/math/special_functions/hypot.hpp>
41
#include <ggl/projections/impl/base_static.hpp>
42
#include <ggl/projections/impl/base_dynamic.hpp>
43
#include <ggl/projections/impl/projects.hpp>
44
#include <ggl/projections/impl/factory_entry.hpp>
45
#include <ggl/projections/impl/pj_mlfn.hpp>
47
namespace ggl { namespace projection
49
#ifndef DOXYGEN_NO_DETAIL
50
namespace detail { namespace gn_sinu{
51
static const double EPS10 = 1e-10;
52
static const int MAX_ITER = 8;
53
static const double LOOP_TOL = 1e-7;
58
double m, n, C_x, C_y;
60
/* Ellipsoidal Sinusoidal only */
62
// template class, using CRTP to implement forward/inverse
63
template <typename Geographic, typename Cartesian, typename Parameters>
64
struct base_gn_sinu_ellipsoid : public base_t_fi<base_gn_sinu_ellipsoid<Geographic, Cartesian, Parameters>,
65
Geographic, Cartesian, Parameters>
68
typedef double geographic_type;
69
typedef double cartesian_type;
71
par_gn_sinu m_proj_parm;
73
inline base_gn_sinu_ellipsoid(const Parameters& par)
74
: base_t_fi<base_gn_sinu_ellipsoid<Geographic, Cartesian, Parameters>,
75
Geographic, Cartesian, Parameters>(*this, par) {}
77
inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
81
xy_y = pj_mlfn(lp_lat, s = sin(lp_lat), c = cos(lp_lat), this->m_proj_parm.en);
82
xy_x = lp_lon * c / sqrt(1. - this->m_par.es * s * s);
85
inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
87
double s; boost::ignore_unused_variable_warning(s);
89
if ((s = fabs(lp_lat = pj_inv_mlfn(xy_y, this->m_par.es, this->m_proj_parm.en))) < HALFPI) {
91
lp_lon = xy_x * sqrt(1. - this->m_par.es * s * s) / cos(lp_lat);
92
} else if ((s - EPS10) < HALFPI)
94
else throw proj_exception();;
97
/* General spherical sinusoidals */
100
// template class, using CRTP to implement forward/inverse
101
template <typename Geographic, typename Cartesian, typename Parameters>
102
struct base_gn_sinu_spheroid : public base_t_fi<base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>,
103
Geographic, Cartesian, Parameters>
106
typedef double geographic_type;
107
typedef double cartesian_type;
109
par_gn_sinu m_proj_parm;
111
inline base_gn_sinu_spheroid(const Parameters& par)
112
: base_t_fi<base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>,
113
Geographic, Cartesian, Parameters>(*this, par) {}
115
inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
117
if (!this->m_proj_parm.m)
118
lp_lat = this->m_proj_parm.n != 1. ? aasin(this->m_proj_parm.n * sin(lp_lat)): lp_lat;
123
k = this->m_proj_parm.n * sin(lp_lat);
124
for (i = MAX_ITER; i ; --i) {
125
lp_lat -= V = (this->m_proj_parm.m * lp_lat + sin(lp_lat) - k) /
126
(this->m_proj_parm.m + cos(lp_lat));
127
if (fabs(V) < LOOP_TOL)
131
throw proj_exception();
133
xy_x = this->m_proj_parm.C_x * lp_lon * (this->m_proj_parm.m + cos(lp_lat));
134
xy_y = this->m_proj_parm.C_y * lp_lat;
137
inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
139
double s; boost::ignore_unused_variable_warning(s);
141
xy_y /= this->m_proj_parm.C_y;
142
lp_lat = this->m_proj_parm.m ? aasin((this->m_proj_parm.m * xy_y + sin(xy_y)) / this->m_proj_parm.n) :
143
( this->m_proj_parm.n != 1. ? aasin(sin(xy_y) / this->m_proj_parm.n) : xy_y );
144
lp_lon = xy_x / (this->m_proj_parm.C_x * (this->m_proj_parm.m + cos(xy_y)));
148
template <typename Parameters>
149
void setup(Parameters& par, par_gn_sinu& proj_parm)
151
boost::ignore_unused_variable_warning(par);
152
boost::ignore_unused_variable_warning(proj_parm);
154
proj_parm.C_x = (proj_parm.C_y = sqrt((proj_parm.m + 1.) / proj_parm.n))/(proj_parm.m + 1.);
155
// par.inv = s_inverse;
156
// par.fwd = s_forward;
160
// General Sinusoidal Series
161
template <typename Parameters>
162
void setup_gn_sinu(Parameters& par, par_gn_sinu& proj_parm)
164
if (pj_param(par.params, "tn").i && pj_param(par.params, "tm").i) {
165
proj_parm.n = pj_param(par.params, "dn").f;
166
proj_parm.m = pj_param(par.params, "dm").f;
168
throw proj_exception(-99);
169
setup(par, proj_parm);
172
// Sinusoidal (Sanson-Flamsteed)
173
template <typename Parameters>
174
void setup_sinu(Parameters& par, par_gn_sinu& proj_parm)
176
pj_enfn(par.es, proj_parm.en);
179
// par.inv = e_inverse;
180
// par.fwd = e_forward;
184
setup(par, proj_parm);
189
template <typename Parameters>
190
void setup_eck6(Parameters& par, par_gn_sinu& proj_parm)
193
proj_parm.n = 2.570796326794896619231321691;
194
setup(par, proj_parm);
197
// McBryde-Thomas Flat-Polar Sinusoidal
198
template <typename Parameters>
199
void setup_mbtfps(Parameters& par, par_gn_sinu& proj_parm)
202
proj_parm.n = 1.785398163397448309615660845;
203
setup(par, proj_parm);
206
}} // namespace detail::gn_sinu
210
\brief Sinusoidal (Sanson-Flamsteed) projection
212
\tparam Geographic latlong point type
213
\tparam Cartesian xy point type
214
\tparam Parameters parameter type
215
\par Projection characteristics
220
\image html ex_sinu.gif
222
template <typename Geographic, typename Cartesian, typename Parameters = parameters>
223
struct sinu_ellipsoid : public detail::gn_sinu::base_gn_sinu_ellipsoid<Geographic, Cartesian, Parameters>
225
inline sinu_ellipsoid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_ellipsoid<Geographic, Cartesian, Parameters>(par)
227
detail::gn_sinu::setup_sinu(this->m_par, this->m_proj_parm);
232
\brief General Sinusoidal Series projection
234
\tparam Geographic latlong point type
235
\tparam Cartesian xy point type
236
\tparam Parameters parameter type
237
\par Projection characteristics
242
\image html ex_gn_sinu.gif
244
template <typename Geographic, typename Cartesian, typename Parameters = parameters>
245
struct gn_sinu_spheroid : public detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>
247
inline gn_sinu_spheroid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>(par)
249
detail::gn_sinu::setup_gn_sinu(this->m_par, this->m_proj_parm);
254
\brief Sinusoidal (Sanson-Flamsteed) projection
256
\tparam Geographic latlong point type
257
\tparam Cartesian xy point type
258
\tparam Parameters parameter type
259
\par Projection characteristics
264
\image html ex_sinu.gif
266
template <typename Geographic, typename Cartesian, typename Parameters = parameters>
267
struct sinu_spheroid : public detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>
269
inline sinu_spheroid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>(par)
271
detail::gn_sinu::setup_sinu(this->m_par, this->m_proj_parm);
276
\brief Eckert VI projection
278
\tparam Geographic latlong point type
279
\tparam Cartesian xy point type
280
\tparam Parameters parameter type
281
\par Projection characteristics
285
\image html ex_eck6.gif
287
template <typename Geographic, typename Cartesian, typename Parameters = parameters>
288
struct eck6_spheroid : public detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>
290
inline eck6_spheroid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>(par)
292
detail::gn_sinu::setup_eck6(this->m_par, this->m_proj_parm);
297
\brief McBryde-Thomas Flat-Polar Sinusoidal projection
299
\tparam Geographic latlong point type
300
\tparam Cartesian xy point type
301
\tparam Parameters parameter type
302
\par Projection characteristics
306
\image html ex_mbtfps.gif
308
template <typename Geographic, typename Cartesian, typename Parameters = parameters>
309
struct mbtfps_spheroid : public detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>
311
inline mbtfps_spheroid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>(par)
313
detail::gn_sinu::setup_mbtfps(this->m_par, this->m_proj_parm);
317
#ifndef DOXYGEN_NO_DETAIL
322
template <typename Geographic, typename Cartesian, typename Parameters>
323
class gn_sinu_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
326
virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
328
return new base_v_fi<gn_sinu_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
332
template <typename Geographic, typename Cartesian, typename Parameters>
333
class sinu_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
336
virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
339
return new base_v_fi<sinu_ellipsoid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
341
return new base_v_fi<sinu_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
345
template <typename Geographic, typename Cartesian, typename Parameters>
346
class eck6_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
349
virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
351
return new base_v_fi<eck6_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
355
template <typename Geographic, typename Cartesian, typename Parameters>
356
class mbtfps_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
359
virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
361
return new base_v_fi<mbtfps_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
365
template <typename Geographic, typename Cartesian, typename Parameters>
366
inline void gn_sinu_init(detail::base_factory<Geographic, Cartesian, Parameters>& factory)
368
factory.add_to_factory("gn_sinu", new gn_sinu_entry<Geographic, Cartesian, Parameters>);
369
factory.add_to_factory("sinu", new sinu_entry<Geographic, Cartesian, Parameters>);
370
factory.add_to_factory("eck6", new eck6_entry<Geographic, Cartesian, Parameters>);
371
factory.add_to_factory("mbtfps", new mbtfps_entry<Geographic, Cartesian, Parameters>);
374
} // namespace detail
377
}} // namespace ggl::projection
379
#endif // GGL_PROJECTIONS_GN_SINU_HPP