File: proj_tmerc.c

package info (click to toggle)
vtk 5.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 130,524 kB
  • sloc: cpp: 1,129,256; ansic: 708,203; tcl: 48,526; python: 20,875; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,788; lex: 931; sh: 660; asm: 471; makefile: 299
file content (185 lines) | stat: -rw-r--r-- 5,809 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
** libproj -- library of cartographic projections
**
** Copyright (c) 2003, 2006   Gerald I. Evenden
*/
static const char
LIBPROJ_ID[] = "Id";
/*
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#define PROJ_PARMS__ \
  double  esp; \
  double  ml0; \
  void  *en;
#define PROJ_LIB__
#include  <lib_proj.h>
PROJ_HEAD(tmerc, "Transverse Mercator") "\n\tCyl, Sph&Ell";
PROJ_HEAD(utm, "Universal Transverse Mercator (UTM)")
  "\n\tCyl, Sph\n\tzone= south";
#define EPS10  1.e-10
#define aks0  P->esp
#define aks5  P->ml0
#define FC1 1.
#define FC2 .5
#define FC3 .16666666666666666666
#define FC4 .08333333333333333333
#define FC5 .05
#define FC6 .03333333333333333333
#define FC7 .02380952380952380952
#define FC8 .01785714285714285714
FORWARD(e_forward); /* ellipse */
  double al, als, n, cosphi, sinphi, t;

  sinphi = sin(lp.phi); cosphi = cos(lp.phi);
  t = fabs(cosphi) > 1e-10 ? sinphi/cosphi : 0.;
  t *= t;
  al = cosphi * lp.lam;
  als = al * al;
  al /= sqrt(1. - P->es * sinphi * sinphi);
  n = P->esp * cosphi * cosphi;
  xy.x = P->k0 * al * (FC1 +
    FC3 * als * (1. - t + n +
    FC5 * als * (5. + t * (t - 18.) + n * (14. - 58. * t +
     n * (13. - 64. * t + n * (4. - 24 * t)))
    + FC7 * als * (61. + t * ( t * (179. - t) - 479. ) )
    )));
  xy.y = P->k0 * (proj_mdist(lp.phi, sinphi, cosphi, P->en) - P->ml0 +
    sinphi * al * lp.lam * FC2 * ( 1. +
    FC4 * als * (5. - t + n * (9. + 4. * n) +
    FC6 * als * (61. + t * (t - 58.) + n * (270. - 330 * t +
     n * (445. - 680. * t + n * (324. - 600. * t + n * (88. - 192. * t))))
    + FC8 * als * (1385. + t * ( t * (543. - t) - 3111.) )
    ))));
  return (xy);
}
FORWARD(s_forward); /* sphere */
  double b, cosphi;

  b = (cosphi = cos(lp.phi)) * sin(lp.lam);
  if (fabs(fabs(b) - 1.) <= EPS10) F_ERROR;
  xy.x = aks5 * log((1. + b) / (1. - b));
  if ((b = fabs( xy.y = cosphi * cos(lp.lam) / sqrt(1. - b * b) )) >= 1.) {
    if ((b - 1.) > EPS10) F_ERROR
    else xy.y = 0.;
  } else
    xy.y = acos(xy.y);
  if (lp.phi < 0.) xy.y = -xy.y;
  xy.y = aks0 * (xy.y - P->phi0);
  return (xy);
}
INVERSE(e_inverse); /* ellipsoid */
  double n, con, cosphi, d, ds, sinphi, t;

  lp.phi = proj_inv_mdist(P->ml0 + xy.y / P->k0, P->en);
  if (fabs(lp.phi) >= HALFPI) {
    lp.phi = xy.y < 0. ? -HALFPI : HALFPI;
    lp.lam = 0.;
  } else {
    sinphi = sin(lp.phi);
    cosphi = cos(lp.phi);
    t = fabs(cosphi) > 1e-10 ? sinphi/cosphi : 0.;
    n = P->esp * cosphi * cosphi;
    d = xy.x * sqrt(con = 1. - P->es * sinphi * sinphi) / P->k0;
    con *= t;
    t *= t;
    ds = d * d;
    lp.phi -= (con * ds / (1.-P->es)) * FC2 * (1. -
      ds * FC4 * (5. + t * (3. - 9. *  n) + n * (1. - 4 * n) -
      ds * FC6*(61. + t*(90. - n*(252. + 90.*t) +
        45.*t) + n*(46. + n*(-3. + t*(-66. + 225.*t) +
        n*(100. + 84.*t + n*(88. - 192.*t))))
       - ds * FC8 * (1385. + t * (3633. + t * (4095. + 1574. * t)) )
      )));
    lp.lam = d*(FC1 -
      ds*FC3*( 1. + 2.*t + n -
      ds*FC5*(5. + t*(28. + 8.*n + 24.*t) + n * (6. + n*(- 3. +
         4.*t + n*(-4. + 24.*t)))
       - ds * FC7 * (61. + t * (662. + t * (1320. + 720. * t)) )
    ))) / cosphi;
  }
  return (lp);
}
INVERSE(s_inverse); /* sphere */
  double D = xy.y / aks0 + P->phi0, xp = xy.x / aks0;

  lp.phi = asin(sin(D) / cosh(xp));
  lp.lam = atan2(sinh(xp), cos(D));
  return (lp);
}
FREEUP;
  if (P) {
    if (P->en)
      free(P->en);
    free(P);
  }
}
  static PROJ *
setup(PROJ *P) { /* general initialization */
  if (P->es) {
    if (!((P->en = proj_mdist_ini(P->es))))
      E_ERROR_0;
    P->ml0 = proj_mdist(P->phi0, sin(P->phi0), cos(P->phi0), P->en);
    P->esp = P->es / (1. - P->es);
    P->inv = e_inverse;
    P->fwd = e_forward;
  } else {
    aks0 = P->k0;
    aks5 = .5 * aks0;
    P->inv = s_inverse;
    P->fwd = s_forward;
  }
  return P;
}
ENTRY1(tmerc, en)
ENDENTRY(setup(P))
ENTRY1(utm, en)
  int zone;

  if (!P->es) E_ERROR(-34);
  P->y0 = proj_param(P->params, "bsouth").i ? 10000000. : 0.;
  P->x0 = 500000.;
  if (proj_param(P->params, "tzone").i) /* zone input ? */
    if ((zone = proj_param(P->params, "izone").i) > 0 && zone <= 60)
      --zone;
    else
      E_ERROR(-35)
  else /* nearest central meridian input */
    if (((zone = (int)floor((proj_adjlon(P->lam0) + PI) * 30. / PI))) < 0)
      zone = 0;
    else if (zone >= 60)
      zone = 59;
  P->lam0 = (zone + .5) * PI / 30. - PI;
  P->k0 = 0.9996;
  P->phi0 = 0.;
ENDENTRY(setup(P))
/*
** Log: proj_tmerc.c
** Revision 3.2  2008/06/28 15:10:58  gie
** Corrected error in inverse.
** Updated precision to comply with USC&GS Sp. Pub. #251 and
** DMA publication DMATM 8358.2.
** Effects of both error correction and precision update are
** only noticeable in the mm range.
**
** Revision 3.1  2006/01/11 01:38:18  gie
** Initial
**
*/