OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
aziminv.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME AZIMUTHAL EQUIDISTANT
3 
4 PURPOSE: Transforms input Easting and Northing to longitude and
5  latitude for the Azimuthal Equidistant projection. The
6  Easting and Northing must be in meters. The longitude
7  and latitude values will be returned in radians.
8 
9 ALGORITHM REFERENCES
10 
11 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
12  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
13  State Government Printing Office, Washington D.C., 1987.
14 
15 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
16  U.S. Geological Survey Professional Paper 1453 , United State Government
17  Printing Office, Washington D.C., 1989.
18 *******************************************************************************/
19 #include "oli_cproj.h"
20 #include "oli_local.h"
21 
22 /* Variables common to all subroutines in this code file
23  -----------------------------------------------------*/
24 static double r_major; /* major axis */
25 static double lon_center; /* Center longitude (projection center) */
26 static double lat_origin; /* center latitude */
27 static double false_northing; /* y offset in meters */
28 static double false_easting; /* x offset in meters */
29 static double sin_p12; /* sin of center latitude */
30 static double cos_p12; /* cos of center latitude */
31 
32 /* Initialize the Azimuthal projection
33  ----------------------------------*/
34 long aziminvint
35 (
36  double r_maj, /* major axis */
37  double center_lon, /* center longitude */
38  double center_lat, /* center latitude */
39  double false_east, /* x offset in meters */
40  double false_north /* y offset in meters */
41 )
42 {
43 
44 /* Place parameters in static storage for common use
45  -------------------------------------------------*/
46 r_major = r_maj;
47 lon_center = center_lon;
48 lat_origin = center_lat;
49 false_northing = false_north;
50 false_easting = false_east;
51 
52 sincos(center_lat,&sin_p12,&cos_p12);
53 
54 /* Report parameters to the user
55  -----------------------------*/
56 gctp_print_title("AZIMUTHAL EQUIDISTANT");
57 gctp_print_radius(r_major);
58 gctp_print_cenlonmer(lon_center);
59 gctp_print_origin(lat_origin);
60 gctp_print_offsetp(false_easting,false_northing);
61 return(OK);
62 }
63 
64 
65 /* Azimuthal inverse equations--mapping x,y to lat/long
66  ---------------------------------------------------*/
67 long aziminv
68 (
69  double x, /* (O) X projection coordinate */
70  double y, /* (O) Y projection coordinate */
71  double *lon, /* (I) Longitude */
72  double *lat /* (I) Latitude */
73 )
74 {
75 double rh; /* height above ellipsoid */
76 double z; /* angle */
77 double sinz,cosz; /* sin of z and cos of z */
78 double con;
79 
80 /* Inverse equations
81  -----------------*/
82 x -= false_easting;
83 y -= false_northing;
84 rh = sqrt(x * x + y * y);
85 if (rh > (2.0 * HALF_PI * r_major))
86  {
87  GCTP_PRINT_ERROR("Input data error");
88  return(125);
89  }
90 z = rh / r_major;
91 sincos(z,&sinz,&cosz);
92 *lon = lon_center;
93 if (fabs(rh) <= EPSLN)
94  {
95  *lat = lat_origin;
96  return(OK);
97  }
98 *lat = asinz(cosz * sin_p12 + (y * sinz * cos_p12) / rh);
99 con = fabs(lat_origin) - HALF_PI;
100 if (fabs(con) <= EPSLN)
101  {
102  if (lat_origin >= 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_p12 * sin(*lat);
114 if ((fabs(con) < EPSLN) && (fabs(x) < EPSLN))
115  return(OK);
116 *lon = adjust_lon(lon_center + atan2((x * sinz * cos_p12), (con * rh)));
117 
118 return(OK);
119 }
void gctp_print_origin(double A)
Definition: gctp_report.c:65
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
long aziminv(double x, double y, double *lon, double *lat)
Definition: aziminv.c:68
#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
long aziminvint(double r_maj, double center_lon, double center_lat, double false_east, double false_north)
Definition: aziminv.c:35
#define OK
Definition: ancil.h:30
#define sincos
Definition: proj_define.h:108
void gctp_print_cenlonmer(double A)
Definition: gctp_report.c:48
#define fabs(a)
Definition: misc.h:93
float * lon
void gctp_print_radius(double radius)
Definition: gctp_report.c:22
double asinz(double con)
Definition: proj_cproj.c:67
#define EPSLN
Definition: proj_define.h:86