Debian Codegraph @

gctp/src/ceainv.c

raw
1 /*******************************************************************************
2 NAME Cylinderical Equal Area
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the Cylinderical Equal Area projection.
6 The Easting and Northing must be in meters. The longitude
7 and latitude values will be returned in radians.
8
9
10 PROGRAMMER DATE REASON
11 ---------- ---- ------
12 Abe Taaheri/Emergent Info. Tech., Inc. 6/15/00 Initial version.
13 Abe Taaheri/L3 Comm. Analyrics Corp. 1/15/03 Modified to support both
14 spherical and ellipsoidal
15 models of earth for
16 Cylinderical Equal Area
17 projection to support EASE-Grid
18 and to support EASE-Grid2.
19
20 ALGORITHM REFERENCES
21
22 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
23 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
24 State Government Printing Office, Washington D.C., 1987.
25
26 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
27 U.S. Geological Survey Professional Paper 1453 , United State Government
28 Printing Office, Washington D.C., 1989.
29
30 3. "EASE-Grid 2.0: Incremental but Significant Improvements for Earth-Gridded Data
31 Sets", Mary J. Brodzik ?, Brendan Billingsley, Terry Haran , Bruce Raup and
32 Matthew H.Savoie, National Snow & Ice Data Center, Cooperative Institute of
33 Environmental Sciences, University of Colorado, 449 UCB, Boulder, CO 80309, USA;
34 E-Mails: [email protected] (B.B.); [email protected] (T.H.);
35 [email protected] (B.R.); [email protected] (M.H.S.)
36 *******************************************************************************/
37 #include <stdio.h>
38 #include "cproj.h"
39
40 /* Variables common to all subroutines in this code file
41 -----------------------------------------------------*/
42 static double r_major; /* major axis */
43 static double r_minor; /* minor axis */
44 static double e; /* eccentricity */
45 static double es; /* eccentricity squared */
46 static double e_p4; /* eccentricity's 4th power */
47 static double e_p6; /* eccentricity's 6th power */
48 static double lon_center; /* Center longitude (projection center) */
49 static double lat_truesc; /* latitude of true scale */
50 static double false_northing; /* y offset in meters */
51 static double false_easting; /* x offset in meters */
52 static double cosphi1; /* cos of latitude of true scale */
53 static double sinphi1; /* sin of latitude of true scale */
54 static double kz; /* K_0 for Cylinderical Equal Area proj.*/
55 static double qp; /* qp for Cylinderical Equal Area proj.*/
56 static long ind; /* spherical flag */
57
58 /* Initialize the Cylinderical Equal Area projection
59 -----------------------------------*/
60 int ceainvint(
61 double r_maj, /* major axis */
62 double r_min, /* minor axis */
63 double center_lon, /* center longitude */
64 double center_lat, /* center latitude */
65 double false_east, /* x offset in meters */
66 double false_north) /* y offset in meters */
67 {
68 double temp; /* temporary variable */
69
70 /* Place parameters in static storage for common use
71 -------------------------------------------------*/
72 r_major = r_maj;
73 r_minor = r_min;
74 lon_center = center_lon;
75 lat_truesc = center_lat;
76 false_northing = false_north;
77 false_easting = false_east;
78
79 temp = r_minor / r_major;
80 es = 1.0 - SQUARE(temp);
81 e = sqrt(es);
82 e_p4 = es * es;
83 e_p6 = e_p4 *es;
84
85 if(e < 0.00001)
86 {
87 ind = 1;
88 qp = 2.0;
89 }
90 else
91 {
92 ind = 0;
93 qp = (1.0 - es)*((1.0/(1.0 - es))-(1.0/(2.0*e))*log((1.0 - e)/(1.0 + e)));
94 }
95
96 cosphi1 = cos(lat_truesc);
97 sinphi1 = sin(lat_truesc);
98 kz = cosphi1/(sqrt(1.0 - (es*sinphi1*sinphi1)));
99
100 /* Report parameters to the user
101 -----------------------------*/
102 ptitle("Cylinderical Equal Area");
103 radius2(r_major, r_minor);
104 cenlonmer(lon_center);
105 true_scale(lat_truesc);
106 offsetp(false_easting,false_northing);
107 return(OK);
108 }
109
110
111 /* Cylinderical Equal Area inverse equations--mapping x,y to lat/long
112 --------------------------------------------------*/
113 int ceainv(
114 double x, /* (O) X projection coordinate */
115 double y, /* (O) Y projection coordinate */
116 double *lon, /* (I) Longitude */
117 double *lat) /* (I) Latitude */
118 {
119 double beta;
120
121 /* Inverse equations
122 -----------------*/
123 x -= false_easting;
124 y -= false_northing;
125
126 if( ind != 0) /* sphere */
127 {
128 *lat = asinz( y * cosphi1 / r_major); /*we may need to use asinz dfined in
129 cproj.c instead of asin */
130 *lon = adjust_lon(lon_center + x/(r_major * cosphi1));
131 }
132 else /* ellipsoid */
133 {
134 beta = asinz(2.0 * y * kz/(r_major * qp));
135
136 *lat = beta +(((es / 3.0) + ((31.0/180.0) * e_p4)+
137 ((517.0/5040.0) * e_p6)) * sin(2.0*beta))+
138 ((((23.0/360.0) * e_p4)+
139 ((251.0/3780.0) * e_p6)) * sin(4.0*beta))+
140 (((761.0/45360.0) * e_p6) * sin(6.0*beta));
141 *lon = adjust_lon(lon_center + x/(r_major * kz));
142 }
143
144 return(OK);
145 }