Debian Codegraph @

gctp/src/ceafor.c

raw
1 /*******************************************************************************
2 NAME Cylinderical Equal Area
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Cylinderical Equal Area projection.
6 The longitude and latitude must be in radians. The Easting
7 and Northing values will be returned in meters.
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 ALGORITHM REFERENCES
20
21 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
22 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
23 State Government Printing Office, Washington D.C., 1987.
24
25 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
26 U.S. Geological Survey Professional Paper 1453 , United State Government
27 Printing Office, Washington D.C., 1989.
28
29 3. "EASE-Grid 2.0: Incremental but Significant Improvements for Earth-Gridded Data
30 Sets", Mary J. Brodzik ?, Brendan Billingsley, Terry Haran , Bruce Raup and
31 Matthew H.Savoie, National Snow & Ice Data Center, Cooperative Institute of
32 Environmental Sciences, University of Colorado, 449 UCB, Boulder, CO 80309, USA;
33 E-Mails: [email protected] (B.B.); [email protected] (T.H.);
34 [email protected] (B.R.); [email protected] (M.H.S.)
35 *******************************************************************************/
36 #include <stdio.h>
37 #include "cproj.h"
38
39 /* Variables common to all subroutines in this code file
40 -----------------------------------------------------*/
41 static double r_major; /* major axis */
42 static double r_minor; /* minor axis */
43 static double e; /* eccentricity */
44 static double es; /* eccentricity squared */
45 static double lon_center; /* Center longitude (projection center) */
46 static double lat_truesc; /* Latitude of true scale */
47 static double false_northing; /* y offset in meters */
48 static double false_easting; /* x offset in meters */
49 static double cosphi1; /* cos of latitude of true scale */
50 static double sinphi1; /* sin of latitude of true scale */
51 static double kz; /* K_0 for Cylinderical Equal Area proj.*/
52 static long ind; /* spherical flag */
53
54 /* Initialize the Cylinderical Equal Area projection
55 -------------------------------------------------*/
56 int ceaforint(
57 double r_maj, /* major axis */
58 double r_min, /* minor axis */
59 double center_lon, /* center longitude */
60 double center_lat, /* center latitude */
61 double false_east, /* x offset in meters */
62 double false_north) /* y offset in meters */
63 {
64 double temp; /* temporary variable */
65
66 /* Place parameters in static storage for common use
67 -------------------------------------------------*/
68 r_major = r_maj;
69 r_minor = r_min;
70 lon_center = center_lon;
71 lat_truesc = center_lat;
72 false_northing = false_north;
73 false_easting = false_east;
74
75 temp = r_minor / r_major;
76 es = 1.0 - SQUARE(temp);
77 e = sqrt(es);
78
79 if(es < 0.00001)
80 {
81 ind = 1;
82 }
83 else
84 {
85 ind = 0;
86 }
87
88 cosphi1 = cos(lat_truesc);
89 sinphi1 = sin(lat_truesc);
90 kz = cosphi1/(sqrt(1.0 - (es*sinphi1*sinphi1)));
91
92 /* Report parameters to the user
93 -----------------------------*/
94 ptitle("Cylinderical Equal Area");
95 radius2(r_major, r_minor);
96 cenlonmer(lon_center);
97 true_scale(lat_truesc);
98 offsetp(false_easting,false_northing);
99 return(OK);
100 }
101
102
103 /* Cylinderical Equal Area forward equations--mapping lat,long to x,y
104 --------------------------------------------------*/
105 int ceafor(
106 double lon, /* (I) Longitude */
107 double lat, /* (I) Latitude */
108 double *x, /* (O) X projection coordinate */
109 double *y) /* (O) Y projection coordinate */
110 {
111 double dlon; /* delta longitude value */
112 double sinphi; /* sin value */
113 double q;
114
115 /* Forward equations
116 -----------------*/
117 dlon = adjust_lon(lon - lon_center);
118 sinphi = sin(lat);
119
120 if( ind != 0) /* sphere */
121 {
122 *x = false_easting + r_major * dlon * cosphi1;
123 *y = false_northing + r_major * sinphi / cosphi1;
124 }
125 else /* ellipsoid */
126 {
127 q = (1.0 - es) * ((sinphi / (1.0 - es * sinphi * sinphi))
128 - (1.0 / (2.0 * e)) *
129 log((1.0 - e * sinphi)/(1.0 + e * sinphi)));
130 *x = false_easting + (r_major * kz * dlon);
131 *y = false_northing + (r_major * q) / (2.0 * kz);
132 }
133
134 return(OK);
135 }