1
#ifndef GGL_PROJECTIONS_VANDG_HPP
2
#define GGL_PROJECTIONS_VANDG_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/math/special_functions/hypot.hpp>
40
#include <ggl/extensions/gis/projections/impl/base_static.hpp>
41
#include <ggl/extensions/gis/projections/impl/base_dynamic.hpp>
42
#include <ggl/extensions/gis/projections/impl/projects.hpp>
43
#include <ggl/extensions/gis/projections/impl/factory_entry.hpp>
45
namespace ggl { namespace projection
47
#ifndef DOXYGEN_NO_DETAIL
48
namespace detail { namespace vandg{
49
static const double TOL = 1.e-10;
50
static const double THIRD = .33333333333333333333;
51
static const double TWO_THRD = .66666666666666666666;
52
static const double C2_27 = .07407407407407407407;
53
static const double PI4_3 = 4.18879020478639098458;
54
static const double PISQ = 9.86960440108935861869;
55
static const double TPISQ = 19.73920880217871723738;
56
static const double HPISQ = 4.93480220054467930934;
59
// template class, using CRTP to implement forward/inverse
60
template <typename Geographic, typename Cartesian, typename Parameters>
61
struct base_vandg_spheroid : public base_t_fi<base_vandg_spheroid<Geographic, Cartesian, Parameters>,
62
Geographic, Cartesian, Parameters>
65
typedef double geographic_type;
66
typedef double cartesian_type;
69
inline base_vandg_spheroid(const Parameters& par)
70
: base_t_fi<base_vandg_spheroid<Geographic, Cartesian, Parameters>,
71
Geographic, Cartesian, Parameters>(*this, par) {}
73
inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
75
double al, al2, g, g2, p2;
77
p2 = fabs(lp_lat / HALFPI);
78
if ((p2 - TOL) > 1.) throw proj_exception();;
81
if (fabs(lp_lat) <= TOL) {
84
} else if (fabs(lp_lon) <= TOL || fabs(p2 - 1.) < TOL) {
86
xy_y = PI * tan(.5 * asin(p2));
87
if (lp_lat < 0.) xy_y = -xy_y;
89
al = .5 * fabs(PI / lp_lon - lp_lon / PI);
91
g = sqrt(1. - p2 * p2);
92
g = g / (p2 + g - 1.);
94
p2 = g * (2. / p2 - 1.);
96
xy_x = g - p2; g = p2 + al2;
97
xy_x = PI * (al * xy_x + sqrt(al2 * xy_x * xy_x - g * (g2 - p2))) / g;
98
if (lp_lon < 0.) xy_x = -xy_x;
99
xy_y = fabs(xy_x / PI);
100
xy_y = 1. - xy_y * (xy_y + 2. * al);
101
if (xy_y < -TOL) throw proj_exception();;
102
if (xy_y < 0.) xy_y = 0.;
103
else xy_y = sqrt(xy_y) * (lp_lat < 0. ? -PI : PI);
107
inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
109
double t, c0, c1, c2, c3, al, r2, r, m, d, ay, x2, y2;
112
if ((ay = fabs(xy_y)) < TOL) {
114
t = x2 * x2 + TPISQ * (x2 + HPISQ);
115
lp_lon = fabs(xy_x) <= TOL ? 0. :
116
.5 * (x2 - PISQ + sqrt(t)) / xy_x;
120
r = x2 + y2; r2 = r * r;
121
c1 = - PI * ay * (r + PISQ);
122
c3 = r2 + TWOPI * (ay * r + PI * (y2 + PI * (ay + HALFPI)));
123
c2 = c1 + PISQ * (r - 3. * y2);
126
al = c1 / c3 - THIRD * c2 * c2;
127
m = 2. * sqrt(-THIRD * al);
128
d = C2_27 * c2 * c2 * c2 + (c0 * c0 - THIRD * c2 * c1) / c3;
129
if (((t = fabs(d = 3. * d / (al * m))) - TOL) <= 1.) {
130
d = t > 1. ? (d > 0. ? 0. : PI) : acos(d);
131
lp_lat = PI * (m * cos(d * THIRD + PI4_3) - THIRD * c2);
132
if (xy_y < 0.) lp_lat = -lp_lat;
133
t = r2 + TPISQ * (x2 - y2 + HPISQ);
134
lp_lon = fabs(xy_x) <= TOL ? 0. :
135
.5 * (r - PISQ + (t <= 0. ? 0. : sqrt(t))) / xy_x;
137
throw proj_exception();;
141
// van der Grinten (I)
142
template <typename Parameters>
143
void setup_vandg(Parameters& par)
146
// par.inv = s_inverse;
147
// par.fwd = s_forward;
150
}} // namespace detail::vandg
154
\brief van der Grinten (I) projection
156
\tparam Geographic latlong point type
157
\tparam Cartesian xy point type
158
\tparam Parameters parameter type
159
\par Projection characteristics
163
\image html ex_vandg.gif
165
template <typename Geographic, typename Cartesian, typename Parameters = parameters>
166
struct vandg_spheroid : public detail::vandg::base_vandg_spheroid<Geographic, Cartesian, Parameters>
168
inline vandg_spheroid(const Parameters& par) : detail::vandg::base_vandg_spheroid<Geographic, Cartesian, Parameters>(par)
170
detail::vandg::setup_vandg(this->m_par);
174
#ifndef DOXYGEN_NO_DETAIL
179
template <typename Geographic, typename Cartesian, typename Parameters>
180
class vandg_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
183
virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
185
return new base_v_fi<vandg_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
189
template <typename Geographic, typename Cartesian, typename Parameters>
190
inline void vandg_init(detail::base_factory<Geographic, Cartesian, Parameters>& factory)
192
factory.add_to_factory("vandg", new vandg_entry<Geographic, Cartesian, Parameters>);
195
} // namespace detail
198
}} // namespace ggl::projection
200
#endif // GGL_PROJECTIONS_VANDG_HPP