Debian Codegraph @

gctp/src/lamazfor.c

raw
1 /*******************************************************************************
2 NAME LAMBERT AZIMUTHAL EQUAL-AREA
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Lambert Azimuthal Equal-Area projection. The
6 longitude and latitude must be in radians. The Easting
7 and Northing values will be returned in meters.
8
9 PROGRAMMER DATE REASON
10 ---------- ---- ------
11 D. Steinwand, EROS March, 1991
12 Abe Taaheri/Raytheon IIS Nov, 2013 Modified to support both
13 spherical and ellipsoidal
14 models of earth for
15 Lambert Azimuthal Equal Area
16 projection to support EASE-Grid2
17
18 This function was adapted from the Lambert Azimuthal Equal Area projection
19 code (FORTRAN) in the General Cartographic Transformation Package software
20 which is available from the U.S. Geological Survey National Mapping Division.
21
22 ALGORITHM REFERENCES
23
24 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
25 The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
26
27 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
28 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
29 State Government Printing Office, Washington D.C., 1987.
30
31 3. "Software Documentation for GCTP General Cartographic Transformation
32 Package", U.S. Geological Survey National Mapping Division, May 1982.
33
34 4. "EASE-Grid 2.0: Incremental but Significant Improvements for Earth-Gridded Data
35 Sets", Mary J. Brodzik ?, Brendan Billingsley, Terry Haran , Bruce Raup and
36 Matthew H.Savoie, National Snow & Ice Data Center, Cooperative Institute of
37 Environmental Sciences, University of Colorado, 449 UCB, Boulder, CO 80309, USA;
38 E-Mails: [email protected] (B.B.); [email protected] (T.H.);
39 [email protected] (B.R.); [email protected] (M.H.S.)
40 *******************************************************************************/
41 #include <stdio.h>
42 #include "cproj.h"
43
44 /* Variables common to all subroutines in this code file
45 -----------------------------------------------------*/
46 static double r_major; /* major axis */
47 static double r_minor; /* minor axis */
48 static double lon_center; /* Center longitude (projection center) */
49 static double lat_center; /* Center latitude (projection center) */
50 static double R; /* Radius of the earth (sphere) */
51 static double sin_lat_o; /* Sine of the center latitude */
52 static double cos_lat_o; /* Cosine of the center latitude */
53 static double sinphi1; /* Sine of the center latitude */
54 static double cosphi1; /* Cosine of the center latitude */
55 static double false_easting; /* x offset in meters */
56 static double false_northing; /* y offset in meters */
57 static double qp; /* q at 90 degrees. */
58 static double q1; /* q at lat_center degrees */
59 static double beta1, m1, Rq, D;
60 static double sin_beta1;
61 static double cos_beta1;
62 static long ind; /* spherical flag */
63 static double e, es; /* eccentricity constants */
64
65 /* Initialize the General Lambert Azimuthal Equal Area projection
66 --------------------------------------------------------------*/
67 int lamazforint(
68 double r_maj, /* major axis */
69 double r_min, /* minor axis */
70 double center_long, /* (I) Center longitude */
71 double center_lat, /* (I) Center latitude */
72 double false_east, /* x offset in meters */
73 double false_north) /* y offset in meters */
74 {
75 /* Place parameters in static storage for common use
76 -------------------------------------------------*/
77 R = r_maj;
78 if(fabs(r_min) < EPSLN ) /* sphere */
79 {
80 r_major = r_maj;
81 r_minor = r_maj;
82 }
83 else /* sphere or ellipsoide */
84 {
85 r_major = r_maj;
86 r_minor = r_min;
87 }
88
89 lon_center = center_long;
90 lat_center = center_lat;
91 false_easting = false_east;
92 false_northing = false_north;
93 tsincos(center_lat, &sin_lat_o, &cos_lat_o);
94 sinphi1 = sin_lat_o;
95 cosphi1 = cos_lat_o;
96
97 es = 1.0 - SQUARE(r_minor / r_major);
98 e = sqrt(es);
99
100 if(es < 0.00001)
101 {
102 ind = 1; /* sphere */
103 qp = 2.0;
104 q1 = 2.0;
105 }
106 else
107 {
108 ind = 0; /* ellipsoid */
109 qp = (1.0 - es)* (((1.0/(1.0 - es))-(1.0/(2.0*e))*log((1.0 - e)/(1.0 + e))));
110
111 if((fabs (lat_center - HALF_PI) <= EPSLN ) || (fabs (lat_center + HALF_PI) <= EPSLN ))
112 {
113 /* no other constants needed for LA with North and South polar Aspects lat_center = 90 or -90*/
114 }
115 else
116 {
117 tsincos(lat_center, &sinphi1, &cosphi1);
118 q1 = (1.0 - es) * ((sinphi1 / (1.0 - es * sinphi1 * sinphi1))
119 - (1.0 / (2.0 * e)) *
120 log((1.0 - e * sinphi1)/(1.0 + e * sinphi1)));
121 Rq = r_major * sqrt(qp/2.0);
122 if(fabs(q1) >= fabs(qp))
123 {
124 beta1 = HALF_PI * (fabs(q1/qp)/(q1/qp));
125 }
126 else
127 {
128 beta1 = asinz(q1/qp);
129 }
130 tsincos(beta1, &sin_beta1, &cos_beta1);
131 m1 = cosphi1 / sqrt(1.0 - es * sinphi1 * sinphi1);
132 D = (r_major * m1)/ (Rq * cos_beta1);
133 }
134 }
135
136 /* Report parameters to the user
137 -----------------------------*/
138 ptitle("LAMBERT AZIMUTHAL EQUAL-AREA");
139 radius2(r_major, r_minor);
140 cenlon(center_long);
141 cenlat(center_lat);
142 offsetp(false_easting,false_northing);
143 return(OK);
144 }
145
146 /* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
147 -----------------------------------------------------------------------*/
148 int lamazfor(
149 double lon, /* (I) Longitude */
150 double lat, /* (I) Latitude */
151 double *x, /* (O) X projection coordinate */
152 double *y) /* (O) Y projection coordinate */
153 {
154 double delta_lon; /* Delta longitude (Given longitude - center */
155 double sin_delta_lon; /* Sine of the delta longitude */
156 double cos_delta_lon; /* Cosine of the delta longitude */
157 double sinphi; /* Sine of the center latitude */
158 double cosphi; /* Cosine of the center latitude */
159 double sin_lat; /* Sine of the given latitude */
160 double cos_lat; /* Cosine of the given latitude */
161 double g; /* temporary varialbe */
162 double ksp; /* heigth above elipsiod */
163 char mess[60];
164 double qpmq, qppq, rho;
165 double beta, sin_beta, cos_beta;
166 double q, B;
167
168 /* Forward equations
169 -----------------*/
170 if( ind != 0) /* sphere */
171 {
172 delta_lon = adjust_lon(lon - lon_center);
173 tsincos(lat, &sin_lat, &cos_lat);
174 tsincos(delta_lon, &sin_delta_lon, &cos_delta_lon);
175 g = sin_lat_o * sin_lat + cos_lat_o * cos_lat * cos_delta_lon;
176 if (g == -1.0)
177 {
178 sprintf(mess, "Point projects to a circle of radius = %lf\n", 2.0 * R);
179 p_error(mess, "lamaz-forward");
180 return(113);
181 }
182 ksp = R * sqrt(2.0 / (1.0 + g));
183 *x = ksp * cos_lat * sin_delta_lon + false_easting;
184 *y = ksp * (cos_lat_o * sin_lat - sin_lat_o * cos_lat * cos_delta_lon) +
185 false_northing;
186 }
187 else /* ellipsoid */
188 {
189 delta_lon = adjust_lon(lon - lon_center);
190 tsincos(lat, &sinphi, &cosphi);
191 q = (1.0 - es) * ((sinphi / (1.0 - es * sinphi * sinphi))
192 - (1.0 / (2.0 * e)) *
193 log((1.0 - e * sinphi)/(1.0 + e * sinphi)));
194
195 if (fabs(lat_center - HALF_PI) <= EPSLN) /* if Northern Polar Aspect */
196 {
197 qpmq = qp - q;
198 if (fabs(qpmq) <= EPSLN)
199 {
200 rho = 0.0;
201 }
202 else
203 {
204 rho = r_major * sqrt(qpmq);
205 }
206 *x = false_easting + rho * sin(delta_lon);
207 *y = false_northing - rho * cos(delta_lon);
208 }
209 else if (fabs(lat_center + HALF_PI) <= EPSLN) /* if Southern Polar Aspect */
210 {
211 qppq = qp + q;
212 if (fabs(qppq) <= EPSLN)
213 {
214 rho = 0.0;
215 }
216 else
217 {
218 rho = r_major * sqrt(qppq);
219 }
220 *x = false_easting + rho * sin(delta_lon);
221 *y = false_northing + rho * cos(delta_lon);
222 }
223 else /* with any other latitude of origin */
224 {
225 beta = asinz(q/qp);
226 tsincos(beta, &sin_beta, &cos_beta);
227 B = Rq * sqrt((2.0/(1.0 + sin_beta1 * sin_beta + cos_beta1 * cos_beta * cos(delta_lon))));
228
229 *x = false_easting + (B*D) * (cos_beta * sin(delta_lon));
230 *y = false_northing + (B/D) * (cos_beta1 * sin_beta - sin_beta1 * cos_beta * cos(delta_lon));
231 }
232 }
233
234 return(OK);
235 }