Debian Codegraph @

gctp/src/lamccfor.c

raw
1
2 /*******************************************************************************
3 NAME LAMBERT CONFORMAL CONIC
4
5 PURPOSE: Transforms input longitude and latitude to Easting and
6 Northing for the Lambert Conformal Conic projection. The
7 longitude and latitude must be in radians. The Easting
8 and Northing values will be returned in meters.
9
10 PROGRAMMER DATE
11 ---------- ----
12 T. Mittan 2-26-93
13
14
15 ALGORITHM REFERENCES
16
17 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
18 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
19 State Government Printing Office, Washington D.C., 1987.
20
21 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
22 U.S. Geological Survey Professional Paper 1453 , United State Government
23 *******************************************************************************/
24 #include <stdio.h>
25 #include "cproj.h"
26
27 /* Variables common to all subroutines in this code file
28 -----------------------------------------------------*/
29 static double r_major; /* major axis */
30 static double r_minor; /* minor axis */
31 static double es; /* eccentricity squared */
32 static double e; /* eccentricity */
33 static double center_lon; /* center longituted */
34 static double center_lat; /* cetner latitude */
35 static double ns; /* ratio of angle between meridian*/
36 static double f0; /* flattening of ellipsoid */
37 static double rh; /* height above ellipsoid */
38 static double false_easting; /* x offset in meters */
39 static double false_northing; /* y offset in meters */
40
41 /* Initialize the Lambert Conformal conic projection
42 ------------------------------------------------*/
43 int lamccforint(
44 double r_maj, /* major axis */
45 double r_min, /* minor axis */
46 double lat1, /* first standard parallel */
47 double lat2, /* second standard parallel */
48 double c_lon, /* center longitude */
49 double c_lat, /* center latitude */
50 double false_east, /* x offset in meters */
51 double false_north) /* y offset in meters */
52 {
53 double sin_po; /* sin value */
54 double cos_po; /* cos value */
55 double con; /* temporary variable */
56 double ms1; /* small m 1 */
57 double ms2; /* small m 2 */
58 double temp; /* temporary variable */
59 double ts0; /* small t 0 */
60 double ts1; /* small t 1 */
61 double ts2; /* small t 2 */
62 r_major = r_maj;
63 r_minor = r_min;
64 false_northing = false_north;
65 false_easting = false_east;
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-for");
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 /* Report parameters to the user
101 -----------------------------*/
102 ptitle("LAMBERT CONFORMAL CONIC");
103 radius2(r_major, r_minor);
104 stanparl(lat1,lat2);
105 cenlonmer(center_lon);
106 origin(c_lat);
107 offsetp(false_easting,false_northing);
108
109 return(OK);
110 }
111 /* Lambert Conformal conic forward equations--mapping lat,long to x,y
112 -----------------------------------------------------------------*/
113 int lamccfor(
114 double lon, /* (I) Longitude */
115 double lat, /* (I) Latitude */
116 double *x, /* (O) X projection coordinate */
117 double *y) /* (O) Y projection coordinate */
118
119 {
120 double con; /* temporary angle variable */
121 double rh1; /* height above ellipsoid */
122 double sinphi; /* sin value */
123 double theta; /* angle */
124 double ts; /* small value t */
125
126 con = fabs( fabs(lat) - HALF_PI);
127 if (con > EPSLN)
128 {
129 sinphi = sin(lat);
130 ts = tsfnz(e,lat,sinphi);
131 rh1 = r_major * f0 * pow(ts,ns);
132 }
133 else
134 {
135 con = lat * ns;
136 if (con <= 0)
137 {
138 p_error("Point can not be projected","lamcc-for");
139 return(44);
140 }
141 rh1 = 0;
142 }
143 theta = ns * adjust_lon(lon - center_lon);
144 *x = rh1 * sin(theta) + false_easting;
145 *y = rh - rh1 * cos(theta) + false_northing;
146
147 return(OK);
148 }
149