Debian Codegraph @

gctp/src/sininv.c

raw
1 /*******************************************************************************
2 NAME SINUSOIDAL
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the Sinusoidal projection. The
6 Easting and Northing must be in meters. The longitude
7 and latitude values will be returned in radians.
8
9 PROGRAMMER DATE REASON
10 ---------- ---- ------
11 D. Steinwand, EROS May, 1991
12 Abe Taaheri/Raytheon IIS March, 2017 Modified to support both
13 spherical and ellipsoidal
14 models of earth for
15 Sinusoidal projection
16
17 This function was adapted from the Sinusoidal projection code (FORTRAN) in the
18 General Cartographic Transformation Package software which is available from
19 the U.S. Geological Survey National Mapping Division.
20
21 ALGORITHM REFERENCES
22
23 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
24 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
25 State Government Printing Office, Washington D.C., 1987.
26
27 2. "Software Documentation for GCTP General Cartographic Transformation
28 Package", U.S. Geological Survey National Mapping Division, May 1982.
29 *******************************************************************************/
30 #include <stdio.h>
31 #include "cproj.h"
32
33 /* Variables common to all subroutines in this code file
34 -----------------------------------------------------*/
35 static double r_major, r_minor; /* major axis */
36 static double lon_center; /* Center longitude (projection center) */
37 static double R; /* Radius of the earth (sphere) */
38 static double false_easting; /* x offset in meters */
39 static double false_northing; /* y offset in meters */
40 static long ind; /* spherical flag */
41 static double e, es, imu; /* eccentricity constants */
42 static double e1, e2, e3, e4, e5;
43
44 /* Initialize the Sinusoidal projection
45 ------------------------------------*/
46 int sininvint(
47 double r_maj, /* major axis */
48 double r_min, /* minor axis */
49 double center_long, /* (I) Center longitude */
50 double false_east, /* x offset in meters */
51 double false_north) /* y offset in meters */
52 {
53 /* Place parameters in static storage for common use
54 -------------------------------------------------*/
55 R = r_maj;
56 if(fabs(r_min) < EPSLN ) /* sphere */
57 {
58 r_major = r_maj;
59 r_minor = r_maj;
60 }
61 else /* sphere or ellipsoide */
62 {
63 r_major = r_maj;
64 r_minor = r_min;
65 }
66
67 lon_center = center_long;
68 false_easting = false_east;
69 false_northing = false_north;
70 es = 1.0 - SQUARE(r_minor / r_major);
71 e = sqrt(es);
72
73 if(e < 0.00001)
74 {
75 ind = 1; /* sphere */
76 }
77 else
78 {
79 double e12, e13, e14;
80 ind = 0; /* ellipsoid */
81 e1 = (1.0 - sqrt(1.0 - es))/(1.0 + sqrt(1.0 - es));
82 e12 = e1 * e1;
83 e13 = e12 * e1;
84 e14 = e13 * e1;
85 imu = (1.0 - (es/4.0) - (3.0 * es * es / 64.0) -
86 (5.0 * es * es * es /256.0));
87 e2 = ((3.0 * e1 /2.0) - (27.0 * e13 / 32.0));
88 e3 = ((21.0 * e12 / 16.0) - (55.0 * e14 / 32.0));
89 e4 = (151.0 * e13 / 96.0);
90 e5 = (1097.0 * e14 / 512.0);
91 }
92
93 /* Report parameters to the user
94 -----------------------------*/
95 ptitle("SINUSOIDAL");
96 radius2(r_major, r_minor);
97 cenlon(center_long);
98 offsetp(false_easting,false_northing);
99 return(OK);
100 }
101
102 /* Sinusoidal inverse equations--mapping x,y to lat,long
103 -----------------------------------------------------*/
104 int sininv(
105 double x, /* (I) X projection coordinate */
106 double y, /* (I) Y projection coordinate */
107 double *lon, /* (O) Longitude */
108 double *lat) /* (O) Latitude */
109 {
110 double temp; /* Re-used temporary variable */
111 double mu, ml;
112 double sin_phi, cos_phi;
113 /* Inverse equations
114 -----------------*/
115 x -= false_easting;
116 y -= false_northing;
117
118 if (ind != 0) /* Spherical */
119 {
120 *lat = y / R;
121 if (fabs(*lat) > HALF_PI)
122 {
123 p_error("Input data error","sinusoidal-inverse");
124 return(164);
125 }
126 temp = fabs(*lat) - HALF_PI;
127 if (fabs(temp) > EPSLN)
128 {
129 temp = lon_center + x / (R * cos(*lat));
130 *lon = adjust_lon(temp);
131 }
132 else *lon = lon_center;
133 return(OK);
134 }
135 else /* Ellipsoidal */
136 {
137 ml = y;
138 mu = ml / (r_major * imu);
139 *lat = mu +
140 (e2 * sin(2.0 * mu)) +
141 (e3 * sin(4.0 * mu)) +
142 (e4 * sin(6.0 * mu)) +
143 (e5 * sin(8.0 * mu));
144
145 if (fabs(*lat) > HALF_PI)
146 {
147 p_error("Input data error","sinusoidal-inverse");
148 return(164);
149 }
150 temp = fabs(*lat) - HALF_PI;
151 if (fabs(temp) > EPSLN)
152 {
153 sin_phi = sin(*lat);
154 cos_phi = cos(*lat);
155 temp = lon_center +
156 x * sqrt(1.0 - es * SQUARE(sin_phi)) / (r_major * cos_phi);
157 *lon = adjust_lon(temp);
158 }
159 else *lon = lon_center;
160 return(OK);
161 }
162 }
163