Debian Codegraph @

gctp/src/bceafor.c

raw
1 /*******************************************************************************
2 NAME Cylinderical Equal Area
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Cylinderical Equal Area projection.
6 The longitude and latitude must be in radians. The Easting
7 and Northing values will be returned in meters.
8
9
10 PROGRAMMER DATE
11 ---------- ----
12 D. Steinwand, EROS Nov, 1991
13 T. Mittan Mar, 1993
14 Abe Taaheri/Emergent Info. Tech., Inc. June, 2000
15 Abe Taaheri/L3 Comm. Analyrics Corp. Oct. 2002 Modified to support both
16 spherical and ellipsoid
17 models of earth for
18 Cylinderical Equal Area
19 projection.
20 ALGORITHM REFERENCES
21
22 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
23 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
24 State Government Printing Office, Washington D.C., 1987.
25
26 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
27 U.S. Geological Survey Professional Paper 1453 , United State Government
28 Printing Office, Washington D.C., 1989.
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; /* major axis */
36 static double r_minor; /* minor axis */
37 static double e; /* eccentricity */
38 static double es; /* eccentricity squared */
39 static double lon_center; /* Center longitude (projection center) */
40 static double lat_truesc; /* Latitude of true scale */
41 static double false_northing; /* y offset in meters */
42 static double false_easting; /* x offset in meters */
43 static double cosphi1; /* cos of latitude of true scale */
44 static double sinphi1; /* sin of latitude of true scale */
45 static double kz; /* K_0 for Cylinderical Equal Area proj.*/
46 static long ind; /* spherical flag */
47
48 /* Initialize the Cylinderical Equal Area projection
49 -------------------------------------------------*/
50 int bceaforint(
51 double r_maj, /* major axis */
52 double r_min, /* minor axis */
53 double center_lon, /* center longitude */
54 double center_lat, /* center latitude */
55 double false_east, /* x offset in meters */
56 double false_north) /* y offset in meters */
57 {
58 double temp; /* temporary variable */
59
60 /* Place parameters in static storage for common use
61 -------------------------------------------------*/
62 r_major = r_maj;
63 r_minor = r_min;
64 lon_center = center_lon;
65 lat_truesc = center_lat;
66 false_northing = false_north;
67 false_easting = false_east;
68
69 temp = r_minor / r_major;
70 es = 1.0 - SQUARE(temp);
71 e = sqrt(es);
72
73 if(es < 0.00001)
74 {
75 ind = 1;
76 }
77 else
78 {
79 ind = 0;
80 }
81
82 cosphi1 = cos(lat_truesc);
83 sinphi1 = sin(lat_truesc);
84 kz = cosphi1/(sqrt(1.0 - (es*sinphi1*sinphi1)));
85
86 /* Report parameters to the user
87 -----------------------------*/
88 ptitle("Cylinderical Equal Area");
89 radius2(r_major, r_minor);
90 cenlonmer(lon_center);
91 true_scale(lat_truesc);
92 offsetp(false_easting,false_northing);
93 return(OK);
94 }
95
96
97 /* Cylinderical Equal Area forward equations--mapping lat,long to x,y
98 --------------------------------------------------*/
99 int bceafor(
100 double lon, /* (I) Longitude */
101 double lat, /* (I) Latitude */
102 double *x, /* (O) X projection coordinate */
103 double *y) /* (O) Y projection coordinate */
104 {
105 double dlon; /* delta longitude value */
106 double sinphi; /* sin value */
107 double q;
108
109 /* Forward equations
110 -----------------*/
111 dlon = adjust_lon(lon - lon_center);
112 sinphi = sin(lat);
113
114 if( ind != 0) /* sphere */
115 {
116 *x = false_easting + r_major * dlon * cosphi1;
117 *y = false_northing + r_major * sinphi / cosphi1;
118 }
119 else /* ellipsoid */
120 {
121 q = (1.0 - es) * ((sinphi / (1.0 - es * sinphi * sinphi))
122 - (1.0 / (2.0 * e)) *
123 log((1.0 - e * sinphi)/(1.0 + e * sinphi)));
124 *x = false_easting + (r_major * kz * dlon);
125 *y = false_northing + (r_major * q) / (2.0 * kz);
126 }
127
128 return(OK);
129 }