svn-gvsig-desktop / tags / tmp_build_del / libraries / libjni-proj4 / src / pj_ell_set.c @ 38629
History | View | Annotate | Download (3.22 KB)
1 |
/* set ellipsoid parameters a and es */
|
---|---|
2 |
#ifndef lint
|
3 |
static const char SCCSID[]="@(#)pj_ell_set.c 4.5 93/06/12 GIE REL"; |
4 |
#endif
|
5 |
#include <projects.h> |
6 |
#include <string.h> |
7 |
#define SIXTH .1666666666666666667 /* 1/6 */ |
8 |
#define RA4 .04722222222222222222 /* 17/360 */ |
9 |
#define RA6 .02215608465608465608 /* 67/3024 */ |
10 |
#define RV4 .06944444444444444444 /* 5/72 */ |
11 |
#define RV6 .04243827160493827160 /* 55/1296 */ |
12 |
int /* initialize geographic shape parameters */ |
13 |
pj_ell_set(paralist *pl, double *a, double *es) { |
14 |
int i;
|
15 |
double b=0.0, e; |
16 |
char *name;
|
17 |
paralist *start = 0, *curr;
|
18 |
|
19 |
/* check for varying forms of ellipsoid input */
|
20 |
*a = *es = 0.;
|
21 |
/* R takes precedence */
|
22 |
if (pj_param(pl, "tR").i) |
23 |
*a = pj_param(pl, "dR").f;
|
24 |
else { /* probable elliptical figure */ |
25 |
|
26 |
/* check if ellps present and temporarily append its values to pl */
|
27 |
if (name = pj_param(pl, "sellps").s) { |
28 |
char *s;
|
29 |
|
30 |
for (start = pl; start && start->next ; start = start->next) ;
|
31 |
curr = start; |
32 |
for (i = 0; (s = pj_ellps[i].id) && strcmp(name, s) ; ++i) ; |
33 |
if (!s) { pj_errno = -9; return 1; } |
34 |
curr = curr->next = pj_mkparam(pj_ellps[i].major); |
35 |
curr = curr->next = pj_mkparam(pj_ellps[i].ell); |
36 |
} |
37 |
*a = pj_param(pl, "da").f;
|
38 |
if (pj_param(pl, "tes").i) /* eccentricity squared */ |
39 |
*es = pj_param(pl, "des").f;
|
40 |
else if (pj_param(pl, "te").i) { /* eccentricity */ |
41 |
e = pj_param(pl, "de").f;
|
42 |
*es = e * e; |
43 |
} else if (pj_param(pl, "trf").i) { /* recip flattening */ |
44 |
*es = pj_param(pl, "drf").f;
|
45 |
if (!*es) {
|
46 |
pj_errno = -10;
|
47 |
goto bomb;
|
48 |
} |
49 |
*es = 1./ *es;
|
50 |
*es = *es * (2. - *es);
|
51 |
} else if (pj_param(pl, "tf").i) { /* flattening */ |
52 |
*es = pj_param(pl, "df").f;
|
53 |
*es = *es * (2. - *es);
|
54 |
} else if (pj_param(pl, "tb").i) { /* minor axis */ |
55 |
b = pj_param(pl, "db").f;
|
56 |
*es = 1. - (b * b) / (*a * *a);
|
57 |
} /* else *es == 0. and sphere of radius *a */
|
58 |
if (!b)
|
59 |
b = *a * sqrt(1. - *es);
|
60 |
/* following options turn ellipsoid into equivalent sphere */
|
61 |
if (pj_param(pl, "bR_A").i) { /* sphere--area of ellipsoid */ |
62 |
*a *= 1. - *es * (SIXTH + *es * (RA4 + *es * RA6));
|
63 |
*es = 0.;
|
64 |
} else if (pj_param(pl, "bR_V").i) { /* sphere--vol. of ellipsoid */ |
65 |
*a *= 1. - *es * (SIXTH + *es * (RV4 + *es * RV6));
|
66 |
*es = 0.;
|
67 |
} else if (pj_param(pl, "bR_a").i) { /* sphere--arithmetic mean */ |
68 |
*a = .5 * (*a + b);
|
69 |
*es = 0.;
|
70 |
} else if (pj_param(pl, "bR_g").i) { /* sphere--geometric mean */ |
71 |
*a = sqrt(*a * b); |
72 |
*es = 0.;
|
73 |
} else if (pj_param(pl, "bR_h").i) { /* sphere--harmonic mean */ |
74 |
*a = 2. * *a * b / (*a + b);
|
75 |
*es = 0.;
|
76 |
} else if ((i = pj_param(pl, "tR_lat_a").i) || /* sphere--arith. */ |
77 |
pj_param(pl, "tR_lat_g").i) { /* or geom. mean at latitude */ |
78 |
double tmp;
|
79 |
|
80 |
tmp = sin(pj_param(pl, i ? "rR_lat_a" : "rR_lat_g").f); |
81 |
if (fabs(tmp) > HALFPI) {
|
82 |
pj_errno = -11;
|
83 |
goto bomb;
|
84 |
} |
85 |
tmp = 1. - *es * tmp * tmp;
|
86 |
*a *= i ? .5 * (1. - *es + tmp) / ( tmp * sqrt(tmp)) : |
87 |
sqrt(1. - *es) / tmp;
|
88 |
*es = 0.;
|
89 |
} |
90 |
bomb:
|
91 |
if (start) { /* clean up temporary extension of list */ |
92 |
pj_dalloc(start->next->next); |
93 |
pj_dalloc(start->next); |
94 |
start->next = 0;
|
95 |
} |
96 |
if (pj_errno)
|
97 |
return 1; |
98 |
} |
99 |
/* some remaining checks */
|
100 |
if (*es < 0.) |
101 |
{ pj_errno = -12; return 1; } |
102 |
if (*a <= 0.) |
103 |
{ pj_errno = -13; return 1; } |
104 |
return 0; |
105 |
} |