OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
gnomfor.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME GNOMONIC
3 
4 PURPOSE: Transforms input longitude and latitude to Easting and
5  Northing for the Gnomonic projection. The longitude
6  and latitude must be in radians. The Easting and
7  Northing values will be returned in meters.
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 R; /* Radius of the earth (sphere) */
32 static double sin_p13; /* Sine of the center latitude */
33 static double cos_p13; /* Cosine of the center latitude */
34 static double false_easting; /* x offset in meters */
35 static double false_northing; /* y offset in meters */
36 
37 /* Initialize the Gnomonic projection
38  ---------------------------------*/
39 long gnomforint
40 (
41  double r, /* (I) Radius of the earth (sphere) */
42  double center_long, /* (I) Center longitude */
43  double center_lat, /* (I) Center latitude */
44  double false_east, /* x offset in meters */
45  double false_north /* y offset in meters */
46 )
47 {
48 /* Place parameters in static storage for common use
49  -------------------------------------------------*/
50 R = r;
51 lon_center = center_long;
52 false_easting = false_east;
53 false_northing = false_north;
54 sincos(center_lat, &sin_p13, &cos_p13);
55 
56 /* Report parameters to the user
57  -----------------------------*/
58 gctp_print_title("GNOMONIC");
60 gctp_print_cenlon(center_long);
61 gctp_print_cenlat(center_lat);
62 gctp_print_offsetp(false_easting,false_northing);
63 return(OK);
64 }
65 
66 /* Gnomonic forward equations--mapping lat,long to x,y
67  --------------------------------------------------*/
68 long gnomfor
69 (
70  double lon, /* (I) Longitude */
71  double lat, /* (I) Latitude */
72  double *x, /* (O) X projection coordinate */
73  double *y /* (O) Y projection coordinate */
74 )
75 
76 {
77 double dlon;
78 double sinphi,cosphi;
79 double coslon;
80 double g;
81 double ksp;
82 
83 
84 /* Forward equations
85  -----------------*/
86 dlon = adjust_lon(lon - lon_center);
87 sincos(lat,&sinphi,&cosphi);
88 coslon = cos(dlon);
89 g = sin_p13 * sinphi + cos_p13 * cosphi * coslon;
90 if (g <= 0.0)
91  {
92  GCTP_PRINT_ERROR("Point projects into infinity");
93  return(133);
94  }
95 ksp = 1.0 / g;
96 *x = false_easting + R * ksp * cosphi * sin(dlon);
97 *y = false_northing + R * ksp * (cos_p13 * sinphi - sin_p13 * cosphi *
98  coslon);
99 
100 return(OK);
101 }
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
long gnomforint(double r, double center_long, double center_lat, double false_east, double false_north)
Definition: gnomfor.c:40
double adjust_lon(double x)
Definition: proj_cproj.c:349
long gnomfor(double lon, double lat, double *x, double *y)
Definition: gnomfor.c:69
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
float * lon
void gctp_print_radius(double radius)
Definition: gctp_report.c:22
#define R
Definition: make_L3_v1.1.c:96
void gctp_print_cenlat(double A)
Definition: gctp_report.c:57