OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
gnominv.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME GNOMONIC
3 
4 PURPOSE: Transforms input Easting and Northing to longitude and
5  latitude for the Gnomonic 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 Gnomonic projection code (FORTRAN)
10 in the General Cartographic Transformation Package software which is
11 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_p13; /* Sine of the center latitude */
34 static double cos_p13; /* 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 Gnomonic projection
39  ---------------------------------*/
40 long gnominvint
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_p13, &cos_p13);
57 
58 /* Report parameters to the user
59  -----------------------------*/
60 gctp_print_title("GNOMONIC");
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 /* Gnomonic inverse equations--mapping x,y to lat/long
69  --------------------------------------------------*/
70 long gnominv
71 (
72  double x, /* (O) X projection coordinate */
73  double y, /* (O) Y projection coordinate */
74  double *lon, /* (I) Longitude */
75  double *lat /* (I) Latitude */
76 )
77 
78 {
79 double rh;
80 double z,sinz,cosz;
81 double con;
82 
83 
84 /* Inverse equations
85  -----------------*/
86 x -= false_easting;
87 y -= false_northing;
88 rh = sqrt(x * x + y * y);
89 z = atan(rh / R);
90 sincos(z,&sinz,&cosz);
91 *lon = lon_center;
92 
93 if (fabs(rh) <= EPSLN)
94  {
95  *lat = lat_center;
96  return(OK);
97  }
98 *lat = asinz(cosz * sin_p13 + (y * sinz * cos_p13) / rh);
99 con = fabs(lat_center) - HALF_PI;
100 if (fabs(con) <= EPSLN)
101  {
102  if (lat_center >= 0.0)
103  {
104  *lon = adjust_lon(lon_center + atan2(x, -y));
105  return(OK);
106  }
107  else
108  {
109  *lon = adjust_lon(lon_center - atan2(-x, y));
110  return(OK);
111  }
112  }
113 con = cosz - sin_p13 * sin(*lat);
114 if ((fabs(con) < EPSLN) && (fabs(x) < EPSLN))
115  return(OK);
116 *lon = adjust_lon(lon_center + atan2((x * sinz * cos_p13), (con * rh)));
117 
118 
119 return(OK);
120 }
int r
Definition: decode_rs.h:73
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
long gnominv(double x, double y, double *lon, double *lat)
Definition: gnominv.c:71
void gctp_print_cenlon(double A)
Definition: gctp_report.c:40
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
#define HALF_PI
Definition: proj_define.h:84
long gnominvint(double r, double center_long, double center_lat, double false_east, double false_north)
Definition: gnominv.c:41
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
#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
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