Debian Codegraph @

gctp/src/goodfor.c

raw
1 /*******************************************************************************
2 NAME GOODE'S HOMOLOSINE
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Goode's Homolosine 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
10 ---------- ----
11 D. Steinwand, EROS May, 1991; Updated Sept, 1992; Updated Feb 1993
12 S. Nelson, EDC Jun, 1993 Make changes in precision and number
13 of iterations.
14
15 ALGORITHM REFERENCES
16
17 1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
18 U.S. Geological Survey Professional Paper 1453 , United State Government
19 Printing Office, Washington D.C., 1989.
20
21 2. 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 3. Goode, J.P., 1925, The Homolosine projection: a new device for
26 portraying the Earth's surface entire: Assoc. Am. Geographers, Annals,
27 v. 15, p. 119-125
28 *******************************************************************************/
29 #include <stdio.h>
30 #include "cproj.h"
31
32 /* Variables common to all subroutines in this code file
33 -----------------------------------------------------*/
34 static double R; /* Radius of the earth (sphere) */
35 static double lon_center[12]; /* Central meridians, one for each region */
36 static double feast[12]; /* False easting, one for each region */
37
38 /* Initialize the Goode`s Homolosine projection
39 --------------------------------------------*/
40 int goodforint(
41 double r) /* (I) Radius of the earth (sphere) */
42 {
43 /* Place parameters in static storage for common use
44 -------------------------------------------------*/
45 R = r;
46
47 /* Initialize central meridians for each of the 12 regions
48 -------------------------------------------------------*/
49 lon_center[0] = -1.74532925199; /* -100.0 degrees */
50 lon_center[1] = -1.74532925199; /* -100.0 degrees */
51 lon_center[2] = 0.523598775598; /* 30.0 degrees */
52 lon_center[3] = 0.523598775598; /* 30.0 degrees */
53 lon_center[4] = -2.79252680319; /* -160.0 degrees */
54 lon_center[5] = -1.0471975512; /* -60.0 degrees */
55 lon_center[6] = -2.79252680319; /* -160.0 degrees */
56 lon_center[7] = -1.0471975512; /* -60.0 degrees */
57 lon_center[8] = 0.349065850399; /* 20.0 degrees */
58 lon_center[9] = 2.44346095279; /* 140.0 degrees */
59 lon_center[10] = 0.349065850399; /* 20.0 degrees */
60 lon_center[11] = 2.44346095279; /* 140.0 degrees */
61
62 /* Initialize false eastings for each of the 12 regions
63 ----------------------------------------------------*/
64 feast[0] = R * -1.74532925199;
65 feast[1] = R * -1.74532925199;
66 feast[2] = R * 0.523598775598;
67 feast[3] = R * 0.523598775598;
68 feast[4] = R * -2.79252680319;
69 feast[5] = R * -1.0471975512;
70 feast[6] = R * -2.79252680319;
71 feast[7] = R * -1.0471975512;
72 feast[8] = R * 0.349065850399;
73 feast[9] = R * 2.44346095279;
74 feast[10] = R * 0.349065850399;
75 feast[11] = R * 2.44346095279;
76
77 /* Report parameters to the user
78 -----------------------------*/
79 ptitle("GOODE'S HOMOLOSINE EQUAL-AREA");
80 radius(r);
81 return(OK);
82 }
83
84 /* Goode`s Homolosine forward equations--mapping lat,long to x,y
85 -------------------------------------------------------------*/
86 int goodfor(
87 double lon, /* (I) Longitude */
88 double lat, /* (I) Latitude */
89 double *x, /* (O) X projection coordinate */
90 double *y) /* (O) Y projection coordinate */
91 {
92 double delta_lon; /* Delta longitude (Given longitude - center */
93 double theta;
94 double delta_theta;
95 double constant;
96 long i;
97 long region;
98
99 /* Forward equations
100 -----------------*/
101 if (lat >= 0.710987989993) /* if on or above 40 44' 11.8" */
102 {
103 if (lon <= -0.698131700798) region = 0; /* If to the left of -40 */
104 else region = 2;
105 }
106 else if (lat >= 0.0) /* Between 0.0 and 40 44' 11.8" */
107 {
108 if (lon <= -0.698131700798) region = 1; /* If to the left of -40 */
109 else region = 3;
110 }
111 else if (lat >= -0.710987989993) /* Between 0.0 & -40 44' 11.8" */
112 {
113 if (lon <= -1.74532925199) region = 4; /* If between -180 and -100 */
114 else if (lon <= -0.349065850399) region = 5; /* If between -100 and -20 */
115 else if (lon <= 1.3962634016) region = 8; /* If between -20 and 80 */
116 else region = 9; /* If between 80 and 180 */
117 }
118 else /* Below -40 44' */
119 {
120 if (lon <= -1.74532925199) region = 6; /* If between -180 and -100 */
121 else if (lon <= -0.349065850399) region = 7; /* If between -100 and -20 */
122 else if (lon <= 1.3962634016) region = 10; /* If between -20 and 80 */
123 else region = 11; /* If between 80 and 180 */
124 }
125
126 if (region==1||region==3||region==4||region==5||region==8||region==9)
127 {
128 delta_lon = adjust_lon(lon - lon_center[region]);
129 *x = feast[region] + R * delta_lon * cos(lat);
130 *y = R * lat;
131 }
132 else
133 {
134 delta_lon = adjust_lon(lon - lon_center[region]);
135 theta = lat;
136 constant = PI * sin(lat);
137
138 /* Iterate using the Newton-Raphson method to find theta
139 -----------------------------------------------------*/
140 for (i=0;;i++)
141 {
142 delta_theta = -(theta + sin(theta) - constant) / (1.0 + cos(theta));
143 theta += delta_theta;
144 if (fabs(delta_theta) < EPSLN) break;
145 if (i >= 50)
146 {
147 p_error("Iteration failed to converge","goode-forward");
148 return(251);
149 }
150 }
151 theta /= 2.0;
152
153 /* If the latitude is 90 deg, force the x coordinate to be
154 "0 + false easting" this is done here because of precision problems
155 with "cos(theta)"
156 ------------------------------------------------------------------*/
157 if (PI / 2 - fabs(lat) < EPSLN)
158 delta_lon = 0;
159 *x = feast[region] + 0.900316316158 * R * delta_lon * cos(theta);
160 *y = R * (1.4142135623731 * sin(theta) - 0.0528035274542 * sign(lat));
161 }
162
163 return(OK);
164 }