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

« back to all changes in this revision

Viewing changes to include/ggl/extensions/gis/projections/proj/omerc.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_OMERC_HPP
2
 
#define GGL_PROJECTIONS_OMERC_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
 
#include <ggl/extensions/gis/projections/impl/pj_tsfn.hpp>
45
 
#include <ggl/extensions/gis/projections/impl/pj_phi2.hpp>
46
 
 
47
 
namespace ggl { namespace projection
48
 
{
49
 
    #ifndef DOXYGEN_NO_DETAIL
50
 
    namespace detail { namespace omerc{ 
51
 
            static const double TOL = 1.e-7;
52
 
            static const double EPS = 1.e-10;
53
 
 
54
 
                inline double TSFN0(double x) 
55
 
                    {return tan(.5 * (HALFPI - (x))); }
56
 
 
57
 
 
58
 
            struct par_omerc
59
 
            {
60
 
                double    alpha, lamc, lam1, phi1, lam2, phi2, Gamma, al, bl, el,
61
 
                singam, cosgam, sinrot, cosrot, u_0;
62
 
                int        ellips, rot;
63
 
            };
64
 
 
65
 
            // template class, using CRTP to implement forward/inverse
66
 
            template <typename Geographic, typename Cartesian, typename Parameters>
67
 
            struct base_omerc_ellipsoid : public base_t_fi<base_omerc_ellipsoid<Geographic, Cartesian, Parameters>,
68
 
                     Geographic, Cartesian, Parameters>
69
 
            {
70
 
 
71
 
                 typedef double geographic_type;
72
 
                 typedef double cartesian_type;
73
 
 
74
 
                par_omerc m_proj_parm;
75
 
 
76
 
                inline base_omerc_ellipsoid(const Parameters& par)
77
 
                    : base_t_fi<base_omerc_ellipsoid<Geographic, Cartesian, Parameters>,
78
 
                     Geographic, Cartesian, Parameters>(*this, par) {}
79
 
 
80
 
                inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
81
 
                {
82
 
                    double  con, q, s, ul, us, vl, vs;
83
 
                
84
 
                    vl = sin(this->m_proj_parm.bl * lp_lon);
85
 
                    if (fabs(fabs(lp_lat) - HALFPI) <= EPS) {
86
 
                        ul = lp_lat < 0. ? -this->m_proj_parm.singam : this->m_proj_parm.singam;
87
 
                        us = this->m_proj_parm.al * lp_lat / this->m_proj_parm.bl;
88
 
                    } else {
89
 
                        q = this->m_proj_parm.el / (this->m_proj_parm.ellips ? pow(pj_tsfn(lp_lat, sin(lp_lat), this->m_par.e), this->m_proj_parm.bl)
90
 
                            : TSFN0(lp_lat));
91
 
                        s = .5 * (q - 1. / q);
92
 
                        ul = 2. * (s * this->m_proj_parm.singam - vl * this->m_proj_parm.cosgam) / (q + 1. / q);
93
 
                        con = cos(this->m_proj_parm.bl * lp_lon);
94
 
                        if (fabs(con) >= TOL) {
95
 
                            us = this->m_proj_parm.al * atan((s * this->m_proj_parm.cosgam + vl * this->m_proj_parm.singam) / con) / this->m_proj_parm.bl;
96
 
                            if (con < 0.)
97
 
                                us += PI * this->m_proj_parm.al / this->m_proj_parm.bl;
98
 
                        } else
99
 
                            us = this->m_proj_parm.al * this->m_proj_parm.bl * lp_lon;
100
 
                    }
101
 
                    if (fabs(fabs(ul) - 1.) <= EPS) throw proj_exception();;
102
 
                    vs = .5 * this->m_proj_parm.al * log((1. - ul) / (1. + ul)) / this->m_proj_parm.bl;
103
 
                    us -= this->m_proj_parm.u_0;
104
 
                    if (! this->m_proj_parm.rot) {
105
 
                        xy_x = us;
106
 
                        xy_y = vs;
107
 
                    } else {
108
 
                        xy_x = vs * this->m_proj_parm.cosrot + us * this->m_proj_parm.sinrot;
109
 
                        xy_y = us * this->m_proj_parm.cosrot - vs * this->m_proj_parm.sinrot;
110
 
                    }
111
 
                }
112
 
 
113
 
                inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
114
 
                {
115
 
                    double  q, s, ul, us, vl, vs;
116
 
                
117
 
                    if (! this->m_proj_parm.rot) {
118
 
                        us = xy_x;
119
 
                        vs = xy_y;
120
 
                    } else {
121
 
                        vs = xy_x * this->m_proj_parm.cosrot - xy_y * this->m_proj_parm.sinrot;
122
 
                        us = xy_y * this->m_proj_parm.cosrot + xy_x * this->m_proj_parm.sinrot;
123
 
                    }
124
 
                    us += this->m_proj_parm.u_0;
125
 
                    q = exp(- this->m_proj_parm.bl * vs / this->m_proj_parm.al);
126
 
                    s = .5 * (q - 1. / q);
127
 
                    vl = sin(this->m_proj_parm.bl * us / this->m_proj_parm.al);
128
 
                    ul = 2. * (vl * this->m_proj_parm.cosgam + s * this->m_proj_parm.singam) / (q + 1. / q);
129
 
                    if (fabs(fabs(ul) - 1.) < EPS) {
130
 
                        lp_lon = 0.;
131
 
                        lp_lat = ul < 0. ? -HALFPI : HALFPI;
132
 
                    } else {
133
 
                        lp_lat = this->m_proj_parm.el / sqrt((1. + ul) / (1. - ul));
134
 
                        if (this->m_proj_parm.ellips) {
135
 
                            if ((lp_lat = pj_phi2(pow(lp_lat, 1. / this->m_proj_parm.bl), this->m_par.e)) == HUGE_VAL)
136
 
                                throw proj_exception();;
137
 
                        } else
138
 
                            lp_lat = HALFPI - 2. * atan(lp_lat);
139
 
                        lp_lon = - atan2((s * this->m_proj_parm.cosgam -
140
 
                            vl * this->m_proj_parm.singam), cos(this->m_proj_parm.bl * us / this->m_proj_parm.al)) / this->m_proj_parm.bl;
141
 
                    }
142
 
                }
143
 
            };
144
 
 
145
 
            // Oblique Mercator
146
 
            template <typename Parameters>
147
 
            void setup_omerc(Parameters& par, par_omerc& proj_parm)
148
 
            {
149
 
                double con, com, cosph0, d, f, h, l, sinph0, p, j;
150
 
                int azi;
151
 
                proj_parm.rot    = pj_param(par.params, "bno_rot").i == 0;
152
 
                if( (azi    = pj_param(par.params, "talpha").i) != 0.0) {
153
 
                    proj_parm.lamc    = pj_param(par.params, "rlonc").f;
154
 
                    proj_parm.alpha    = pj_param(par.params, "ralpha").f;
155
 
                    if ( fabs(proj_parm.alpha) <= TOL ||
156
 
                        fabs(fabs(par.phi0) - HALFPI) <= TOL ||
157
 
                        fabs(fabs(proj_parm.alpha) - HALFPI) <= TOL)
158
 
                        throw proj_exception(-32);
159
 
                } else {
160
 
                    proj_parm.lam1    = pj_param(par.params, "rlon_1").f;
161
 
                    proj_parm.phi1    = pj_param(par.params, "rlat_1").f;
162
 
                    proj_parm.lam2    = pj_param(par.params, "rlon_2").f;
163
 
                    proj_parm.phi2    = pj_param(par.params, "rlat_2").f;
164
 
                    if (fabs(proj_parm.phi1 - proj_parm.phi2) <= TOL ||
165
 
                        (con = fabs(proj_parm.phi1)) <= TOL ||
166
 
                        fabs(con - HALFPI) <= TOL ||
167
 
                        fabs(fabs(par.phi0) - HALFPI) <= TOL ||
168
 
                        fabs(fabs(proj_parm.phi2) - HALFPI) <= TOL) throw proj_exception(-33);
169
 
                }
170
 
                com = (proj_parm.ellips = par.es > 0.) ? sqrt(par.one_es) : 1.;
171
 
                if (fabs(par.phi0) > EPS) {
172
 
                    sinph0 = sin(par.phi0);
173
 
                    cosph0 = cos(par.phi0);
174
 
                    if (proj_parm.ellips) {
175
 
                        con = 1. - par.es * sinph0 * sinph0;
176
 
                        proj_parm.bl = cosph0 * cosph0;
177
 
                        proj_parm.bl = sqrt(1. + par.es * proj_parm.bl * proj_parm.bl / par.one_es);
178
 
                        proj_parm.al = proj_parm.bl * par.k0 * com / con;
179
 
                        d = proj_parm.bl * com / (cosph0 * sqrt(con));
180
 
                    } else {
181
 
                        proj_parm.bl = 1.;
182
 
                        proj_parm.al = par.k0;
183
 
                        d = 1. / cosph0;
184
 
                    }
185
 
                    if ((f = d * d - 1.) <= 0.)
186
 
                        f = 0.;
187
 
                    else {
188
 
                        f = sqrt(f);
189
 
                        if (par.phi0 < 0.)
190
 
                            f = -f;
191
 
                    }
192
 
                    proj_parm.el = f += d;
193
 
                    if (proj_parm.ellips)    proj_parm.el *= pow(pj_tsfn(par.phi0, sinph0, par.e), proj_parm.bl);
194
 
                    else        proj_parm.el *= TSFN0(par.phi0);
195
 
                } else {
196
 
                    proj_parm.bl = 1. / com;
197
 
                    proj_parm.al = par.k0;
198
 
                    proj_parm.el = d = f = 1.;
199
 
                }
200
 
                if (azi) {
201
 
                    proj_parm.Gamma = asin(sin(proj_parm.alpha) / d);
202
 
                    par.lam0 = proj_parm.lamc - asin((.5 * (f - 1. / f)) *
203
 
                       tan(proj_parm.Gamma)) / proj_parm.bl;
204
 
                } else {
205
 
                    if (proj_parm.ellips) {
206
 
                        h = pow(pj_tsfn(proj_parm.phi1, sin(proj_parm.phi1), par.e), proj_parm.bl);
207
 
                        l = pow(pj_tsfn(proj_parm.phi2, sin(proj_parm.phi2), par.e), proj_parm.bl);
208
 
                    } else {
209
 
                        h = TSFN0(proj_parm.phi1);
210
 
                        l = TSFN0(proj_parm.phi2);
211
 
                    }
212
 
                    f = proj_parm.el / h;
213
 
                    p = (l - h) / (l + h);
214
 
                    j = proj_parm.el * proj_parm.el;
215
 
                    j = (j - l * h) / (j + l * h);
216
 
                    if ((con = proj_parm.lam1 - proj_parm.lam2) < -PI)
217
 
                        proj_parm.lam2 -= TWOPI;
218
 
                    else if (con > PI)
219
 
                        proj_parm.lam2 += TWOPI;
220
 
                    par.lam0 = adjlon(.5 * (proj_parm.lam1 + proj_parm.lam2) - atan(
221
 
                       j * tan(.5 * proj_parm.bl * (proj_parm.lam1 - proj_parm.lam2)) / p) / proj_parm.bl);
222
 
                    proj_parm.Gamma = atan(2. * sin(proj_parm.bl * adjlon(proj_parm.lam1 - par.lam0)) /
223
 
                       (f - 1. / f));
224
 
                    proj_parm.alpha = asin(d * sin(proj_parm.Gamma));
225
 
                }
226
 
                proj_parm.singam = sin(proj_parm.Gamma);
227
 
                proj_parm.cosgam = cos(proj_parm.Gamma);
228
 
                f = pj_param(par.params, "brot_conv").i ? proj_parm.Gamma : proj_parm.alpha;
229
 
                proj_parm.sinrot = sin(f);
230
 
                proj_parm.cosrot = cos(f);
231
 
                proj_parm.u_0 = pj_param(par.params, "bno_uoff").i ? 0. :
232
 
                    fabs(proj_parm.al * atan(sqrt(d * d - 1.) / proj_parm.cosrot) / proj_parm.bl);
233
 
                if (par.phi0 < 0.)
234
 
                    proj_parm.u_0 = - proj_parm.u_0;
235
 
                // par.inv = e_inverse;
236
 
                // par.fwd = e_forward;
237
 
            }
238
 
 
239
 
        }} // namespace detail::omerc
240
 
    #endif // doxygen 
241
 
 
242
 
    /*!
243
 
        \brief Oblique Mercator projection
244
 
        \ingroup projections
245
 
        \tparam Geographic latlong point type
246
 
        \tparam Cartesian xy point type
247
 
        \tparam Parameters parameter type
248
 
        \par Projection characteristics
249
 
         - Cylindrical
250
 
         - Spheroid
251
 
         - Ellipsoid
252
 
         - no_rot rot_conv no_uoff and
253
 
         - alpha= lonc= or
254
 
         - lon_1= lat_1= lon_2= lat_2=
255
 
        \par Example
256
 
        \image html ex_omerc.gif
257
 
    */
258
 
    template <typename Geographic, typename Cartesian, typename Parameters = parameters>
259
 
    struct omerc_ellipsoid : public detail::omerc::base_omerc_ellipsoid<Geographic, Cartesian, Parameters>
260
 
    {
261
 
        inline omerc_ellipsoid(const Parameters& par) : detail::omerc::base_omerc_ellipsoid<Geographic, Cartesian, Parameters>(par)
262
 
        {
263
 
            detail::omerc::setup_omerc(this->m_par, this->m_proj_parm);
264
 
        }
265
 
    };
266
 
 
267
 
    #ifndef DOXYGEN_NO_DETAIL
268
 
    namespace detail
269
 
    {
270
 
 
271
 
        // Factory entry(s)
272
 
        template <typename Geographic, typename Cartesian, typename Parameters>
273
 
        class omerc_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
274
 
        {
275
 
            public :
276
 
                virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
277
 
                {
278
 
                    return new base_v_fi<omerc_ellipsoid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
279
 
                }
280
 
        };
281
 
 
282
 
        template <typename Geographic, typename Cartesian, typename Parameters>
283
 
        inline void omerc_init(detail::base_factory<Geographic, Cartesian, Parameters>& factory)
284
 
        {
285
 
            factory.add_to_factory("omerc", new omerc_entry<Geographic, Cartesian, Parameters>);
286
 
        }
287
 
 
288
 
    } // namespace detail 
289
 
    #endif // doxygen
290
 
 
291
 
}} // namespace ggl::projection
292
 
 
293
 
#endif // GGL_PROJECTIONS_OMERC_HPP
294