OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
merinv.c
Go to the documentation of this file.
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 ALGORITHM REFERENCES
10 
11 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
12  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
13  State Government Printing Office, Washington D.C., 1987.
14 
15 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
16  U.S. Geological Survey Professional Paper 1453 , United State Government
17  Printing Office, Washington D.C., 1989.
18 *******************************************************************************/
19 #include "oli_cproj.h"
20 #include "oli_local.h"
21 
22 /* Variables common to all subroutines in this code file
23  -----------------------------------------------------*/
24 static double r_major; /* major axis */
25 static double r_minor; /* minor axis */
26 static double lon_center; /* Center longitude (projection center) */
27 static double lat_origin; /* center latitude */
28 static double e,es; /* eccentricity constants */
29 static double m1; /* small value m */
30 static double false_northing; /* y offset in meters */
31 static double false_easting; /* x offset in meters */
32 
33 
34 /* Initialize the Mercator projection
35  -----------------------------------*/
36 long merinvint
37 (
38  double r_maj, /* major axis */
39  double r_min, /* minor axis */
40  double center_lon, /* center longitude */
41  double center_lat, /* center latitude */
42  double false_east, /* x offset in meters */
43  double false_north /* y offset in meters */
44 )
45 {
46 double temp; /* temporary variable */
47 
48 /* Place parameters in static storage for common use
49  -------------------------------------------------*/
50 r_major = r_maj;
51 r_minor = r_min;
52 lon_center = center_lon;
53 lat_origin = center_lat;
54 false_northing = false_north;
55 false_easting = false_east;
56 
57 temp = r_minor / r_major;
58 es = 1.0 - SQUARE(temp);
59 e = sqrt(es);
60 m1 = cos(center_lat)/(sqrt(1.0 - es * sin(center_lat) * sin(center_lat)));
61 
62 /* Report parameters to the user
63  -----------------------------*/
64 gctp_print_title("MERCATOR");
66 gctp_print_cenlonmer(lon_center);
69 return(OK);
70 }
71 
72 
73 /* Mercator inverse equations--mapping x,y to lat/long
74  --------------------------------------------------*/
75 long merinv
76 (
77  double x, /* (O) X projection coordinate */
78  double y, /* (O) Y projection coordinate */
79  double *lon, /* (I) Longitude */
80  double *lat /* (I) Latitude */
81 )
82 {
83 double ts; /* small t value */
84 long flag; /* error flag */
85 
86 
87 /* Inverse equations
88  -----------------*/
89 flag = 0;
90 x -= false_easting;
91 y -= false_northing;
92 ts = exp(-y/(r_major * m1));
93 flag = gctp_calc_phi2(e,ts,lat);
94 if (flag != GCTP_SUCCESS)
95  return GCTP_ERROR;
96 *lon = adjust_lon(lon_center + x/(r_major * m1));
97 
98 return(OK);
99 }
#define SQUARE(x)
Definition: proj_define.h:99
void gctp_print_origin(double A)
Definition: gctp_report.c:65
long merinvint(double r_maj, double r_min, double center_lon, double center_lat, double false_east, double false_north)
Definition: merinv.c:37
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
#define GCTP_ERROR
Definition: gctp.h:81
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
int gctp_calc_phi2(double eccent, double ts, double *phi2)
Definition: gctp_utility.c:209
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
long merinv(double x, double y, double *lon, double *lat)
Definition: merinv.c:76
#define GCTP_SUCCESS
Definition: gctp.h:82
void gctp_print_radius2(double radius1, double radius2)
Definition: gctp_report.c:30
void gctp_print_cenlonmer(double A)
Definition: gctp_report.c:48
float * lon