| 1 |
/******************************************************************************* |
| 2 |
NAME GOODE'S HOMOLOSINE |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Goode's Homolosine projection. The |
| 6 |
Easting and Northing must be in meters. The longitude |
| 7 |
and latitude values will be returned in radians. |
| 8 |
|
| 9 |
PROGRAMMER DATE |
| 10 |
---------- ---- |
| 11 |
D. Steinwand, EROS May, 1991; Updated Sept, 1992; Updated Feb 1993 |
| 12 |
S. Nelson, EDC Jun, 1993 Made changes in precision. |
| 13 |
|
| 14 |
ALGORITHM REFERENCES |
| 15 |
|
| 16 |
1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections", |
| 17 |
U.S. Geological Survey Professional Paper 1453 , United State Government |
| 18 |
Printing Office, Washington D.C., 1989. |
| 19 |
|
| 20 |
2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 21 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 22 |
State Government Printing Office, Washington D.C., 1987. |
| 23 |
|
| 24 |
3. Goode, J.P., 1925, The Homolosine projection: a new device for |
| 25 |
portraying the Earth's surface entire: Assoc. Am. Geographers, Annals, |
| 26 |
v. 15, p. 119-125 |
| 27 |
*******************************************************************************/ |
| 28 |
#include <stdio.h> |
| 29 |
#include "cproj.h" |
| 30 |
|
| 31 |
/* Variables common to all subroutines in this code file |
| 32 |
-----------------------------------------------------*/ |
| 33 |
static double R; /* Radius of the earth (sphere) */ |
| 34 |
static double lon_center[12]; /* Central meridians, one for each region */ |
| 35 |
static double feast[12]; /* False easting, one for each region */ |
| 36 |
|
| 37 |
/* Initialize the Goode`s Homolosine projection |
| 38 |
--------------------------------------------*/ |
| 39 |
int goodinvint( |
| 40 |
double r) /* (I) Radius of the earth (sphere) */ |
| 41 |
{ |
| 42 |
/* Place parameters in static storage for common use |
| 43 |
-------------------------------------------------*/ |
| 44 |
R = r; |
| 45 |
|
| 46 |
/* Initialize central meridians for each of the 12 regions |
| 47 |
-------------------------------------------------------*/ |
| 48 |
lon_center[0] = -1.74532925199; /* -100.0 degrees */ |
| 49 |
lon_center[1] = -1.74532925199; /* -100.0 degrees */ |
| 50 |
lon_center[2] = 0.523598775598; /* 30.0 degrees */ |
| 51 |
lon_center[3] = 0.523598775598; /* 30.0 degrees */ |
| 52 |
lon_center[4] = -2.79252680319; /* -160.0 degrees */ |
| 53 |
lon_center[5] = -1.0471975512; /* -60.0 degrees */ |
| 54 |
lon_center[6] = -2.79252680319; /* -160.0 degrees */ |
| 55 |
lon_center[7] = -1.0471975512; /* -60.0 degrees */ |
| 56 |
lon_center[8] = 0.349065850399; /* 20.0 degrees */ |
| 57 |
lon_center[9] = 2.44346095279; /* 140.0 degrees */ |
| 58 |
lon_center[10] = 0.349065850399; /* 20.0 degrees */ |
| 59 |
lon_center[11] = 2.44346095279; /* 140.0 degrees */ |
| 60 |
|
| 61 |
/* Initialize false eastings for each of the 12 regions |
| 62 |
----------------------------------------------------*/ |
| 63 |
feast[0] = R * -1.74532925199; |
| 64 |
feast[1] = R * -1.74532925199; |
| 65 |
feast[2] = R * 0.523598775598; |
| 66 |
feast[3] = R * 0.523598775598; |
| 67 |
feast[4] = R * -2.79252680319; |
| 68 |
feast[5] = R * -1.0471975512; |
| 69 |
feast[6] = R * -2.79252680319; |
| 70 |
feast[7] = R * -1.0471975512; |
| 71 |
feast[8] = R * 0.349065850399; |
| 72 |
feast[9] = R * 2.44346095279; |
| 73 |
feast[10] = R * 0.349065850399; |
| 74 |
feast[11] = R * 2.44346095279; |
| 75 |
|
| 76 |
/* Report parameters to the user |
| 77 |
-----------------------------*/ |
| 78 |
ptitle("GOODE'S HOMOLOSINE EQUAL-AREA"); |
| 79 |
radius(r); |
| 80 |
return(OK); |
| 81 |
} |
| 82 |
|
| 83 |
/* Goode`s Homolosine inverse equations--mapping x,y to lat,long |
| 84 |
-------------------------------------------------------------*/ |
| 85 |
int goodinv( |
| 86 |
double x, /* (I) X projection coordinate */ |
| 87 |
double y, /* (I) Y projection coordinate */ |
| 88 |
double *lon, /* (O) Longitude */ |
| 89 |
double *lat) /* (O) Latitude */ |
| 90 |
{ |
| 91 |
double arg; |
| 92 |
double theta; |
| 93 |
double temp; |
| 94 |
long region; |
| 95 |
|
| 96 |
/* Inverse equations |
| 97 |
-----------------*/ |
| 98 |
if (y >= R * 0.710987989993) /* if on or above 40 44' 11.8" */ |
| 99 |
{ |
| 100 |
if (x <= R * -0.698131700798) region = 0; /* If to the left of -40 */ |
| 101 |
else region = 2; |
| 102 |
} |
| 103 |
else if (y >= 0.0) /* Between 0.0 and 40 44' 11.8" */ |
| 104 |
{ |
| 105 |
if (x <= R * -0.698131700798) region = 1; /* If to the left of -40 */ |
| 106 |
else region = 3; |
| 107 |
} |
| 108 |
else if (y >= R * -0.710987989993) /* Between 0.0 & -40 44' 11.8" */ |
| 109 |
{ |
| 110 |
if (x <= R * -1.74532925199) region = 4; /* If between -180 and -100 */ |
| 111 |
else if (x <= R * -0.349065850399) region = 5; /* If between -100 and -20 */ |
| 112 |
else if (x <= R * 1.3962634016) region = 8; /* If between -20 and 80 */ |
| 113 |
else region = 9; /* If between 80 and 180 */ |
| 114 |
} |
| 115 |
else /* Below -40 44' 11.8" */ |
| 116 |
{ |
| 117 |
if (x <= R * -1.74532925199) region = 6; /* If between -180 and -100 */ |
| 118 |
else if (x <= R * -0.349065850399) region = 7; /* If between -100 and -20 */ |
| 119 |
else if (x <= R * 1.3962634016) region = 10; /* If between -20 and 80 */ |
| 120 |
else region = 11; /* If between 80 and 180 */ |
| 121 |
} |
| 122 |
x = x - feast[region]; |
| 123 |
|
| 124 |
if (region==1||region==3||region==4||region==5||region==8||region==9) |
| 125 |
{ |
| 126 |
*lat = y / R; |
| 127 |
if (fabs(*lat) > HALF_PI) |
| 128 |
{ |
| 129 |
p_error("Input data error","goode-inverse"); |
| 130 |
return(252); |
| 131 |
} |
| 132 |
temp = fabs(*lat) - HALF_PI; |
| 133 |
if (fabs(temp) > EPSLN) |
| 134 |
{ |
| 135 |
temp = lon_center[region] + x / (R * cos(*lat)); |
| 136 |
*lon = adjust_lon(temp); |
| 137 |
} |
| 138 |
else *lon = lon_center[region]; |
| 139 |
} |
| 140 |
else |
| 141 |
{ |
| 142 |
arg = (y + 0.0528035274542 * R * sign(y)) / (1.4142135623731 * R); |
| 143 |
if (fabs(arg) > 1.0) return(IN_BREAK); |
| 144 |
theta = asin(arg); |
| 145 |
*lon = lon_center[region]+(x/(0.900316316158 * R * cos(theta))); |
| 146 |
if(*lon < -(PI + EPSLN)) return(IN_BREAK); |
| 147 |
arg = (2.0 * theta + sin(2.0 * theta)) / PI; |
| 148 |
if (fabs(arg) > 1.0) return(IN_BREAK); |
| 149 |
*lat = asin(arg); |
| 150 |
} |
| 151 |
/* because of precision problems, long values of 180 deg and -180 deg |
| 152 |
may be mixed. |
| 153 |
----------------------------------------------------------------*/ |
| 154 |
if (((x < 0) && (PI - *lon < EPSLN)) || ((x > 0) && (PI + *lon < EPSLN))) |
| 155 |
*lon = -(*lon); |
| 156 |
|
| 157 |
/* Are we in a interrupted area? If so, return status code of IN_BREAK. |
| 158 |
---------------------------------------------------------------------*/ |
| 159 |
if (region == 0 && (*lon < -(PI + EPSLN) || *lon > -0.698131700798)) |
| 160 |
return(IN_BREAK); |
| 161 |
if (region == 1 && (*lon < -(PI + EPSLN) || *lon > -0.698131700798)) |
| 162 |
return(IN_BREAK); |
| 163 |
if (region == 2 && (*lon < -0.698131700798 || *lon > PI + EPSLN)) |
| 164 |
return(IN_BREAK); |
| 165 |
if (region == 3 && (*lon < -0.698131700798 || *lon > PI + EPSLN)) |
| 166 |
return(IN_BREAK); |
| 167 |
if (region == 4 && (*lon < -(PI + EPSLN) || *lon > -1.74532925199)) |
| 168 |
return(IN_BREAK); |
| 169 |
if (region == 5 && (*lon < -1.74532925199 || *lon > -0.349065850399)) |
| 170 |
return(IN_BREAK); |
| 171 |
if (region == 6 && (*lon < -(PI + EPSLN) || *lon > -1.74532925199)) |
| 172 |
return(IN_BREAK); |
| 173 |
if (region == 7 && (*lon < -1.74532925199 || *lon > -0.349065850399)) |
| 174 |
return(IN_BREAK); |
| 175 |
if (region == 8 && (*lon < -0.349065850399 || *lon > 1.3962634016)) |
| 176 |
return(IN_BREAK); |
| 177 |
if (region == 9 && (*lon < 1.3962634016|| *lon > PI + EPSLN)) |
| 178 |
return(IN_BREAK); |
| 179 |
if (region ==10 && (*lon < -0.349065850399 || *lon > 1.3962634016)) |
| 180 |
return(IN_BREAK); |
| 181 |
if (region ==11 && (*lon < 1.3962634016 || *lon > PI + EPSLN)) |
| 182 |
return(IN_BREAK); |
| 183 |
return(OK); |
| 184 |
} |
| 185 |
|