| 1 |
/******************************************************************************* |
| 2 |
NAME MERCATOR |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Mercator 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 Nov, 1991 |
| 12 |
T. Mittan Mar, 1993 |
| 13 |
|
| 14 |
ALGORITHM REFERENCES |
| 15 |
|
| 16 |
1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 17 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 18 |
State Government Printing Office, Washington D.C., 1987. |
| 19 |
|
| 20 |
2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections", |
| 21 |
U.S. Geological Survey Professional Paper 1453 , United State Government |
| 22 |
Printing Office, Washington D.C., 1989. |
| 23 |
*******************************************************************************/ |
| 24 |
#include <stdio.h> |
| 25 |
#include "cproj.h" |
| 26 |
|
| 27 |
/* Variables common to all subroutines in this code file |
| 28 |
-----------------------------------------------------*/ |
| 29 |
static double r_major; /* major axis */ |
| 30 |
static double r_minor; /* minor axis */ |
| 31 |
static double lon_center; /* Center longitude (projection center) */ |
| 32 |
static double lat_origin; /* center latitude */ |
| 33 |
static double e,es; /* eccentricity constants */ |
| 34 |
static double m1; /* small value m */ |
| 35 |
static double false_northing; /* y offset in meters */ |
| 36 |
static double false_easting; /* x offset in meters */ |
| 37 |
|
| 38 |
|
| 39 |
/* Initialize the Mercator projection |
| 40 |
-----------------------------------*/ |
| 41 |
int merinvint( |
| 42 |
double r_maj, /* major axis */ |
| 43 |
double r_min, /* minor axis */ |
| 44 |
double center_lon, /* center longitude */ |
| 45 |
double center_lat, /* center latitude */ |
| 46 |
double false_east, /* x offset in meters */ |
| 47 |
double false_north) /* y offset in meters */ |
| 48 |
{ |
| 49 |
double temp; /* temporary variable */ |
| 50 |
double e0fn(),e1fn(),e2fn(),e3fn(); /* functions */ |
| 51 |
|
| 52 |
/* Place parameters in static storage for common use |
| 53 |
-------------------------------------------------*/ |
| 54 |
r_major = r_maj; |
| 55 |
r_minor = r_min; |
| 56 |
lon_center = center_lon; |
| 57 |
lat_origin = center_lat; |
| 58 |
false_northing = false_north; |
| 59 |
false_easting = false_east; |
| 60 |
|
| 61 |
temp = r_minor / r_major; |
| 62 |
es = 1.0 - SQUARE(temp); |
| 63 |
e = sqrt(es); |
| 64 |
m1 = cos(center_lat)/(sqrt(1.0 - es * sin(center_lat) * sin(center_lat))); |
| 65 |
|
| 66 |
/* Report parameters to the user |
| 67 |
-----------------------------*/ |
| 68 |
ptitle("MERCATOR"); |
| 69 |
radius2(r_major, r_minor); |
| 70 |
cenlonmer(lon_center); |
| 71 |
origin(lat_origin); |
| 72 |
offsetp(false_easting,false_northing); |
| 73 |
return(OK); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
/* Mercator inverse equations--mapping x,y to lat/long |
| 78 |
--------------------------------------------------*/ |
| 79 |
int merinv( |
| 80 |
double x, /* (O) X projection coordinate */ |
| 81 |
double y, /* (O) Y projection coordinate */ |
| 82 |
double *lon, /* (I) Longitude */ |
| 83 |
double *lat) /* (I) Latitude */ |
| 84 |
{ |
| 85 |
double ts; /* small t value */ |
| 86 |
long flag; /* error flag */ |
| 87 |
|
| 88 |
|
| 89 |
/* Inverse equations |
| 90 |
-----------------*/ |
| 91 |
flag = 0; |
| 92 |
x -= false_easting; |
| 93 |
y -= false_northing; |
| 94 |
ts = exp(-y/(r_major * m1)); |
| 95 |
*lat = phi2z(e,ts,&flag); |
| 96 |
if (flag != 0) |
| 97 |
return(flag); |
| 98 |
*lon = adjust_lon(lon_center + x/(r_major * m1)); |
| 99 |
|
| 100 |
return(OK); |
| 101 |
} |