OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
merfor.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME MERCATOR
3 
4 PURPOSE: Transforms input longitude and latitude to Easting and
5  Northing for the Mercator projection. The
6  longitude and latitude must be in radians. The Easting
7  and Northing values will be returned in meters.
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 merforint
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 forward equations--mapping lat,long to x,y
74  --------------------------------------------------*/
75 long merfor
76 (
77  double lon, /* (I) Longitude */
78  double lat, /* (I) Latitude */
79  double *x, /* (O) X projection coordinate */
80  double *y /* (O) Y projection coordinate */
81 )
82 {
83 double ts; /* small t value */
84 double sinphi; /* sin value */
85 
86 /* Forward equations
87  -----------------*/
88 if (fabs(fabs(lat) - HALF_PI) <= EPSLN)
89  {
90  GCTP_PRINT_ERROR("Transformation cannot be computed at the poles");
91  return(53);
92  }
93 else
94  {
95  sinphi = sin(lat);
96  ts = gctp_calc_small_t(e,lat,sinphi);
97  *x = false_easting + r_major * m1 * adjust_lon(lon - lon_center);
98  *y = false_northing - r_major * m1 * log(ts);
99  }
100 return(OK);
101 }
#define SQUARE(x)
Definition: proj_define.h:99
void gctp_print_origin(double A)
Definition: gctp_report.c:65
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
long merfor(double lon, double lat, double *x, double *y)
Definition: merfor.c:76
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
#define HALF_PI
Definition: proj_define.h:84
double gctp_calc_small_t(double eccent, double phi, double sinphi)
Definition: gctp_utility.c:277
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
void gctp_print_radius2(double radius1, double radius2)
Definition: gctp_report.c:30
void gctp_print_cenlonmer(double A)
Definition: gctp_report.c:48
#define fabs(a)
Definition: misc.h:93
long merforint(double r_maj, double r_min, double center_lon, double center_lat, double false_east, double false_north)
Definition: merfor.c:37
float * lon
#define EPSLN
Definition: proj_define.h:86