OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
gvnspinv.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME GENERAL VERTICAL NEAR-SIDE PERSPECTIVE
3 
4 PURPOSE: Transforms input Easting and Northing to longitude and
5  latitude for the General Vertical Near-Side Perspective
6  projection. The Easting and Northing must be in meters.
7  The longitude and latitude values will be returned in radians.
8 
9 This function was adapted from the General Vertical Near-side 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 p; /* Height above sphere */
34 static double sin_p15; /* Sine of the center latitude */
35 static double cos_p15; /* Cosine of the center latitude */
36 static double false_easting; /* x offset in meters */
37 static double false_northing; /* y offset in meters */
38 
39 /* Initialize the General Vertical Near-Side Perspective projection
40  ---------------------------------------------------------------*/
41 long gvnspinvint
42 (
43  double r, /* (I) Radius of the earth (sphere) */
44  double h, /* height above sphere */
45  double center_long, /* (I) Center longitude */
46  double center_lat, /* (I) Center latitude */
47  double false_east, /* x offset in meters */
48  double false_north /* y offset in meters */
49 )
50 {
51 /* Place parameters in static storage for common use
52  -------------------------------------------------*/
53 R = r;
54 p = 1.0 + h / R;
55 lon_center = center_long;
56 lat_center = center_lat;
57 false_easting = false_east;
58 false_northing = false_north;
59 sincos(center_lat, &sin_p15, &cos_p15);
60 
61 /* Report parameters to the user
62  -----------------------------*/
63 gctp_print_title("GENERAL VERTICAL NEAR-SIDE PERSPECTIVE");
65 gctp_print_genrpt(h,"Height of Point Above Surface of Sphere: ");
66 gctp_print_cenlon(center_long);
67 gctp_print_cenlat(center_lat);
68 gctp_print_offsetp(false_easting,false_northing);
69 return(OK);
70 }
71 
72 /* General Vertical Near-Side Perspective inverse equations--mapping
73  x,y to lat/long
74  ----------------------------------------------------------------*/
75 long gvnspinv
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 {
84 double rh;
85 double r;
86 double con;
87 double com;
88 double z,sinz,cosz;
89 
90 
91 /* Inverse equations
92  -----------------*/
93 x -= false_easting;
94 y -= false_northing;
95 rh = sqrt(x * x + y * y);
96 r = rh / R;
97 con = p - 1.0;
98 com = p + 1.0;
99 if (r > sqrt(con/com))
100  {
101  GCTP_PRINT_ERROR("Input data error");
102  return(155);
103  }
104 sinz = (p - sqrt(1.0 - (r * r * com) / con)) / (con / r + r/con);
105 z = asinz(sinz);
106 sincos(z,&sinz,&cosz);
107 *lon = lon_center;
108 if (fabs(rh) <= EPSLN)
109  {
110  *lat = lat_center;
111  return(OK);
112  }
113 *lat = asinz(cosz * sin_p15 + ( y * sinz * cos_p15)/rh);
114 con = fabs(lat_center) - HALF_PI;
115 if (fabs(con) <= EPSLN)
116  {
117  if (lat_center >= 0.0)
118  {
119  *lon = adjust_lon(lon_center + atan2(x, -y));
120  return(OK);
121  }
122  else
123  {
124  *lon = adjust_lon(lon_center - atan2(-x, y));
125  return(OK);
126  }
127  }
128 con = cosz - sin_p15 * sin(*lat);
129 if ((fabs(con) < EPSLN) && (fabs(x) < EPSLN))
130  return(OK);
131 *lon = adjust_lon(lon_center + atan2((x * sinz * cos_p15), (con * rh)));
132 
133 return(OK);
134 }
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
long gvnspinvint(double r, double h, double center_long, double center_lat, double false_east, double false_north)
Definition: gvnspinv.c:42
float h[MODELMAX]
Definition: atrem_corl1.h:131
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
void gctp_print_genrpt(double A, const char *S)
Definition: gctp_report.c:117
#define sincos
Definition: proj_define.h:108
#define fabs(a)
Definition: misc.h:93
float * lon
long gvnspinv(double x, double y, double *lon, double *lat)
Definition: gvnspinv.c:76
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
float p[MODELMAX]
Definition: atrem_corl1.h:131
void gctp_print_cenlat(double A)
Definition: gctp_report.c:57
#define EPSLN
Definition: proj_define.h:86