| 1 |
/******************************************************************************* |
| 2 |
NAME MOLLWEIDE |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Mollweide 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, EROS Nov, 1993; fixed infinite loop at poles |
| 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 |
#include <stdio.h> |
| 25 |
#include "cproj.h" |
| 26 |
|
| 27 |
/* Variables common to all subroutines in this code file |
| 28 |
-----------------------------------------------------*/ |
| 29 |
static double lon_center; /* Center longitude (projection center) */ |
| 30 |
static double R; /* Radius of the earth (sphere) */ |
| 31 |
static double false_easting; /* x offset in meters */ |
| 32 |
static double false_northing; /* y offset in meters */ |
| 33 |
|
| 34 |
/* Initialize the Mollweide projection |
| 35 |
------------------------------------*/ |
| 36 |
int molwinvint( |
| 37 |
double r, /* (I) Radius of the earth (sphere) */ |
| 38 |
double center_long, /* (I) Center longitude */ |
| 39 |
double false_east, /* x offset in meters */ |
| 40 |
double false_north) /* y offset in meters */ |
| 41 |
{ |
| 42 |
/* Place parameters in static storage for common use |
| 43 |
-------------------------------------------------*/ |
| 44 |
false_easting = false_east; |
| 45 |
false_northing = false_north; |
| 46 |
R = r; |
| 47 |
lon_center = center_long; |
| 48 |
|
| 49 |
/* Report parameters to the user |
| 50 |
-----------------------------*/ |
| 51 |
ptitle("MOLLWEIDE"); |
| 52 |
radius(r); |
| 53 |
cenlon(center_long); |
| 54 |
offsetp(false_easting,false_northing); |
| 55 |
return(OK); |
| 56 |
} |
| 57 |
|
| 58 |
/* Mollweide inverse equations--mapping x,y to lat,long |
| 59 |
----------------------------------------------------*/ |
| 60 |
int molwinv( |
| 61 |
double x, /* (I) X projection coordinate */ |
| 62 |
double y, /* (I) Y projection coordinate */ |
| 63 |
double *lon, /* (O) Longitude */ |
| 64 |
double *lat) /* (O) Latitude */ |
| 65 |
{ |
| 66 |
double theta; |
| 67 |
double arg; |
| 68 |
|
| 69 |
/* Inverse equations |
| 70 |
-----------------*/ |
| 71 |
x -= false_easting; |
| 72 |
y -= false_northing; |
| 73 |
arg = y / (1.4142135623731 * R); |
| 74 |
|
| 75 |
/* Because of division by zero problems, 'arg' can not be 1.0. Therefore |
| 76 |
a number very close to one is used instead. |
| 77 |
-------------------------------------------------------------------*/ |
| 78 |
if(fabs(arg) > 0.999999999999) arg=0.999999999999; |
| 79 |
theta = asin(arg); |
| 80 |
*lon = adjust_lon(lon_center + (x / (0.900316316158 * R * cos(theta)))); |
| 81 |
if(*lon < (-PI)) *lon= -PI; |
| 82 |
if(*lon > PI) *lon= PI; |
| 83 |
arg = (2.0 * theta + sin(2.0 * theta)) / PI; |
| 84 |
if(fabs(arg) > 1.0)arg=1.0; |
| 85 |
*lat = asin(arg); |
| 86 |
return(OK); |
| 87 |
} |