OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
vandgfor.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME VAN DER GRINTEN
3 
4 PURPOSE: Transforms input longitude and latitude to Easting and
5  Northing for the Van der Grinten projection. The
6  longitude and latitude must be in radians. The Easting
7  and Northing values will be returned in meters.
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 R; /* Radius of the earth (sphere) */
32 static double false_easting; /* x offset in meters */
33 static double false_northing; /* y offset in meters */
34 
35 /* Initialize the Van Der Grinten projection
36  ----------------------------------------*/
37 long vandgforint
38 (
39  double r, /* (I) Radius of the earth (sphere) */
40  double center_long, /* (I) Center longitude */
41  double false_east, /* x offset in meters */
42  double false_north /* y offset in meters */
43 )
44 {
45 /* Place parameters in static storage for common use
46  -------------------------------------------------*/
47 R = r;
48 lon_center = center_long;
49 false_easting = false_east;
50 false_northing = false_north;
51 
52 /* Report parameters to the user
53  -----------------------------*/
54 gctp_print_title("VAN DER GRINTEN");
56 gctp_print_cenlon(center_long);
58 return(OK);
59 }
60 
61 /* Van Der Grinten forward equations--mapping lat,long to x,y
62  ---------------------------------------------------------*/
63 long vandgfor
64 (
65  double lon, /* (I) Longitude */
66  double lat, /* (I) Latitude */
67  double *x, /* (O) X projection coordinate */
68  double *y /* (O) Y projection coordinate */
69 )
70 
71 {
72 double dlon;
73 double theta;
74 double al,asq;
75 double g,gsq;
76 double m,msq;
77 double con;
78 double costh,sinth;
79 
80 /* Forward equations
81  -----------------*/
82 dlon = adjust_lon(lon - lon_center);
83 
84 if (fabs(lat) <= EPSLN)
85  {
86  *x = false_easting + R * dlon;
87  *y = false_northing;
88  return (OK);
89  }
90 theta = asinz(2.0 * fabs(lat / PI));
91 if ((fabs(dlon) <= EPSLN) || (fabs(fabs(lat) - HALF_PI) <= EPSLN))
92  {
93  *x = false_easting;
94  if (lat >= 0)
95  *y = false_northing + PI * R * tan(.5 * theta);
96  else
97  *y = false_northing + PI * R * -tan(.5 * theta);
98  return(OK);
99  }
100 al = .5 * fabs((PI / dlon) - (dlon / PI));
101 asq = al * al;
102 sincos(theta,&sinth,&costh);
103 g = costh / (sinth + costh - 1.0);
104 gsq = g * g;
105 m = g * (2.0 / sinth - 1.0);
106 msq = m * m;
107 con = PI * R * (al * (g - msq) + sqrt(asq * (g - msq) * (g - msq) - (msq + asq)
108  * (gsq - msq))) / (msq + asq);
109 if (dlon < 0)
110  con = -con;
111 *x = false_easting + con;
112 con = fabs(con / (PI * R));
113 if (lat >= 0)
114  *y = false_northing + PI * R * sqrt(1.0 - con * con - 2.0 * al * con);
115 else
116  *y = false_northing - PI * R * sqrt(1.0 - con * con - 2.0 * al * con);
117 
118 return(OK);
119 }
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
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
#define PI
Definition: l3_get_org.c:6
double false_easting
Definition: tm.c:54
long vandgfor(double lon, double lat, double *x, double *y)
Definition: vandgfor.c:64
long vandgforint(double r, double center_long, double false_east, double false_north)
Definition: vandgfor.c:38
#define HALF_PI
Definition: proj_define.h:84
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
double false_northing
Definition: tm.c:53
#define OK
Definition: ancil.h:30
#define sincos
Definition: proj_define.h:108
#define fabs(a)
Definition: misc.h:93
double lon_center
Definition: tm.c:51
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
#define EPSLN
Definition: proj_define.h:86