Debian Codegraph @

gctp/src/eqconfor.c

raw
1 /*******************************************************************************
2 NAME EQUIDISTANT CONIC
3
4 PURPOSE: Transforms input longitude and latitude to Easting and Northing
5 for the Equidistant Conic projection. The longitude and
6 latitude must be in radians. The Easting and Northing values
7 will be returned in meters.
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 eqconforint(
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 forward equations--mapping lat,long to x,y
129 -----------------------------------------------------------*/
130 int eqconfor(
131 double lon, /* (I) Longitude */
132 double lat, /* (I) Latitude */
133 double *x, /* (O) X projection coordinate */
134 double *y) /* (O) Y projection coordinate */
135 {
136 double ml;
137 double theta;
138 double rh1;
139
140 /* Forward equations
141 -----------------*/
142 ml = mlfn(e0, e1, e2, e3, lat);
143 rh1 = r_major * (g - ml);
144 theta = ns * adjust_lon(lon - lon_center);
145 *x = false_easting + rh1 * sin(theta);
146 *y = false_northing + rh - rh1 * cos(theta);
147
148 return(OK);
149 }