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

« back to all changes in this revision

Viewing changes to include/ggl/projections/proj/gn_sinu.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef GGL_PROJECTIONS_GN_SINU_HPP
 
2
#define GGL_PROJECTIONS_GN_SINU_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/concept_check.hpp>
 
39
#include <boost/math/special_functions/hypot.hpp>
 
40
 
 
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>
 
46
 
 
47
namespace ggl { namespace projection
 
48
{
 
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;
 
54
 
 
55
            struct par_gn_sinu
 
56
            {
 
57
                double en[EN_SIZE];
 
58
                double m, n, C_x, C_y;
 
59
            };
 
60
            /* Ellipsoidal Sinusoidal only */
 
61
 
 
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>
 
66
            {
 
67
 
 
68
                 typedef double geographic_type;
 
69
                 typedef double cartesian_type;
 
70
 
 
71
                par_gn_sinu m_proj_parm;
 
72
 
 
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) {}
 
76
 
 
77
                inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
 
78
                {
 
79
                        double s, c;
 
80
                
 
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);
 
83
                }
 
84
 
 
85
                inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
 
86
                {
 
87
                        double s; boost::ignore_unused_variable_warning(s);
 
88
                
 
89
                        if ((s = fabs(lp_lat = pj_inv_mlfn(xy_y, this->m_par.es, this->m_proj_parm.en))) < HALFPI) {
 
90
                                s = sin(lp_lat);
 
91
                                lp_lon = xy_x * sqrt(1. - this->m_par.es * s * s) / cos(lp_lat);
 
92
                        } else if ((s - EPS10) < HALFPI)
 
93
                                lp_lon = 0.;
 
94
                        else throw proj_exception();;
 
95
                            return;
 
96
                }
 
97
                /* General spherical sinusoidals */
 
98
            };
 
99
 
 
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>
 
104
            {
 
105
 
 
106
                 typedef double geographic_type;
 
107
                 typedef double cartesian_type;
 
108
 
 
109
                par_gn_sinu m_proj_parm;
 
110
 
 
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) {}
 
114
 
 
115
                inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
 
116
                {
 
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;
 
119
                        else {
 
120
                                double k, V;
 
121
                                int i;
 
122
                
 
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)
 
128
                                                break;
 
129
                                }
 
130
                                if (!i)
 
131
                                        throw proj_exception();
 
132
                        }
 
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;
 
135
                }
 
136
 
 
137
                inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
 
138
                {
 
139
                        double s; boost::ignore_unused_variable_warning(s);
 
140
                
 
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)));
 
145
                }
 
146
            };
 
147
 
 
148
            template <typename Parameters>
 
149
            void setup(Parameters& par, par_gn_sinu& proj_parm) 
 
150
            {
 
151
                boost::ignore_unused_variable_warning(par);
 
152
                boost::ignore_unused_variable_warning(proj_parm);
 
153
                par.es = 0;
 
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;
 
157
            }
 
158
 
 
159
 
 
160
            // General Sinusoidal Series
 
161
            template <typename Parameters>
 
162
            void setup_gn_sinu(Parameters& par, par_gn_sinu& proj_parm)
 
163
            {
 
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;
 
167
                } else
 
168
                        throw proj_exception(-99);
 
169
                setup(par, proj_parm);
 
170
            }
 
171
 
 
172
            // Sinusoidal (Sanson-Flamsteed)
 
173
            template <typename Parameters>
 
174
            void setup_sinu(Parameters& par, par_gn_sinu& proj_parm)
 
175
            {
 
176
                    pj_enfn(par.es, proj_parm.en);
 
177
            
 
178
                if (par.es) {
 
179
                // par.inv = e_inverse;
 
180
                // par.fwd = e_forward;
 
181
                } else {
 
182
                        proj_parm.n = 1.;
 
183
                        proj_parm.m = 0.;
 
184
                        setup(par, proj_parm);
 
185
                }
 
186
            }
 
187
 
 
188
            // Eckert VI
 
189
            template <typename Parameters>
 
190
            void setup_eck6(Parameters& par, par_gn_sinu& proj_parm)
 
191
            {
 
192
                proj_parm.m = 1.;
 
193
                proj_parm.n = 2.570796326794896619231321691;
 
194
                setup(par, proj_parm);
 
195
            }
 
196
 
 
197
            // McBryde-Thomas Flat-Polar Sinusoidal
 
198
            template <typename Parameters>
 
199
            void setup_mbtfps(Parameters& par, par_gn_sinu& proj_parm)
 
200
            {
 
201
                proj_parm.m = 0.5;
 
202
                proj_parm.n = 1.785398163397448309615660845;
 
203
                setup(par, proj_parm);
 
204
            }
 
205
 
 
206
        }} // namespace detail::gn_sinu
 
207
    #endif // doxygen 
 
208
 
 
209
    /*!
 
210
        \brief Sinusoidal (Sanson-Flamsteed) 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
         - Pseudocylindrical
 
217
         - Spheroid
 
218
         - Ellipsoid
 
219
        \par Example
 
220
        \image html ex_sinu.gif
 
221
    */
 
222
    template <typename Geographic, typename Cartesian, typename Parameters = parameters>
 
223
    struct sinu_ellipsoid : public detail::gn_sinu::base_gn_sinu_ellipsoid<Geographic, Cartesian, Parameters>
 
224
    {
 
225
        inline sinu_ellipsoid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_ellipsoid<Geographic, Cartesian, Parameters>(par)
 
226
        {
 
227
            detail::gn_sinu::setup_sinu(this->m_par, this->m_proj_parm);
 
228
        }
 
229
    };
 
230
 
 
231
    /*!
 
232
        \brief General Sinusoidal Series projection
 
233
        \ingroup projections
 
234
        \tparam Geographic latlong point type
 
235
        \tparam Cartesian xy point type
 
236
        \tparam Parameters parameter type
 
237
        \par Projection characteristics
 
238
         - Pseudocylindrical
 
239
         - Spheroid
 
240
         - m= n=
 
241
        \par Example
 
242
        \image html ex_gn_sinu.gif
 
243
    */
 
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>
 
246
    {
 
247
        inline gn_sinu_spheroid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>(par)
 
248
        {
 
249
            detail::gn_sinu::setup_gn_sinu(this->m_par, this->m_proj_parm);
 
250
        }
 
251
    };
 
252
 
 
253
    /*!
 
254
        \brief Sinusoidal (Sanson-Flamsteed) projection
 
255
        \ingroup projections
 
256
        \tparam Geographic latlong point type
 
257
        \tparam Cartesian xy point type
 
258
        \tparam Parameters parameter type
 
259
        \par Projection characteristics
 
260
         - Pseudocylindrical
 
261
         - Spheroid
 
262
         - Ellipsoid
 
263
        \par Example
 
264
        \image html ex_sinu.gif
 
265
    */
 
266
    template <typename Geographic, typename Cartesian, typename Parameters = parameters>
 
267
    struct sinu_spheroid : public detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>
 
268
    {
 
269
        inline sinu_spheroid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>(par)
 
270
        {
 
271
            detail::gn_sinu::setup_sinu(this->m_par, this->m_proj_parm);
 
272
        }
 
273
    };
 
274
 
 
275
    /*!
 
276
        \brief Eckert VI projection
 
277
        \ingroup projections
 
278
        \tparam Geographic latlong point type
 
279
        \tparam Cartesian xy point type
 
280
        \tparam Parameters parameter type
 
281
        \par Projection characteristics
 
282
         - Pseudocylindrical
 
283
         - Spheroid
 
284
        \par Example
 
285
        \image html ex_eck6.gif
 
286
    */
 
287
    template <typename Geographic, typename Cartesian, typename Parameters = parameters>
 
288
    struct eck6_spheroid : public detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>
 
289
    {
 
290
        inline eck6_spheroid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>(par)
 
291
        {
 
292
            detail::gn_sinu::setup_eck6(this->m_par, this->m_proj_parm);
 
293
        }
 
294
    };
 
295
 
 
296
    /*!
 
297
        \brief McBryde-Thomas Flat-Polar Sinusoidal projection
 
298
        \ingroup projections
 
299
        \tparam Geographic latlong point type
 
300
        \tparam Cartesian xy point type
 
301
        \tparam Parameters parameter type
 
302
        \par Projection characteristics
 
303
         - Pseudocylindrical
 
304
         - Spheroid
 
305
        \par Example
 
306
        \image html ex_mbtfps.gif
 
307
    */
 
308
    template <typename Geographic, typename Cartesian, typename Parameters = parameters>
 
309
    struct mbtfps_spheroid : public detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>
 
310
    {
 
311
        inline mbtfps_spheroid(const Parameters& par) : detail::gn_sinu::base_gn_sinu_spheroid<Geographic, Cartesian, Parameters>(par)
 
312
        {
 
313
            detail::gn_sinu::setup_mbtfps(this->m_par, this->m_proj_parm);
 
314
        }
 
315
    };
 
316
 
 
317
    #ifndef DOXYGEN_NO_DETAIL
 
318
    namespace detail
 
319
    {
 
320
 
 
321
        // Factory entry(s)
 
322
        template <typename Geographic, typename Cartesian, typename Parameters>
 
323
        class gn_sinu_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
 
324
        {
 
325
            public :
 
326
                virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
 
327
                {
 
328
                    return new base_v_fi<gn_sinu_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
 
329
                }
 
330
        };
 
331
 
 
332
        template <typename Geographic, typename Cartesian, typename Parameters>
 
333
        class sinu_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
 
334
        {
 
335
            public :
 
336
                virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
 
337
                {
 
338
                    if (par.es)
 
339
                        return new base_v_fi<sinu_ellipsoid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
 
340
                    else
 
341
                        return new base_v_fi<sinu_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
 
342
                }
 
343
        };
 
344
 
 
345
        template <typename Geographic, typename Cartesian, typename Parameters>
 
346
        class eck6_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
 
347
        {
 
348
            public :
 
349
                virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
 
350
                {
 
351
                    return new base_v_fi<eck6_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
 
352
                }
 
353
        };
 
354
 
 
355
        template <typename Geographic, typename Cartesian, typename Parameters>
 
356
        class mbtfps_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
 
357
        {
 
358
            public :
 
359
                virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
 
360
                {
 
361
                    return new base_v_fi<mbtfps_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
 
362
                }
 
363
        };
 
364
 
 
365
        template <typename Geographic, typename Cartesian, typename Parameters>
 
366
        inline void gn_sinu_init(detail::base_factory<Geographic, Cartesian, Parameters>& factory)
 
367
        {
 
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>);
 
372
        }
 
373
 
 
374
    } // namespace detail 
 
375
    #endif // doxygen
 
376
 
 
377
}} // namespace ggl::projection
 
378
 
 
379
#endif // GGL_PROJECTIONS_GN_SINU_HPP
 
380