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

« back to all changes in this revision

Viewing changes to include/ggl/extensions/gis/projections/proj/ocea.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_OCEA_HPP
2
 
#define GGL_PROJECTIONS_OCEA_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 ocea{ 
49
 
 
50
 
            struct par_ocea
51
 
            {
52
 
                double    rok;
53
 
                double    rtk;
54
 
                double    sinphi;
55
 
                double    cosphi;
56
 
                double    singam;
57
 
                double    cosgam;
58
 
            };
59
 
 
60
 
            // template class, using CRTP to implement forward/inverse
61
 
            template <typename Geographic, typename Cartesian, typename Parameters>
62
 
            struct base_ocea_spheroid : public base_t_fi<base_ocea_spheroid<Geographic, Cartesian, Parameters>,
63
 
                     Geographic, Cartesian, Parameters>
64
 
            {
65
 
 
66
 
                 typedef double geographic_type;
67
 
                 typedef double cartesian_type;
68
 
 
69
 
                par_ocea m_proj_parm;
70
 
 
71
 
                inline base_ocea_spheroid(const Parameters& par)
72
 
                    : base_t_fi<base_ocea_spheroid<Geographic, Cartesian, Parameters>,
73
 
                     Geographic, Cartesian, Parameters>(*this, par) {}
74
 
 
75
 
                inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
76
 
                {
77
 
                    double t;
78
 
                
79
 
                    xy_y = sin(lp_lon);
80
 
                /*
81
 
                    xy_x = atan2((tan(lp_lat) * this->m_proj_parm.cosphi + this->m_proj_parm.sinphi * xy_y) , cos(lp_lon));
82
 
                */
83
 
                    t = cos(lp_lon);
84
 
                    xy_x = atan((tan(lp_lat) * this->m_proj_parm.cosphi + this->m_proj_parm.sinphi * xy_y) / t);
85
 
                    if (t < 0.)
86
 
                        xy_x += PI;
87
 
                    xy_x *= this->m_proj_parm.rtk;
88
 
                    xy_y = this->m_proj_parm.rok * (this->m_proj_parm.sinphi * sin(lp_lat) - this->m_proj_parm.cosphi * cos(lp_lat) * xy_y);
89
 
                }
90
 
 
91
 
                inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
92
 
                {
93
 
                    double t, s;
94
 
                
95
 
                    xy_y /= this->m_proj_parm.rok;
96
 
                    xy_x /= this->m_proj_parm.rtk;
97
 
                    t = sqrt(1. - xy_y * xy_y);
98
 
                    lp_lat = asin(xy_y * this->m_proj_parm.sinphi + t * this->m_proj_parm.cosphi * (s = sin(xy_x)));
99
 
                    lp_lon = atan2(t * this->m_proj_parm.sinphi * s - xy_y * this->m_proj_parm.cosphi,
100
 
                        t * cos(xy_x));
101
 
                }
102
 
            };
103
 
 
104
 
            // Oblique Cylindrical Equal Area
105
 
            template <typename Parameters>
106
 
            void setup_ocea(Parameters& par, par_ocea& proj_parm)
107
 
            {
108
 
                double phi_0=0.0, phi_1, phi_2, lam_1, lam_2, lonz, alpha;
109
 
                proj_parm.rok = par.a / par.k0;
110
 
                proj_parm.rtk = par.a * par.k0;
111
 
                if ( pj_param(par.params, "talpha").i) {
112
 
                    alpha    = pj_param(par.params, "ralpha").f;
113
 
                    lonz = pj_param(par.params, "rlonc").f;
114
 
                    proj_parm.singam = atan(-cos(alpha)/(-sin(phi_0) * sin(alpha))) + lonz;
115
 
                    proj_parm.sinphi = asin(cos(phi_0) * sin(alpha));
116
 
                } else {
117
 
                    phi_1 = pj_param(par.params, "rlat_1").f;
118
 
                    phi_2 = pj_param(par.params, "rlat_2").f;
119
 
                    lam_1 = pj_param(par.params, "rlon_1").f;
120
 
                    lam_2 = pj_param(par.params, "rlon_2").f;
121
 
                    proj_parm.singam = atan2(cos(phi_1) * sin(phi_2) * cos(lam_1) -
122
 
                        sin(phi_1) * cos(phi_2) * cos(lam_2),
123
 
                        sin(phi_1) * cos(phi_2) * sin(lam_2) -
124
 
                        cos(phi_1) * sin(phi_2) * sin(lam_1) );
125
 
                    proj_parm.sinphi = atan(-cos(proj_parm.singam - lam_1) / tan(phi_1));
126
 
                }
127
 
                par.lam0 = proj_parm.singam + HALFPI;
128
 
                proj_parm.cosphi = cos(proj_parm.sinphi);
129
 
                proj_parm.sinphi = sin(proj_parm.sinphi);
130
 
                proj_parm.cosgam = cos(proj_parm.singam);
131
 
                proj_parm.singam = sin(proj_parm.singam);
132
 
                // par.inv = s_inverse;
133
 
                // par.fwd = s_forward;
134
 
                par.es = 0.;
135
 
            }
136
 
 
137
 
        }} // namespace detail::ocea
138
 
    #endif // doxygen 
139
 
 
140
 
    /*!
141
 
        \brief Oblique Cylindrical Equal Area projection
142
 
        \ingroup projections
143
 
        \tparam Geographic latlong point type
144
 
        \tparam Cartesian xy point type
145
 
        \tparam Parameters parameter type
146
 
        \par Projection characteristics
147
 
         - Cylindrical
148
 
         - Sph lonc= alpha= or
149
 
         - lat_1= lat_2= lon_1= lon_2=
150
 
        \par Example
151
 
        \image html ex_ocea.gif
152
 
    */
153
 
    template <typename Geographic, typename Cartesian, typename Parameters = parameters>
154
 
    struct ocea_spheroid : public detail::ocea::base_ocea_spheroid<Geographic, Cartesian, Parameters>
155
 
    {
156
 
        inline ocea_spheroid(const Parameters& par) : detail::ocea::base_ocea_spheroid<Geographic, Cartesian, Parameters>(par)
157
 
        {
158
 
            detail::ocea::setup_ocea(this->m_par, this->m_proj_parm);
159
 
        }
160
 
    };
161
 
 
162
 
    #ifndef DOXYGEN_NO_DETAIL
163
 
    namespace detail
164
 
    {
165
 
 
166
 
        // Factory entry(s)
167
 
        template <typename Geographic, typename Cartesian, typename Parameters>
168
 
        class ocea_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
169
 
        {
170
 
            public :
171
 
                virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
172
 
                {
173
 
                    return new base_v_fi<ocea_spheroid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
174
 
                }
175
 
        };
176
 
 
177
 
        template <typename Geographic, typename Cartesian, typename Parameters>
178
 
        inline void ocea_init(detail::base_factory<Geographic, Cartesian, Parameters>& factory)
179
 
        {
180
 
            factory.add_to_factory("ocea", new ocea_entry<Geographic, Cartesian, Parameters>);
181
 
        }
182
 
 
183
 
    } // namespace detail 
184
 
    #endif // doxygen
185
 
 
186
 
}} // namespace ggl::projection
187
 
 
188
 
#endif // GGL_PROJECTIONS_OCEA_HPP
189