Debian Codegraph @

gctp/src/lamccinv.c

raw
1 /*******************************************************************************
2 NAME LAMBERT CONFORMAL CONIC
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the Lambert Conformal Conic 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
10 ---------- ----
11 T. Mittan 2-26-93
12
13 ALGORITHM REFERENCES
14
15 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
16 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
17 State Government Printing Office, Washington D.C., 1987.
18
19 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
20 U.S. Geological Survey Professional Paper 1453 , United State Government
21 Printing Office, Washington D.C., 1989.
22 *******************************************************************************/
23 #include <stdio.h>
24 #include "cproj.h"
25
26 /* Variables common to all subroutines in this code file
27 -----------------------------------------------------*/
28 static double r_major; /* major axis */
29 static double r_minor; /* minor axis */
30 static double es; /* eccentricity squared */
31 static double e; /* eccentricity */
32 static double center_lon; /* center longituted */
33 static double center_lat; /* cetner latitude */
34 static double ns; /* ratio of angle between meridian*/
35 static double f0; /* flattening of ellipsoid */
36 static double rh; /* height above ellipsoid */
37 static double false_easting; /* x offset in meters */
38 static double false_northing; /* y offset in meters */
39
40 /* Initialize the Lambert Conformal Conic projection
41 ------------------------------------------------*/
42 int lamccinvint(
43 double r_maj, /* major axis */
44 double r_min, /* minor axis */
45 double lat1, /* first standard parallel */
46 double lat2, /* second standard parallel */
47 double c_lon, /* center longitude */
48 double c_lat, /* center latitude */
49 double false_east, /* x offset in meters */
50 double false_north) /* y offset in meters */
51 {
52 double sin_po; /* sin value */
53 double cos_po; /* cos value */
54 double con; /* temporary sin value */
55 double ms1; /* small m 1 */
56 double ms2; /* small m 2 */
57 double temp; /* temporary variable */
58 double ts0; /* small t 0 */
59 double ts1; /* small t 1 */
60 double ts2; /* small t 2 */
61
62 r_major = r_maj;
63 r_minor = r_min;
64 false_easting = false_east;
65 false_northing = false_north;
66
67 /* Standard Parallels cannot be equal and on opposite sides of the equator
68 ------------------------------------------------------------------------*/
69 if (fabs(lat1+lat2) < EPSLN)
70 {
71 p_error("Equal Latitiudes for St. Parallels on opposite sides of equator",
72 "lamcc-inv");
73 return(41);
74 }
75
76 temp = r_minor / r_major;
77 es = 1.0 - SQUARE(temp);
78 e = sqrt(es);
79
80 center_lon = c_lon;
81 center_lat = c_lat;
82 tsincos(lat1,&sin_po,&cos_po);
83 con = sin_po;
84 ms1 = msfnz(e,sin_po,cos_po);
85 ts1 = tsfnz(e,lat1,sin_po);
86 tsincos(lat2,&sin_po,&cos_po);
87 ms2 = msfnz(e,sin_po,cos_po);
88 ts2 = tsfnz(e,lat2,sin_po);
89 sin_po = sin(center_lat);
90 ts0 = tsfnz(e,center_lat,sin_po);
91
92 if (fabs(lat1 - lat2) > EPSLN)
93 ns = log (ms1/ms2)/ log (ts1/ts2);
94 else
95 ns = con;
96 f0 = ms1 / (ns * pow(ts1,ns));
97 rh = r_major * f0 * pow(ts0,ns);
98
99
100
101 /* Report parameters to the user
102 -----------------------------*/
103 ptitle("LAMBERT CONFORMAL CONIC");
104 radius2(r_major, r_minor);
105 stanparl(lat1,lat2);
106 cenlonmer(center_lon);
107 origin(c_lat);
108 offsetp(false_easting,false_northing);
109
110 return(OK);
111 }
112
113 /* Lambert Conformal Conic inverse equations--mapping x,y to lat/long
114 -----------------------------------------------------------------*/
115 int lamccinv(
116 double x, /* (O) X projection coordinate */
117 double y, /* (O) Y projection coordinate */
118 double *lon, /* (I) Longitude */
119 double *lat) /* (I) Latitude */
120
121 {
122 double rh1; /* height above ellipsoid */
123 double con; /* sign variable */
124 double ts; /* small t */
125 double theta; /* angle */
126 long flag; /* error flag */
127
128 flag = 0;
129 x -= false_easting;
130 y = rh - y + false_northing;
131 if (ns > 0)
132 {
133 rh1 = sqrt (x * x + y * y);
134 con = 1.0;
135 }
136 else
137 {
138 rh1 = -sqrt (x * x + y * y);
139 con = -1.0;
140 }
141 theta = 0.0;
142 if (rh1 != 0)
143 theta = atan2((con * x),(con * y));
144 if ((rh1 != 0) || (ns > 0.0))
145 {
146 con = 1.0/ns;
147 ts = pow((rh1/(r_major * f0)),con);
148 *lat = phi2z(e,ts,&flag);
149 if (flag != 0)
150 return(flag);
151 }
152 else
153 *lat = -HALF_PI;
154 *lon = adjust_lon(theta/ns + center_lon);
155 return(OK);
156 }