Debian Codegraph @

gctp/src/robfor.c

raw
1 /*******************************************************************************
2 NAME ROBINSON
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Robinson projection. The
6 longitude and latitude must be in radians. The Easting
7 and Northing values will be returned in meters.
8
9 PROGRAMMER DATE
10 ---------- ----
11 T. Mittan March, 1993
12
13 This function was adapted from the Lambert Azimuthal Equal Area projection
14 code (FORTRAN) in the General Cartographic Transformation Package software
15 which is available from the U.S. Geological Survey National Mapping Division.
16
17 ALGORITHM REFERENCES
18
19 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
20 The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
21
22 2. 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 3. "Software Documentation for GCTP General Cartographic Transformation
27 Package", U.S. Geological Survey National Mapping Division, May 1982.
28 *******************************************************************************/
29 #include <stdio.h>
30 #include "cproj.h"
31
32 /* Variables common to all subroutines in this code file
33 -----------------------------------------------------*/
34 static double lon_center; /* Center longitude (projection center) */
35 static double R; /* Radius of the earth (sphere) */
36 static double false_easting; /* x offset in meters */
37 static double false_northing; /* y offset in meters */
38 static double pr[21];
39 static double xlr[21];
40
41 /* Initialize the ROBINSON projection
42 ---------------------------------*/
43 int robforint(
44 double r, /* (I) Radius of the earth (sphere) */
45 double center_long, /* (I) Center longitude */
46 double false_east, /* x offset in meters */
47 double false_north) /* y offset in meters */
48 {
49 long i;
50
51 /* Place parameters in static storage for common use
52 -------------------------------------------------*/
53 R = r;
54 lon_center = center_long;
55 false_easting = false_east;
56 false_northing = false_north;
57
58 pr[1]= -0.062;
59 xlr[1]=0.9986;
60 pr[2]=0.0;
61 xlr[2]=1.0;
62 pr[3]=0.062;
63 xlr[3]=0.9986;
64 pr[4]=0.124;
65 xlr[4]=0.9954;
66 pr[5]=0.186;
67 xlr[5]=0.99;
68 pr[6]=0.248;
69 xlr[6]=0.9822;
70 pr[7]=0.31;
71 xlr[7]=0.973;
72 pr[8]=0.372;
73 xlr[8]=0.96;
74 pr[9]=0.434;
75 xlr[9]=0.9427;
76 pr[10]=0.4958;
77 xlr[10]=0.9216;
78 pr[11]=0.5571;
79 xlr[11]=0.8962;
80 pr[12]=0.6176;
81 xlr[12]=0.8679;
82 pr[13]=0.6769;
83 xlr[13]=0.835;
84 pr[14]=0.7346;
85 xlr[14]=0.7986;
86 pr[15]=0.7903;
87 xlr[15]=0.7597;
88 pr[16]=0.8435;
89 xlr[16]=0.7186;
90 pr[17]=0.8936;
91 xlr[17]=0.6732;
92 pr[18]=0.9394;
93 xlr[18]=0.6213;
94 pr[19]=0.9761;
95 xlr[19]=0.5722;
96 pr[20]=1.0;
97 xlr[20]=0.5322;
98
99 for (i = 0; i < 21; i++)
100 xlr[i] *= 0.9858;
101
102 /* Report parameters to the user
103 -----------------------------*/
104 ptitle("ROBINSON");
105 radius(r);
106 cenlon(center_long);
107 offsetp(false_easting,false_northing);
108 return(OK);
109 }
110
111 /* Robinson forward equations--mapping lat,long to x,y
112 ------------------------------------------------------------*/
113 int robfor(
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 dlon;
121 double p2;
122 long ip1;
123
124 /* Forward equations
125 -----------------*/
126 dlon = adjust_lon(lon - lon_center);
127 p2 = fabs(lat / 5.0 / .01745329252);
128 ip1 = (long) (p2 - EPSLN);
129
130 /* Stirling's interpolation formula (using 2nd Diff.)
131 ---------------------------------------------------*/
132 p2 -= (double) ip1;
133 *x = R * (xlr[ip1 + 2] + p2 * (xlr[ip1 + 3] - xlr[ip1 + 1]) / 2.0 +
134 p2 * p2 * (xlr[ip1 + 3] - 2.0 * xlr[ip1 + 2] + xlr[ip1 + 1])/2.0) *
135 dlon + false_easting;
136
137 if (lat >= 0)
138 *y = R * (pr[ip1 + 2] + p2 * (pr[ip1 + 3] - pr[ip1 +1]) / 2.0 + p2 * p2 *
139 (pr[ip1 + 3] - 2.0 * pr[ip1 + 2] + pr[ip1 + 1]) / 2.0) * PI / 2.0 +
140 false_northing;
141 else
142 *y = -R * (pr[ip1 + 2] + p2 * (pr[ip1 + 3] - pr[ip1 +1]) / 2.0 + p2 * p2 *
143 (pr[ip1 + 3] - 2.0 * pr[ip1 + 2] + pr[ip1 + 1]) / 2.0) * PI / 2.0 +
144 false_northing;
145
146 return(OK);
147 }