OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
lamazinv.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME LAMBERT AZIMUTHAL EQUAL-AREA
3 
4 PURPOSE: Transforms input Easting and Northing to longitude and
5  latitude for the Lambert Azimuthal Equal Area projection. The
6  Easting and Northing must be in meters. The longitude
7  and latitude values will be returned in radians.
8 
9 This function was adapted from the Lambert Azimuthal Equal Area projection
10 code (FORTRAN) in the General Cartographic Transformation Package software
11 which is available from the U.S. Geological Survey National Mapping Division.
12 
13 ALGORITHM REFERENCES
14 
15 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
16  The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
17 
18 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
19  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
20  State Government Printing Office, Washington D.C., 1987.
21 
22 3. "Software Documentation for GCTP General Cartographic Transformation
23  Package", U.S. Geological Survey National Mapping Division, May 1982.
24 *******************************************************************************/
25 #include "oli_cproj.h"
26 #include "oli_local.h"
27 
28 /* Variables common to all subroutines in this code file
29  -----------------------------------------------------*/
30 static double lon_center; /* Center longitude (projection center) */
31 static double lat_center; /* Center latitude (projection center) */
32 static double R; /* Radius of the earth (sphere) */
33 static double sin_lat_o; /* Sine of the center latitude */
34 static double cos_lat_o; /* Cosine of the center latitude */
35 static double false_easting; /* x offset in meters */
36 static double false_northing; /* y offset in meters */
37 
38 /* Initialize the Lambert Azimuthal Equal Area projection
39  ------------------------------------------------------*/
40 long lamazinvint
41 (
42  double r, /* (I) Radius of the earth (sphere) */
43  double center_long, /* (I) Center longitude */
44  double center_lat, /* (I) Center latitude */
45  double false_east, /* x offset in meters */
46  double false_north /* y offset in meters */
47 )
48 {
49 /* Place parameters in static storage for common use
50  -------------------------------------------------*/
51 R = r;
52 lon_center = center_long;
53 lat_center = center_lat;
54 false_easting = false_east;
55 false_northing = false_north;
56 sincos(center_lat, &sin_lat_o, &cos_lat_o);
57 
58 /* Report parameters to the user
59  -----------------------------*/
60 gctp_print_title("LAMBERT AZIMUTHAL EQUAL-AREA");
62 gctp_print_cenlon(center_long);
63 gctp_print_cenlat(center_lat);
64 gctp_print_offsetp(false_easting,false_northing);
65 return(OK);
66 }
67 
68 /* Lambert Azimuthal Equal Area inverse equations--mapping x,y to lat,long
69  -----------------------------------------------------------------------*/
70 long lamazinv
71 (
72  double x, /* (I) X projection coordinate */
73  double y, /* (I) Y projection coordinate */
74  double *lon, /* (O) Longitude */
75  double *lat /* (O) Latitude */
76 )
77 {
78 double Rh;
79 double z; /* Great circle dist from proj center to given point */
80 double sin_z; /* Sine of z */
81 double cos_z; /* Cosine of z */
82 double temp; /* Re-used temporary variable */
83 
84 
85 /* Inverse equations
86  -----------------*/
87 x -= false_easting;
88 y -= false_northing;
89 Rh = sqrt(x * x + y * y);
90 temp = Rh / (2.0 * R);
91 if (temp > 1)
92  {
93  GCTP_PRINT_ERROR("Input data error");
94  return(115);
95  }
96 z = 2.0 * asinz(temp);
97 sincos(z, &sin_z, &cos_z);
98 *lon = lon_center;
99 if (fabs(Rh) > EPSLN)
100  {
101  *lat = asinz(sin_lat_o * cos_z + cos_lat_o * sin_z * y / Rh);
102  temp = fabs(lat_center) - HALF_PI;
103  if (fabs(temp) > EPSLN)
104  {
105  temp = cos_z - sin_lat_o * sin(*lat);
106  if(temp!=0.0)*lon=adjust_lon(lon_center+atan2(x*sin_z*cos_lat_o,temp*Rh));
107  }
108  else if (lat_center < 0.0) *lon = adjust_lon(lon_center - atan2(-x, y));
109  else *lon = adjust_lon(lon_center + atan2(x, -y));
110  }
111 else *lat = lat_center;
112 return(OK);
113 }
int r
Definition: decode_rs.h:73
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
void gctp_print_cenlon(double A)
Definition: gctp_report.c:40
#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
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
long lamazinv(double x, double y, double *lon, double *lat)
Definition: lamazinv.c:71
#define sincos
Definition: proj_define.h:108
#define fabs(a)
Definition: misc.h:93
float * lon
void gctp_print_radius(double radius)
Definition: gctp_report.c:22
#define R
Definition: make_L3_v1.1.c:96
long lamazinvint(double r, double center_long, double center_lat, double false_east, double false_north)
Definition: lamazinv.c:41
double asinz(double con)
Definition: proj_cproj.c:67
void gctp_print_cenlat(double A)
Definition: gctp_report.c:57
#define EPSLN
Definition: proj_define.h:86