~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to include/builtin-ggl/ggl/extensions/gis/projections/proj/vandg.hpp

Tags: upstream-0.15.3+svn20934
ImportĀ upstreamĀ versionĀ 0.15.3+svn20934

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef GGL_PROJECTIONS_VANDG_HPP
 
2
#define GGL_PROJECTIONS_VANDG_HPP
 
3
 
 
4
// Generic Geometry Library - projections (based on PROJ4)
 
5
// This file is automatically generated. DO NOT EDIT.
 
6
 
 
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)
 
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 Geometry Library by Barend Gehrels (Geodan, Amsterdam)
 
17
 
 
18
// Original copyright notice:
 
19
 
 
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:
 
26
 
 
27
// The above copyright notice and this permission notice shall be included
 
28
// in all copies or substantial portions of the Software.
 
29
 
 
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.
 
37
 
 
38
#include <boost/math/special_functions/hypot.hpp>
 
39
 
 
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>
 
44
 
 
45
namespace ggl { namespace projection
 
46
{
 
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;
 
57
 
 
58
 
 
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>
 
63
            {
 
64
 
 
65
                 typedef double geographic_type;
 
66
                 typedef double cartesian_type;
 
67
 
 
68
 
 
69
                inline base_vandg_spheroid(const Parameters& par)
 
70
                    : base_t_fi<base_vandg_spheroid<Geographic, Cartesian, Parameters>,
 
71
                     Geographic, Cartesian, Parameters>(*this, par) {}
 
72
 
 
73
                inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
 
74
                {
 
75
                    double  al, al2, g, g2, p2;
 
76
                
 
77
                    p2 = fabs(lp_lat / HALFPI);
 
78
                    if ((p2 - TOL) > 1.) throw proj_exception();;
 
79
                    if (p2 > 1.)
 
80
                        p2 = 1.;
 
81
                    if (fabs(lp_lat) <= TOL) {
 
82
                        xy_x = lp_lon;
 
83
                        xy_y = 0.;
 
84
                    } else if (fabs(lp_lon) <= TOL || fabs(p2 - 1.) < TOL) {
 
85
                        xy_x = 0.;
 
86
                        xy_y = PI * tan(.5 * asin(p2));
 
87
                        if (lp_lat < 0.) xy_y = -xy_y;
 
88
                    } else {
 
89
                        al = .5 * fabs(PI / lp_lon - lp_lon / PI);
 
90
                        al2 = al * al;
 
91
                        g = sqrt(1. - p2 * p2);
 
92
                        g = g / (p2 + g - 1.);
 
93
                        g2 = g * g;
 
94
                        p2 = g * (2. / p2 - 1.);
 
95
                        p2 = p2 * p2;
 
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);
 
104
                    }
 
105
                }
 
106
 
 
107
                inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
 
108
                {
 
109
                    double t, c0, c1, c2, c3, al, r2, r, m, d, ay, x2, y2;
 
110
                
 
111
                    x2 = xy_x * xy_x;
 
112
                    if ((ay = fabs(xy_y)) < TOL) {
 
113
                        lp_lat = 0.;
 
114
                        t = x2 * x2 + TPISQ * (x2 + HPISQ);
 
115
                        lp_lon = fabs(xy_x) <= TOL ? 0. :
 
116
                           .5 * (x2 - PISQ + sqrt(t)) / xy_x;
 
117
                            return;
 
118
                    }
 
119
                    y2 = xy_y * xy_y;
 
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);
 
124
                    c0 = PI * ay;
 
125
                    c2 /= c3;
 
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;
 
136
                    } else
 
137
                        throw proj_exception();;
 
138
                }
 
139
            };
 
140
 
 
141
            // van der Grinten (I)
 
142
            template <typename Parameters>
 
143
            void setup_vandg(Parameters& par)
 
144
            {
 
145
                par.es = 0.;
 
146
                // par.inv = s_inverse;
 
147
                // par.fwd = s_forward;
 
148
            }
 
149
 
 
150
        }} // namespace detail::vandg
 
151
    #endif // doxygen 
 
152
 
 
153
    /*!
 
154
        \brief van der Grinten (I) 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
         - Miscellaneous
 
161
         - Spheroid
 
162
        \par Example
 
163
        \image html ex_vandg.gif
 
164
    */
 
165
    template <typename Geographic, typename Cartesian, typename Parameters = parameters>
 
166
    struct vandg_spheroid : public detail::vandg::base_vandg_spheroid<Geographic, Cartesian, Parameters>
 
167
    {
 
168
        inline vandg_spheroid(const Parameters& par) : detail::vandg::base_vandg_spheroid<Geographic, Cartesian, Parameters>(par)
 
169
        {
 
170
            detail::vandg::setup_vandg(this->m_par);
 
171
        }
 
172
    };
 
173
 
 
174
    #ifndef DOXYGEN_NO_DETAIL
 
175
    namespace detail
 
176
    {
 
177
 
 
178
        // Factory entry(s)
 
179
        template <typename Geographic, typename Cartesian, typename Parameters>
 
180
        class vandg_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
 
181
        {
 
182
            public :
 
183
                virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
 
184
                {
 
185
                    return new base_v_fi<vandg_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
 
186
                }
 
187
        };
 
188
 
 
189
        template <typename Geographic, typename Cartesian, typename Parameters>
 
190
        inline void vandg_init(detail::base_factory<Geographic, Cartesian, Parameters>& factory)
 
191
        {
 
192
            factory.add_to_factory("vandg", new vandg_entry<Geographic, Cartesian, Parameters>);
 
193
        }
 
194
 
 
195
    } // namespace detail 
 
196
    #endif // doxygen
 
197
 
 
198
}} // namespace ggl::projection
 
199
 
 
200
#endif // GGL_PROJECTIONS_VANDG_HPP
 
201