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

« back to all changes in this revision

Viewing changes to include/ggl/extensions/gis/projections/proj/lcca.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_LCCA_HPP
2
 
#define GGL_PROJECTIONS_LCCA_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_mlfn.hpp>
45
 
 
46
 
namespace ggl { namespace projection
47
 
{
48
 
    #ifndef DOXYGEN_NO_DETAIL
49
 
    namespace detail { namespace lcca{ 
50
 
            static const int MAX_ITER = 10;
51
 
            static const double DEL_TOL = 1e-12;
52
 
 
53
 
            struct par_lcca
54
 
            {
55
 
                double    en[EN_SIZE];
56
 
                double    r0, l, M0;
57
 
                double    C;
58
 
            };
59
 
            
60
 
            
61
 
                inline double /* func to compute dr */
62
 
            fS(double S, double C) {
63
 
                    return(S * ( 1. + S * S * C));
64
 
            }
65
 
                inline double /* deriv of fs */
66
 
            fSp(double S, double C) {
67
 
                return(1. + 3.* S * S * C);
68
 
            }
69
 
 
70
 
            // template class, using CRTP to implement forward/inverse
71
 
            template <typename Geographic, typename Cartesian, typename Parameters>
72
 
            struct base_lcca_ellipsoid : public base_t_fi<base_lcca_ellipsoid<Geographic, Cartesian, Parameters>,
73
 
                     Geographic, Cartesian, Parameters>
74
 
            {
75
 
 
76
 
                 typedef double geographic_type;
77
 
                 typedef double cartesian_type;
78
 
 
79
 
                par_lcca m_proj_parm;
80
 
 
81
 
                inline base_lcca_ellipsoid(const Parameters& par)
82
 
                    : base_t_fi<base_lcca_ellipsoid<Geographic, Cartesian, Parameters>,
83
 
                     Geographic, Cartesian, Parameters>(*this, par) {}
84
 
 
85
 
                inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
86
 
                {
87
 
                    double S, r, dr;
88
 
                    
89
 
                    S = pj_mlfn(lp_lat, sin(lp_lat), cos(lp_lat), this->m_proj_parm.en) - this->m_proj_parm.M0;
90
 
                    dr = fS(S, this->m_proj_parm.C);
91
 
                    r = this->m_proj_parm.r0 - dr;
92
 
                    xy_x = this->m_par.k0 * (r * sin( lp_lon *= this->m_proj_parm.l ) );
93
 
                    xy_y = this->m_par.k0 * (this->m_proj_parm.r0 - r * cos(lp_lon) );
94
 
                }
95
 
 
96
 
                inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
97
 
                {
98
 
                    double theta, dr, S, dif;
99
 
                    int i;
100
 
                
101
 
                    xy_x /= this->m_par.k0;
102
 
                    xy_y /= this->m_par.k0;
103
 
                    theta = atan2(xy_x , this->m_proj_parm.r0 - xy_y);
104
 
                    dr = xy_y - xy_x * tan(0.5 * theta);
105
 
                    lp_lon = theta / this->m_proj_parm.l;
106
 
                    S = dr;
107
 
                    for (i = MAX_ITER; i ; --i) {
108
 
                        S -= (dif = (fS(S, this->m_proj_parm.C) - dr) / fSp(S, this->m_proj_parm.C));
109
 
                        if (fabs(dif) < DEL_TOL) break;
110
 
                    }
111
 
                    if (!i) throw proj_exception();
112
 
                    lp_lat = pj_inv_mlfn(S + this->m_proj_parm.M0, this->m_par.es, this->m_proj_parm.en);
113
 
                }
114
 
            };
115
 
 
116
 
            // Lambert Conformal Conic Alternative
117
 
            template <typename Parameters>
118
 
            void setup_lcca(Parameters& par, par_lcca& proj_parm)
119
 
            {
120
 
                double s2p0, N0, R0, tan0, tan20;
121
 
                    pj_enfn(par.es, proj_parm.en);
122
 
                if (!pj_param(par.params, "tlat_0").i) throw proj_exception(50);
123
 
                if (par.phi0 == 0.) throw proj_exception(51);
124
 
                proj_parm.l = sin(par.phi0);
125
 
                proj_parm.M0 = pj_mlfn(par.phi0, proj_parm.l, cos(par.phi0), proj_parm.en);
126
 
                s2p0 = proj_parm.l * proj_parm.l;
127
 
                R0 = 1. / (1. - par.es * s2p0);
128
 
                N0 = sqrt(R0);
129
 
                R0 *= par.one_es * N0;
130
 
                tan0 = tan(par.phi0);
131
 
                tan20 = tan0 * tan0;
132
 
                proj_parm.r0 = N0 / tan0;
133
 
                proj_parm.C = 1. / (6. * R0 * N0);
134
 
                // par.inv = e_inverse;
135
 
                // par.fwd = e_forward;
136
 
            }
137
 
 
138
 
        }} // namespace detail::lcca
139
 
    #endif // doxygen 
140
 
 
141
 
    /*!
142
 
        \brief Lambert Conformal Conic Alternative projection
143
 
        \ingroup projections
144
 
        \tparam Geographic latlong point type
145
 
        \tparam Cartesian xy point type
146
 
        \tparam Parameters parameter type
147
 
        \par Projection characteristics
148
 
         - Conic
149
 
         - Spheroid
150
 
         - Ellipsoid
151
 
         - lat_0=
152
 
        \par Example
153
 
        \image html ex_lcca.gif
154
 
    */
155
 
    template <typename Geographic, typename Cartesian, typename Parameters = parameters>
156
 
    struct lcca_ellipsoid : public detail::lcca::base_lcca_ellipsoid<Geographic, Cartesian, Parameters>
157
 
    {
158
 
        inline lcca_ellipsoid(const Parameters& par) : detail::lcca::base_lcca_ellipsoid<Geographic, Cartesian, Parameters>(par)
159
 
        {
160
 
            detail::lcca::setup_lcca(this->m_par, this->m_proj_parm);
161
 
        }
162
 
    };
163
 
 
164
 
    #ifndef DOXYGEN_NO_DETAIL
165
 
    namespace detail
166
 
    {
167
 
 
168
 
        // Factory entry(s)
169
 
        template <typename Geographic, typename Cartesian, typename Parameters>
170
 
        class lcca_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
171
 
        {
172
 
            public :
173
 
                virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
174
 
                {
175
 
                    return new base_v_fi<lcca_ellipsoid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
176
 
                }
177
 
        };
178
 
 
179
 
        template <typename Geographic, typename Cartesian, typename Parameters>
180
 
        inline void lcca_init(detail::base_factory<Geographic, Cartesian, Parameters>& factory)
181
 
        {
182
 
            factory.add_to_factory("lcca", new lcca_entry<Geographic, Cartesian, Parameters>);
183
 
        }
184
 
 
185
 
    } // namespace detail 
186
 
    #endif // doxygen
187
 
 
188
 
}} // namespace ggl::projection
189
 
 
190
 
#endif // GGL_PROJECTIONS_LCCA_HPP
191