1
#ifndef GGL_PROJECTIONS_OMERC_HPP
2
#define GGL_PROJECTIONS_OMERC_HPP
4
// Generic Geometry Library - projections (based on PROJ4)
5
// This file is automatically generated. DO NOT EDIT.
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)
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)
18
// Original copyright notice:
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:
27
// The above copyright notice and this permission notice shall be included
28
// in all copies or substantial portions of the Software.
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.
38
#include <boost/math/special_functions/hypot.hpp>
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>
47
namespace ggl { namespace projection
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;
54
inline double TSFN0(double x)
55
{return tan(.5 * (HALFPI - (x))); }
60
double alpha, lamc, lam1, phi1, lam2, phi2, Gamma, al, bl, el,
61
singam, cosgam, sinrot, cosrot, u_0;
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>
71
typedef double geographic_type;
72
typedef double cartesian_type;
74
par_omerc m_proj_parm;
76
inline base_omerc_ellipsoid(const Parameters& par)
77
: base_t_fi<base_omerc_ellipsoid<Geographic, Cartesian, Parameters>,
78
Geographic, Cartesian, Parameters>(*this, par) {}
80
inline void fwd(geographic_type& lp_lon, geographic_type& lp_lat, cartesian_type& xy_x, cartesian_type& xy_y) const
82
double con, q, s, ul, us, vl, vs;
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;
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)
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;
97
us += PI * this->m_proj_parm.al / this->m_proj_parm.bl;
99
us = this->m_proj_parm.al * this->m_proj_parm.bl * lp_lon;
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) {
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;
113
inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
115
double q, s, ul, us, vl, vs;
117
if (! this->m_proj_parm.rot) {
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;
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) {
131
lp_lat = ul < 0. ? -HALFPI : HALFPI;
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();;
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;
146
template <typename Parameters>
147
void setup_omerc(Parameters& par, par_omerc& proj_parm)
149
double con, com, cosph0, d, f, h, l, sinph0, p, j;
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);
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);
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));
182
proj_parm.al = par.k0;
185
if ((f = d * d - 1.) <= 0.)
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);
196
proj_parm.bl = 1. / com;
197
proj_parm.al = par.k0;
198
proj_parm.el = d = f = 1.;
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;
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);
209
h = TSFN0(proj_parm.phi1);
210
l = TSFN0(proj_parm.phi2);
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;
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)) /
224
proj_parm.alpha = asin(d * sin(proj_parm.Gamma));
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);
234
proj_parm.u_0 = - proj_parm.u_0;
235
// par.inv = e_inverse;
236
// par.fwd = e_forward;
239
}} // namespace detail::omerc
243
\brief Oblique Mercator projection
245
\tparam Geographic latlong point type
246
\tparam Cartesian xy point type
247
\tparam Parameters parameter type
248
\par Projection characteristics
252
- no_rot rot_conv no_uoff and
254
- lon_1= lat_1= lon_2= lat_2=
256
\image html ex_omerc.gif
258
template <typename Geographic, typename Cartesian, typename Parameters = parameters>
259
struct omerc_ellipsoid : public detail::omerc::base_omerc_ellipsoid<Geographic, Cartesian, Parameters>
261
inline omerc_ellipsoid(const Parameters& par) : detail::omerc::base_omerc_ellipsoid<Geographic, Cartesian, Parameters>(par)
263
detail::omerc::setup_omerc(this->m_par, this->m_proj_parm);
267
#ifndef DOXYGEN_NO_DETAIL
272
template <typename Geographic, typename Cartesian, typename Parameters>
273
class omerc_entry : public detail::factory_entry<Geographic, Cartesian, Parameters>
276
virtual projection<Geographic, Cartesian>* create_new(const Parameters& par) const
278
return new base_v_fi<omerc_ellipsoid<Geographic, Cartesian, Parameters>, Geographic, Cartesian, Parameters>(par);
282
template <typename Geographic, typename Cartesian, typename Parameters>
283
inline void omerc_init(detail::base_factory<Geographic, Cartesian, Parameters>& factory)
285
factory.add_to_factory("omerc", new omerc_entry<Geographic, Cartesian, Parameters>);
288
} // namespace detail
291
}} // namespace ggl::projection
293
#endif // GGL_PROJECTIONS_OMERC_HPP