Debian Codegraph @

include/boost_1_77_0/patches/boost/geometry/srs/projections/proj/tmerc.hpp

raw symbols SCIP
1 // Boost.Geometry - gis-projections (based on PROJ4)
2
3 // Copyright (c) 2008-2015 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2017, 2018, 2019, 2022.
6 // Modifications Copyright (c) 2017, 2026, Oracle and/or its affiliates.
7 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle.
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 // This file is converted from PROJ4, http://trac.osgeo.org/proj
15 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
16 // PROJ4 is maintained by Frank Warmerdam
17 // PROJ4 is converted to Boost.Geometry by Barend Gehrels
18
19 // Last updated version of proj: 8.2.1
20
21 // Original copyright notice:
22
23 // Permission is hereby granted, free of charge, to any person obtaining a
24 // copy of this software and associated documentation files (the "Software"),
25 // to deal in the Software without restriction, including without limitation
26 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
27 // and/or sell copies of the Software, and to permit persons to whom the
28 // Software is furnished to do so, subject to the following conditions:
29
30 // The above copyright notice and this permission notice shall be included
31 // in all copies or substantial portions of the Software.
32
33 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
34 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
36 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
38 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
39 // DEALINGS IN THE SOFTWARE.
40
41 #ifndef BOOST_GEOMETRY_PROJECTIONS_TMERC_HPP
42 #define BOOST_GEOMETRY_PROJECTIONS_TMERC_HPP
43
44 #include <boost/geometry/util/math.hpp>
45
46 #include <boost/geometry/srs/projections/impl/base_static.hpp>
47 #include <boost/geometry/srs/projections/impl/base_dynamic.hpp>
48 #include <boost/geometry/srs/projections/impl/projects.hpp>
49 #include <boost/geometry/srs/projections/impl/factory_entry.hpp>
50 #include <boost/geometry/srs/projections/impl/function_overloads.hpp>
51 #include <boost/geometry/srs/projections/impl/pj_mlfn.hpp>
52
53
54 namespace boost { namespace geometry
55 {
56
57 namespace projections
58 {
59 #ifndef DOXYGEN_NO_DETAIL
60 namespace detail { namespace tmerc
61 {
62
63 static const double epsilon10 = 1.e-10;
64
65 /* Constant for "exact" transverse mercator */
66 static const int proj_etmerc_order = 6;
67
68 template <typename T>
69 inline T FC1() { return 1.; }
70 template <typename T>
71 inline T FC2() { return .5; }
72 template <typename T>
73 inline T FC3() { return .16666666666666666666666666666666666666; }
74 template <typename T>
75 inline T FC4() { return .08333333333333333333333333333333333333; }
76 template <typename T>
77 inline T FC5() { return .05; }
78 template <typename T>
79 inline T FC6() { return .03333333333333333333333333333333333333; }
80 template <typename T>
81 inline T FC7() { return .02380952380952380952380952380952380952; }
82 template <typename T>
83 inline T FC8() { return .01785714285714285714285714285714285714; }
84
85 template <typename T>
86 struct par_tmerc
87 {
88 T esp;
89 T ml0;
90 detail::en<T> en;
91 };
92
93 // More exact: Poder/Engsager
94 template <typename T>
95 struct par_tmerc_exact
96 {
97 T Qn; /* Merid. quad., scaled to the projection */
98 T Zb; /* Radius vector in polar coord. systems */
99 T cgb[6]; /* Constants for Gauss -> Geo lat */
100 T cbg[6]; /* Constants for Geo lat -> Gauss */
101 T utg[6]; /* Constants for transv. merc. -> geo */
102 T gtu[6]; /* Constants for geo -> transv. merc. */
103 };
104
105 template <typename T, typename Parameters>
106 struct base_tmerc_ellipsoid
107 {
108 par_tmerc<T> m_proj_parm;
109
110 // FORWARD(e_forward) ellipse
111 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
112 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
113 {
114 static const T half_pi = detail::half_pi<T>();
115 static const T FC1 = tmerc::FC1<T>();
116 static const T FC2 = tmerc::FC2<T>();
117 static const T FC3 = tmerc::FC3<T>();
118 static const T FC4 = tmerc::FC4<T>();
119 static const T FC5 = tmerc::FC5<T>();
120 static const T FC6 = tmerc::FC6<T>();
121 static const T FC7 = tmerc::FC7<T>();
122 static const T FC8 = tmerc::FC8<T>();
123
124 T al, als, n, cosphi, sinphi, t;
125
126 /*
127 * Fail if our longitude is more than 90 degrees from the
128 * central meridian since the results are essentially garbage.
129 * Is error -20 really an appropriate return value?
130 *
131 * http://trac.osgeo.org/proj/ticket/5
132 */
133 if( lp_lon < -half_pi || lp_lon > half_pi )
134 {
135 xy_x = HUGE_VAL;
136 xy_y = HUGE_VAL;
137 BOOST_THROW_EXCEPTION( projection_exception(error_lat_or_lon_exceed_limit) );
138 return;
139 }
140
141 sinphi = sin(lp_lat);
142 cosphi = cos(lp_lat);
143 t = fabs(cosphi) > 1e-10 ? sinphi/cosphi : 0.;
144 t *= t;
145 al = cosphi * lp_lon;
146 als = al * al;
147 al /= sqrt(1. - par.es * sinphi * sinphi);
148 n = this->m_proj_parm.esp * cosphi * cosphi;
149 xy_x = par.k0 * al * (FC1 +
150 FC3 * als * (1. - t + n +
151 FC5 * als * (5. + t * (t - 18.) + n * (14. - 58. * t)
152 + FC7 * als * (61. + t * ( t * (179. - t) - 479. ) )
153 )));
154 xy_y = par.k0 * (pj_mlfn(lp_lat, sinphi, cosphi, this->m_proj_parm.en) - this->m_proj_parm.ml0 +
155 sinphi * al * lp_lon * FC2 * ( 1. +
156 FC4 * als * (5. - t + n * (9. + 4. * n) +
157 FC6 * als * (61. + t * (t - 58.) + n * (270. - 330 * t)
158 + FC8 * als * (1385. + t * ( t * (543. - t) - 3111.) )
159 ))));
160 }
161
162 // INVERSE(e_inverse) ellipsoid
163 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
164 inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
165 {
166 static const T half_pi = detail::half_pi<T>();
167 static const T FC1 = tmerc::FC1<T>();
168 static const T FC2 = tmerc::FC2<T>();
169 static const T FC3 = tmerc::FC3<T>();
170 static const T FC4 = tmerc::FC4<T>();
171 static const T FC5 = tmerc::FC5<T>();
172 static const T FC6 = tmerc::FC6<T>();
173 static const T FC7 = tmerc::FC7<T>();
174 static const T FC8 = tmerc::FC8<T>();
175
176 T n, con, cosphi, d, ds, sinphi, t;
177
178 lp_lat = pj_inv_mlfn(this->m_proj_parm.ml0 + xy_y / par.k0, par.es, this->m_proj_parm.en);
179 if (fabs(lp_lat) >= half_pi) {
180 lp_lat = xy_y < 0. ? -half_pi : half_pi;
181 lp_lon = 0.;
182 } else {
183 sinphi = sin(lp_lat);
184 cosphi = cos(lp_lat);
185 t = fabs(cosphi) > 1e-10 ? sinphi/cosphi : 0.;
186 n = this->m_proj_parm.esp * cosphi * cosphi;
187 d = xy_x * sqrt(con = 1. - par.es * sinphi * sinphi) / par.k0;
188 con *= t;
189 t *= t;
190 ds = d * d;
191 lp_lat -= (con * ds / (1.-par.es)) * FC2 * (1. -
192 ds * FC4 * (5. + t * (3. - 9. * n) + n * (1. - 4 * n) -
193 ds * FC6 * (61. + t * (90. - 252. * n +
194 45. * t) + 46. * n
195 - ds * FC8 * (1385. + t * (3633. + t * (4095. + 1574. * t)) )
196 )));
197 lp_lon = d*(FC1 -
198 ds*FC3*( 1. + 2.*t + n -
199 ds*FC5*(5. + t*(28. + 24.*t + 8.*n) + 6.*n
200 - ds * FC7 * (61. + t * (662. + t * (1320. + 720. * t)) )
201 ))) / cosphi;
202 }
203 }
204
205 static inline std::string get_name()
206 {
207 return "tmerc_ellipsoid";
208 }
209
210 };
211
212 template <typename T, typename Parameters>
213 struct base_tmerc_ellipsoid_exact
214 {
215 par_tmerc_exact<T> m_proj_parm;
216
217 static inline std::string get_name()
218 {
219 return "tmerc_ellipsoid";
220 }
221
222 /* Helper functions for "exact" transverse mercator */
223 inline
224 static T gatg(const T *p1, int len_p1, T B, T cos_2B, T sin_2B)
225 {
226 T h = 0, h1, h2 = 0;
227
228 const T two_cos_2B = 2*cos_2B;
229 const T* p = p1 + len_p1;
230 h1 = *--p;
231 while (p - p1) {
232 h = -h2 + two_cos_2B*h1 + *--p;
233 h2 = h1;
234 h1 = h;
235 }
236 return (B + h*sin_2B);
237 }
238
239 /* Complex Clenshaw summation */
240 inline
241 static T clenS(const T *a, int size,
242 T sin_arg_r, T cos_arg_r,
243 T sinh_arg_i, T cosh_arg_i,
244 T *R, T *I)
245 {
246 T r, i, hr, hr1, hr2, hi, hi1, hi2;
247
248 /* arguments */
249 const T* p = a + size;
250 r = 2*cos_arg_r*cosh_arg_i;
251 i = -2*sin_arg_r*sinh_arg_i;
252
253 /* summation loop */
254 hi1 = hr1 = hi = 0;
255 hr = *--p;
256 for (; a - p;) {
257 hr2 = hr1;
258 hi2 = hi1;
259 hr1 = hr;
260 hi1 = hi;
261 hr = -hr2 + r*hr1 - i*hi1 + *--p;
262 hi = -hi2 + i*hr1 + r*hi1;
263 }
264
265 r = sin_arg_r*cosh_arg_i;
266 i = cos_arg_r*sinh_arg_i;
267 *R = r*hr - i*hi;
268 *I = r*hi + i*hr;
269 return *R;
270 }
271
272 /* Real Clenshaw summation */
273 static T clens(const T *a, int size, T arg_r)
274 {
275 T r, hr, hr1, hr2, cos_arg_r;
276
277 const T* p = a + size;
278 cos_arg_r = cos(arg_r);
279 r = 2*cos_arg_r;
280
281 /* summation loop */
282 hr1 = 0;
283 hr = *--p;
284 for (; a - p;) {
285 hr2 = hr1;
286 hr1 = hr;
287 hr = -hr2 + r*hr1 + *--p;
288 }
289 return sin(arg_r)*hr;
290 }
291
292 /* Ellipsoidal, forward */
293 //static PJ_XY exact_e_fwd (PJ_LP lp, PJ *P)
294 inline void fwd(Parameters const& par,
295 T const& lp_lon,
296 T const& lp_lat,
297 T& xy_x, T& xy_y) const
298 {
299 //PJ_XY xy = {0.0,0.0};
300 //const auto *Q = &(static_cast<struct tmerc_data*>(par.opaque)->exact);
301
302 /* ell. LAT, LNG -> Gaussian LAT, LNG */
303 T Cn = gatg (this->m_proj_parm.cbg, proj_etmerc_order, lp_lat,
304 cos(2*lp_lat), sin(2*lp_lat));
305 /* Gaussian LAT, LNG -> compl. sph. LAT */
306 const T sin_Cn = sin (Cn);
307 const T cos_Cn = cos (Cn);
308 const T sin_Ce = sin (lp_lon);
309 const T cos_Ce = cos (lp_lon);
310
311 const T cos_Cn_cos_Ce = cos_Cn*cos_Ce;
312 Cn = atan2 (sin_Cn, cos_Cn_cos_Ce);
313
314 const T inv_denom_tan_Ce = 1. / hypot (sin_Cn, cos_Cn_cos_Ce);
315 const T tan_Ce = sin_Ce*cos_Cn * inv_denom_tan_Ce;
316 #if 0
317 // Variant of the above: found not to be measurably faster
318 const T sin_Ce_cos_Cn = sin_Ce*cos_Cn;
319 const T denom = sqrt(1 - sin_Ce_cos_Cn * sin_Ce_cos_Cn);
320 const T tan_Ce = sin_Ce_cos_Cn / denom;
321 #endif
322
323 /* compl. sph. N, E -> ell. norm. N, E */
324 T Ce = asinh ( tan_Ce ); /* Replaces: Ce = log(tan(FORTPI + Ce*0.5)); */
325
326 /*
327 * Non-optimized version:
328 * const T sin_arg_r = sin(2*Cn);
329 * const T cos_arg_r = cos(2*Cn);
330 *
331 * Given:
332 * sin(2 * Cn) = 2 sin(Cn) cos(Cn)
333 * sin(atan(y)) = y / sqrt(1 + y^2)
334 * cos(atan(y)) = 1 / sqrt(1 + y^2)
335 * ==> sin(2 * Cn) = 2 tan_Cn / (1 + tan_Cn^2)
336 *
337 * cos(2 * Cn) = 2cos^2(Cn) - 1
338 * = 2 / (1 + tan_Cn^2) - 1
339 */
340 const T two_inv_denom_tan_Ce = 2 * inv_denom_tan_Ce;
341 const T two_inv_denom_tan_Ce_square = two_inv_denom_tan_Ce * inv_denom_tan_Ce;
342 const T tmp_r = cos_Cn_cos_Ce * two_inv_denom_tan_Ce_square;
343 const T sin_arg_r = sin_Cn * tmp_r;
344 const T cos_arg_r = cos_Cn_cos_Ce * tmp_r - 1;
345
346 /*
347 * Non-optimized version:
348 * const T sinh_arg_i = sinh(2*Ce);
349 * const T cosh_arg_i = cosh(2*Ce);
350 *
351 * Given
352 * sinh(2 * Ce) = 2 sinh(Ce) cosh(Ce)
353 * sinh(asinh(y)) = y
354 * cosh(asinh(y)) = sqrt(1 + y^2)
355 * ==> sinh(2 * Ce) = 2 tan_Ce sqrt(1 + tan_Ce^2)
356 *
357 * cosh(2 * Ce) = 2cosh^2(Ce) - 1
358 * = 2 * (1 + tan_Ce^2) - 1
359 *
360 * and 1+tan_Ce^2 = 1 + sin_Ce^2 * cos_Cn^2 / (sin_Cn^2 + cos_Cn^2 * cos_Ce^2)
361 * = (sin_Cn^2 + cos_Cn^2 * cos_Ce^2 + sin_Ce^2 * cos_Cn^2) / (sin_Cn^2 + cos_Cn^2 * cos_Ce^2)
362 * = 1. / (sin_Cn^2 + cos_Cn^2 * cos_Ce^2)
363 * = inv_denom_tan_Ce^2
364 *
365 */
366 const T sinh_arg_i = tan_Ce * two_inv_denom_tan_Ce;
367 const T cosh_arg_i = two_inv_denom_tan_Ce_square - 1;
368
369 T dCn, dCe;
370 Cn += clenS (this->m_proj_parm.gtu, proj_etmerc_order,
371 sin_arg_r, cos_arg_r, sinh_arg_i, cosh_arg_i,
372 &dCn, &dCe);
373 Ce += dCe;
374 if (fabs (Ce) <= 2.623395162778) {
375 xy_y = this->m_proj_parm.Qn * Cn + this->m_proj_parm.Zb; /* Northing */
376 xy_x = this->m_proj_parm.Qn * Ce; /* Easting */
377 } else {
378 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
379 xy_x = xy_y = HUGE_VAL;
380 }
381 }
382
383
384 /* Ellipsoidal, inverse */
385 inline void inv(Parameters const& par,
386 T const& xy_x,
387 T const& xy_y,
388 T& lp_lon,
389 T& lp_lat) const
390 {
391 //PJ_LP lp = {0.0,0.0};
392 //const auto *Q = &(static_cast<struct tmerc_data*>(par.opaque)->exact);
393
394 /* normalize N, E */
395 T Cn = (xy_y - this->m_proj_parm.Zb)/this->m_proj_parm.Qn;
396 T Ce = xy_x/this->m_proj_parm.Qn;
397
398 if (fabs(Ce) <= 2.623395162778) { /* 150 degrees */
399 /* norm. N, E -> compl. sph. LAT, LNG */
400 const T sin_arg_r = sin(2*Cn);
401 const T cos_arg_r = cos(2*Cn);
402
403 //const T sinh_arg_i = sinh(2*Ce);
404 //const T cosh_arg_i = cosh(2*Ce);
405 const T exp_2_Ce = exp(2*Ce);
406 const T half_inv_exp_2_Ce = 0.5 / exp_2_Ce;
407 const T sinh_arg_i = 0.5 * exp_2_Ce - half_inv_exp_2_Ce;
408 const T cosh_arg_i = 0.5 * exp_2_Ce + half_inv_exp_2_Ce;
409
410 T dCn_ignored, dCe;
411 Cn += clenS(this->m_proj_parm.utg, proj_etmerc_order,
412 sin_arg_r, cos_arg_r, sinh_arg_i, cosh_arg_i,
413 &dCn_ignored, &dCe);
414 Ce += dCe;
415
416 /* compl. sph. LAT -> Gaussian LAT, LNG */
417 const T sin_Cn = sin (Cn);
418 const T cos_Cn = cos (Cn);
419
420 #if 0
421 // Non-optimized version:
422 T sin_Ce, cos_Ce;
423 Ce = atan (sinh (Ce)); // Replaces: Ce = 2*(atan(exp(Ce)) - FORTPI);
424 sin_Ce = sin (Ce);
425 cos_Ce = cos (Ce);
426 Ce = atan2 (sin_Ce, cos_Ce*cos_Cn);
427 Cn = atan2 (sin_Cn*cos_Ce, hypot (sin_Ce, cos_Ce*cos_Cn));
428 #else
429 /*
430 * One can divide both member of Ce = atan2(...) by cos_Ce, which gives:
431 * Ce = atan2 (tan_Ce, cos_Cn) = atan2(sinh(Ce), cos_Cn)
432 *
433 * and the same for Cn = atan2(...)
434 * Cn = atan2 (sin_Cn, hypot (sin_Ce, cos_Ce*cos_Cn)/cos_Ce)
435 * = atan2 (sin_Cn, hypot (sin_Ce/cos_Ce, cos_Cn))
436 * = atan2 (sin_Cn, hypot (tan_Ce, cos_Cn))
437 * = atan2 (sin_Cn, hypot (sinhCe, cos_Cn))
438 */
439 const T sinhCe = sinh (Ce);
440 Ce = atan2 (sinhCe, cos_Cn);
441 const T modulus_Ce = hypot (sinhCe, cos_Cn);
442 Cn = atan2 (sin_Cn, modulus_Ce);
443 #endif
444
445 /* Gaussian LAT, LNG -> ell. LAT, LNG */
446
447 // Optimization of the computation of cos(2*Cn) and sin(2*Cn)
448 const T tmp = 2 * modulus_Ce / (sinhCe * sinhCe + 1);
449 const T sin_2_Cn = sin_Cn * tmp;
450 const T cos_2_Cn = tmp * modulus_Ce - 1.;
451 //const T cos_2_Cn = cos(2 * Cn);
452 //const T sin_2_Cn = sin(2 * Cn);
453
454 lp_lat = gatg (this->m_proj_parm.cgb, proj_etmerc_order, Cn, cos_2_Cn, sin_2_Cn);
455 lp_lon = Ce;
456 }
457 else {
458 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
459 lp_lat = lp_lon = HUGE_VAL;
460 }
461 }
462
463 };
464
465 template <typename T, typename Parameters>
466 struct base_tmerc_spheroid
467 {
468 par_tmerc<T> m_proj_parm;
469
470 // FORWARD(s_forward) sphere
471 // Project coordinates from geographic (lon, lat) to cartesian (x, y)
472 inline void fwd(Parameters const& par, T const& lp_lon, T const& lp_lat, T& xy_x, T& xy_y) const
473 {
474 static const T half_pi = detail::half_pi<T>();
475
476 T b, cosphi;
477
478 /*
479 * Fail if our longitude is more than 90 degrees from the
480 * central meridian since the results are essentially garbage.
481 * Is error -20 really an appropriate return value?
482 *
483 * http://trac.osgeo.org/proj/ticket/5
484 */
485 if( lp_lon < -half_pi || lp_lon > half_pi )
486 {
487 xy_x = HUGE_VAL;
488 xy_y = HUGE_VAL;
489 BOOST_THROW_EXCEPTION( projection_exception(error_lat_or_lon_exceed_limit) );
490 return;
491 }
492
493 cosphi = cos(lp_lat);
494 b = cosphi * sin(lp_lon);
495 if (fabs(fabs(b) - 1.) <= epsilon10)
496 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
497
498 xy_x = this->m_proj_parm.ml0 * log((1. + b) / (1. - b));
499 xy_y = cosphi * cos(lp_lon) / sqrt(1. - b * b);
500
501 b = fabs( xy_y );
502 if (b >= 1.) {
503 if ((b - 1.) > epsilon10)
504 BOOST_THROW_EXCEPTION( projection_exception(error_tolerance_condition) );
505 else xy_y = 0.;
506 } else
507 xy_y = acos(xy_y);
508
509 if (lp_lat < 0.)
510 xy_y = -xy_y;
511 xy_y = this->m_proj_parm.esp * (xy_y - par.phi0);
512 }
513
514 // INVERSE(s_inverse) sphere
515 // Project coordinates from cartesian (x, y) to geographic (lon, lat)
516 inline void inv(Parameters const& par, T const& xy_x, T const& xy_y, T& lp_lon, T& lp_lat) const
517 {
518 T h, g;
519
520 h = exp(xy_x / this->m_proj_parm.esp);
521 g = .5 * (h - 1. / h);
522 h = cos(par.phi0 + xy_y / this->m_proj_parm.esp);
523 lp_lat = asin(sqrt((1. - h * h) / (1. + g * g)));
524
525 /* Make sure that phi is on the correct hemisphere when false northing is used */
526 if (xy_y < 0. && -lp_lat+par.phi0 < 0.0) lp_lat = -lp_lat;
527
528 lp_lon = (g != 0.0 || h != 0.0) ? atan2(g, h) : 0.;
529 }
530
531 static inline std::string get_name()
532 {
533 return "tmerc_spheroid";
534 }
535
536 };
537
538 template <typename Parameters, typename T>
539 inline void setup(Parameters const& par, par_tmerc<T>& proj_parm)
540 {
541 if (par.es != 0.0) {
542 proj_parm.en = pj_enfn<T>(par.es);
543 proj_parm.ml0 = pj_mlfn(par.phi0, sin(par.phi0), cos(par.phi0), proj_parm.en);
544 proj_parm.esp = par.es / (1. - par.es);
545 } else {
546 proj_parm.esp = par.k0;
547 proj_parm.ml0 = .5 * proj_parm.esp;
548 }
549 }
550
551 template <typename Parameters, typename T>
552 inline void setup_exact(Parameters const& par, par_tmerc_exact<T>& proj_parm)
553 {
554 assert( par.es > 0 );
555
556 /* third flattening n */
557 //since we do not keep n in parameters we compute it here;
558 const T n = pow(tan(asin(par.e)/2),2);
559 T np = n;
560
561 /* COEF. OF TRIG SERIES GEO <-> GAUSS */
562 /* cgb := Gaussian -> Geodetic, KW p190 - 191 (61) - (62) */
563 /* cbg := Geodetic -> Gaussian, KW p186 - 187 (51) - (52) */
564 /* PROJ_ETMERC_ORDER = 6th degree : Engsager and Poder: ICC2007 */
565
566 proj_parm.cgb[0] = n*( 2 + n*(-2/3.0 + n*(-2 + n*(116/45.0 + n*(26/45.0 +
567 n*(-2854/675.0 ))))));
568 proj_parm.cbg[0] = n*(-2 + n*( 2/3.0 + n*( 4/3.0 + n*(-82/45.0 + n*(32/45.0 +
569 n*( 4642/4725.0))))));
570 np *= n;
571 proj_parm.cgb[1] = np*(7/3.0 + n*( -8/5.0 + n*(-227/45.0 + n*(2704/315.0 +
572 n*( 2323/945.0)))));
573 proj_parm.cbg[1] = np*(5/3.0 + n*(-16/15.0 + n*( -13/9.0 + n*( 904/315.0 +
574 n*(-1522/945.0)))));
575 np *= n;
576 /* n^5 coeff corrected from 1262/105 -> -1262/105 */
577 proj_parm.cgb[2] = np*( 56/15.0 + n*(-136/35.0 + n*(-1262/105.0 +
578 n*( 73814/2835.0))));
579 proj_parm.cbg[2] = np*(-26/15.0 + n*( 34/21.0 + n*( 8/5.0 +
580 n*(-12686/2835.0))));
581 np *= n;
582 /* n^5 coeff corrected from 322/35 -> 332/35 */
583 proj_parm.cgb[3] = np*(4279/630.0 + n*(-332/35.0 + n*(-399572/14175.0)));
584 proj_parm.cbg[3] = np*(1237/630.0 + n*( -12/5.0 + n*( -24832/14175.0)));
585 np *= n;
586 proj_parm.cgb[4] = np*(4174/315.0 + n*(-144838/6237.0 ));
587 proj_parm.cbg[4] = np*(-734/315.0 + n*( 109598/31185.0));
588 np *= n;
589 proj_parm.cgb[5] = np*(601676/22275.0 );
590 proj_parm.cbg[5] = np*(444337/155925.0);
591
592 /* Constants of the projections */
593 /* Transverse Mercator (UTM, ITM, etc) */
594 np = n*n;
595 /* Norm. mer. quad, K&W p.50 (96), p.19 (38b), p.5 (2) */
596 proj_parm.Qn = par.k0/(1 + n) * (1 + np*(1/4.0 + np*(1/64.0 + np/256.0)));
597 /* coef of trig series */
598 /* utg := ell. N, E -> sph. N, E, KW p194 (65) */
599 /* gtu := sph. N, E -> ell. N, E, KW p196 (69) */
600 proj_parm.utg[0] = n*(-0.5 + n*( 2/3.0 + n*(-37/96.0 + n*( 1/360.0 +
601 n*( 81/512.0 + n*(-96199/604800.0))))));
602 proj_parm.gtu[0] = n*( 0.5 + n*(-2/3.0 + n*( 5/16.0 + n*(41/180.0 +
603 n*(-127/288.0 + n*( 7891/37800.0 ))))));
604 proj_parm.utg[1] = np*(-1/48.0 + n*(-1/15.0 + n*(437/1440.0 + n*(-46/105.0 +
605 n*( 1118711/3870720.0)))));
606 proj_parm.gtu[1] = np*(13/48.0 + n*(-3/5.0 + n*(557/1440.0 + n*(281/630.0 +
607 n*(-1983433/1935360.0)))));
608 np *= n;
609 proj_parm.utg[2] = np*(-17/480.0 + n*( 37/840.0 + n*( 209/4480.0 +
610 n*( -5569/90720.0 ))));
611 proj_parm.gtu[2] = np*( 61/240.0 + n*(-103/140.0 + n*(15061/26880.0 +
612 n*(167603/181440.0))));
613 np *= n;
614 proj_parm.utg[3] = np*(-4397/161280.0 + n*( 11/504.0 + n*( 830251/7257600.0)));
615 proj_parm.gtu[3] = np*(49561/161280.0 + n*(-179/168.0 + n*(6601661/7257600.0)));
616 np *= n;
617 proj_parm.utg[4] = np*(-4583/161280.0 + n*( 108847/3991680.0));
618 proj_parm.gtu[4] = np*(34729/80640.0 + n*(-3418889/1995840.0));
619 np *= n;
620 proj_parm.utg[5] = np*(-20648693/638668800.0);
621 proj_parm.gtu[5] = np*(212378941/319334400.0);
622
623 /* Gaussian latitude value of the origin latitude */
624 const T Z = base_tmerc_ellipsoid_exact<T, Parameters>::gatg (proj_parm.cbg, proj_etmerc_order, par.phi0, cos(2*par.phi0), sin(2*par.phi0));
625
626 /* Origin northing minus true northing at the origin latitude */
627 /* i.e. true northing = N - par.Zb */
628 proj_parm.Zb = - proj_parm.Qn*(Z + base_tmerc_ellipsoid_exact<T, Parameters>::clens(proj_parm.gtu, proj_etmerc_order, 2*Z));
629 }
630
631 }} // namespace detail::tmerc
632 #endif // doxygen
633
634 /*!
635 \brief Transverse Mercator projection
636 \ingroup projections
637 \tparam Geographic latlong point type
638 \tparam Cartesian xy point type
639 \tparam Parameters parameter type
640 \par Projection characteristics
641 - Cylindrical
642 - Spheroid
643 - Ellipsoid
644 \par Example
645 \image html ex_tmerc.gif
646 */
647 //approximate tmerc algorithm
648 /*
649 template <typename T, typename Parameters>
650 struct tmerc_ellipsoid : public detail::tmerc::base_tmerc_ellipsoid<T, Parameters>
651 {
652 template <typename Params>
653 inline tmerc_ellipsoid(Params const&, Parameters const& par)
654 {
655 detail::tmerc::setup(par, this->m_proj_parm);
656 }
657 };
658 */
659 template <typename T, typename Parameters>
660 struct tmerc_ellipsoid : public detail::tmerc::base_tmerc_ellipsoid_exact<T, Parameters>
661 {
662 template <typename Params>
663 inline tmerc_ellipsoid(Params const&, Parameters const& par)
664 {
665 detail::tmerc::setup_exact(par, this->m_proj_parm);
666 }
667 };
668
669 /*!
670 \brief Transverse Mercator projection
671 \ingroup projections
672 \tparam Geographic latlong point type
673 \tparam Cartesian xy point type
674 \tparam Parameters parameter type
675 \par Projection characteristics
676 - Cylindrical
677 - Spheroid
678 - Ellipsoid
679 \par Example
680 \image html ex_tmerc.gif
681 */
682 template <typename T, typename Parameters>
683 struct tmerc_spheroid : public detail::tmerc::base_tmerc_spheroid<T, Parameters>
684 {
685 template <typename Params>
686 inline tmerc_spheroid(Params const&, Parameters const& par)
687 {
688 detail::tmerc::setup(par, this->m_proj_parm);
689 }
690 };
691
692 #ifndef DOXYGEN_NO_DETAIL
693 namespace detail
694 {
695
696 // Static projection
697 BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI2(srs::spar::proj_tmerc, tmerc_spheroid, tmerc_ellipsoid)
698
699 // Factory entry(s) - dynamic projection
700 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_ENTRY_FI2(tmerc_entry, tmerc_spheroid, tmerc_ellipsoid)
701
702 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_BEGIN(tmerc_init)
703 {
704 BOOST_GEOMETRY_PROJECTIONS_DETAIL_FACTORY_INIT_ENTRY(tmerc, tmerc_entry)
705 }
706
707 } // namespace detail
708 #endif // doxygen
709
710 } // namespace projections
711
712 }} // namespace boost::geometry
713
714 #endif // BOOST_GEOMETRY_PROJECTIONS_TMERC_HPP
715