Debian Codegraph @

gctp/src/eqconinv.c

raw
1 /*******************************************************************************
2 NAME EQUIDISTANT CONIC
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the Equidistant 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 Mar, 1993
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 lon_center; /* Center longitude (projection center) */
31 static double e0,e1,e2,e3; /* eccentricity constants */
32 static double e,es; /* eccentricity constants */
33 static double ml0; /* small value m */
34 static double false_northing; /* y offset in meters */
35 static double false_easting; /* x offset in meters */
36 static double ns;
37 static double g;
38 static double rh;
39
40
41 /* Initialize the Equidistant Conic projection
42 ------------------------------------------*/
43 int eqconinvint(
44 double r_maj, /* major axis */
45 double r_min, /* minor axis */
46 double lat1, /* latitude of standard parallel*/
47 double lat2, /* latitude of standard parallel*/
48 double center_lon, /* center longitude */
49 double center_lat, /* center latitude */
50 double false_east, /* x offset in meters */
51 double false_north, /* y offset in meters */
52 long mode) /* which format is present A B */
53 {
54 double temp; /* temporary variable */
55 double sinphi,cosphi; /* sin and cos values */
56 double ms1,ms2;
57 double ml1,ml2;
58
59 /* Place parameters in static storage for common use
60 -------------------------------------------------*/
61 r_major = r_maj;
62 r_minor = r_min;
63 lon_center = center_lon;
64 false_northing = false_north;
65 false_easting = false_east;
66
67 temp = r_minor / r_major;
68 es = 1.0 - SQUARE(temp);
69 e = sqrt(es);
70 e0 = e0fn(es);
71 e1 = e1fn(es);
72 e2 = e2fn(es);
73 e3 = e3fn(es);
74
75 tsincos(lat1,&sinphi,&cosphi);
76 ms1 = msfnz(e,sinphi,cosphi);
77 ml1 = mlfn(e0, e1, e2, e3, lat1);
78
79 /* format B
80 ---------*/
81 if (mode != 0)
82 {
83 if (fabs(lat1 + lat2) < EPSLN)
84 {
85 p_error("Standard Parallels on opposite sides of equator","eqcon-for");
86 return(81);
87 }
88 tsincos(lat2,&sinphi,&cosphi);
89 ms2 = msfnz(e,sinphi,cosphi);
90 ml2 = mlfn(e0, e1, e2, e3, lat2);
91 if (fabs(lat1 - lat2) >= EPSLN)
92 ns = (ms1 - ms2) / (ml2 - ml1);
93 else
94 ns = sinphi;
95 }
96 else
97 ns = sinphi;
98 g = ml1 + ms1/ns;
99 ml0 = mlfn(e0, e1, e2, e3, center_lat);
100 rh = r_major * (g - ml0);
101
102
103 /* Report parameters to the user
104 -----------------------------*/
105 if (mode != 0)
106 {
107 ptitle("EQUIDISTANT CONIC");
108 radius2(r_major, r_minor);
109 stanparl(lat1,lat2);
110 cenlonmer(lon_center);
111 origin(center_lat);
112 offsetp(false_easting,false_northing);
113 }
114 else
115 {
116 ptitle("EQUIDISTANT CONIC");
117 radius2(r_major, r_minor);
118 stparl1(lat1);
119 cenlonmer(lon_center);
120 origin(center_lat);
121 offsetp(false_easting,false_northing);
122 }
123
124 return(OK);
125 }
126
127
128 /* Equidistant Conic inverse equations--mapping x,y to lat/long
129 -----------------------------------------------------------*/
130 int eqconinv(
131 double x, /* (O) X projection coordinate */
132 double y, /* (O) Y projection coordinate */
133 double *lon, /* (I) Longitude */
134 double *lat) /* (I) Latitude */
135 {
136
137 double rh1;
138 double ml;
139 double con;
140 double theta;
141 long flag;
142
143 /* Inverse equations
144 -----------------*/
145 flag = 0;
146 x -= false_easting;
147 y = rh - y + false_northing;
148 if (ns >= 0)
149 {
150 rh1 = sqrt(x * x + y * y);
151 con = 1.0;
152 }
153 else
154 {
155 rh1 = -sqrt(x * x + y * y);
156 con = -1.0;
157 }
158 theta = 0.0;
159 if (rh1 != 0.0)
160 theta = atan2(con * x, con * y);
161 ml = g - rh1 / r_major;
162 *lat = phi3z(ml,e0,e1,e2,e3,&flag);
163 *lon = adjust_lon(lon_center + theta / ns);
164
165 if (flag != 0)
166 return(flag);
167 else
168 return(OK);
169 }