| 1 |
/******************************************************************************* |
| 2 |
NAME ROBINSON |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Robinson 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 REASON |
| 10 |
---------- ---- ------ |
| 11 |
T. Mittan March, 1993 Converted from FORTRAN to C. |
| 12 |
S. Nelson Nov, 1993 Changed number of iterations from 20 |
| 13 |
to 75. This seemed to give a valid |
| 14 |
Latitude with less fatal errors. |
| 15 |
|
| 16 |
This function was adapted from the Robinson projection code (FORTRAN) |
| 17 |
in the General Cartographic Transformation Package software which is |
| 18 |
available from the U.S. Geological Survey National Mapping Division. |
| 19 |
|
| 20 |
ALGORITHM REFERENCES |
| 21 |
|
| 22 |
1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder, |
| 23 |
The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355. |
| 24 |
|
| 25 |
2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 26 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 27 |
State Government Printing Office, Washington D.C., 1987. |
| 28 |
|
| 29 |
3. "Software Documentation for GCTP General Cartographic Transformation |
| 30 |
Package", U.S. Geological Survey National Mapping Division, May 1982. |
| 31 |
*******************************************************************************/ |
| 32 |
#include <stdio.h> |
| 33 |
#include "cproj.h" |
| 34 |
|
| 35 |
/* Variables common to all subroutines in this code file |
| 36 |
-----------------------------------------------------*/ |
| 37 |
static double lon_center; /* Center longitude (projection center) */ |
| 38 |
static double R; /* Radius of the earth (sphere) */ |
| 39 |
static double false_easting; /* x offset in meters */ |
| 40 |
static double false_northing; /* y offset in meters */ |
| 41 |
static double pr[21]; |
| 42 |
static double xlr[21]; |
| 43 |
|
| 44 |
/* Initialize the ROBINSON projection |
| 45 |
---------------------------------*/ |
| 46 |
int robinvint( |
| 47 |
double r, /* (I) Radius of the earth (sphere) */ |
| 48 |
double center_long, /* (I) Center longitude */ |
| 49 |
double false_east, /* x offset in meters */ |
| 50 |
double false_north) /* y offset in meters */ |
| 51 |
{ |
| 52 |
long i; |
| 53 |
|
| 54 |
/* Place parameters in static storage for common use |
| 55 |
-------------------------------------------------*/ |
| 56 |
R = r; |
| 57 |
lon_center = center_long; |
| 58 |
false_easting = false_east; |
| 59 |
false_northing = false_north; |
| 60 |
|
| 61 |
pr[1]= -0.062; |
| 62 |
xlr[1]=0.9986; |
| 63 |
pr[2]=0.0; |
| 64 |
xlr[2]=1.0; |
| 65 |
pr[3]=0.062; |
| 66 |
xlr[3]=0.9986; |
| 67 |
pr[4]=0.124; |
| 68 |
xlr[4]=0.9954; |
| 69 |
pr[5]=0.186; |
| 70 |
xlr[5]=0.99; |
| 71 |
pr[6]=0.248; |
| 72 |
xlr[6]=0.9822; |
| 73 |
pr[7]=0.31; |
| 74 |
xlr[7]=0.973; |
| 75 |
pr[8]=0.372; |
| 76 |
xlr[8]=0.96; |
| 77 |
pr[9]=0.434; |
| 78 |
xlr[9]=0.9427; |
| 79 |
pr[10]=0.4958; |
| 80 |
xlr[10]=0.9216; |
| 81 |
pr[11]=0.5571; |
| 82 |
xlr[11]=0.8962; |
| 83 |
pr[12]=0.6176; |
| 84 |
xlr[12]=0.8679; |
| 85 |
pr[13]=0.6769; |
| 86 |
xlr[13]=0.835; |
| 87 |
pr[14]=0.7346; |
| 88 |
xlr[14]=0.7986; |
| 89 |
pr[15]=0.7903; |
| 90 |
xlr[15]=0.7597; |
| 91 |
pr[16]=0.8435; |
| 92 |
xlr[16]=0.7186; |
| 93 |
pr[17]=0.8936; |
| 94 |
xlr[17]=0.6732; |
| 95 |
pr[18]=0.9394; |
| 96 |
xlr[18]=0.6213; |
| 97 |
pr[19]=0.9761; |
| 98 |
xlr[19]=0.5722; |
| 99 |
pr[20]=1.0; |
| 100 |
xlr[20]=0.5322; |
| 101 |
|
| 102 |
for (i = 0; i < 21; i++) |
| 103 |
xlr[i] *= 0.9858; |
| 104 |
|
| 105 |
/* Report parameters to the user |
| 106 |
-----------------------------*/ |
| 107 |
ptitle("ROBINSON"); |
| 108 |
radius(r); |
| 109 |
cenlon(center_long); |
| 110 |
offsetp(false_easting,false_northing); |
| 111 |
return(OK); |
| 112 |
} |
| 113 |
|
| 114 |
/* Robinson inverse equations--mapping x,y to lat/long |
| 115 |
------------------------------------------------------------*/ |
| 116 |
int robinv( |
| 117 |
double x, /* (O) X projection coordinate */ |
| 118 |
double y, /* (O) Y projection coordinate */ |
| 119 |
double *lon, /* (I) Longitude */ |
| 120 |
double *lat) /* (I) Latitude */ |
| 121 |
|
| 122 |
{ |
| 123 |
double yy; |
| 124 |
double p2; |
| 125 |
double u,v,t,c; |
| 126 |
double phid; |
| 127 |
double y1; |
| 128 |
long ip1; |
| 129 |
long i; |
| 130 |
|
| 131 |
|
| 132 |
/* Inverse equations |
| 133 |
-----------------*/ |
| 134 |
x -= false_easting; |
| 135 |
y -= false_northing; |
| 136 |
|
| 137 |
yy = 2.0 * y / PI / R; |
| 138 |
phid = yy * 90.0; |
| 139 |
p2 = fabs(phid / 5.0); |
| 140 |
ip1 = (long) (p2 - EPSLN); |
| 141 |
if (ip1 == 0) |
| 142 |
ip1 = 1; |
| 143 |
|
| 144 |
/* Stirling's interpolation formula as used in forward transformation is |
| 145 |
reversed for first estimation of LAT. from rectangular coordinates. LAT. |
| 146 |
is then adjusted by iteration until use of forward series provides correct |
| 147 |
value of Y within tolerance. |
| 148 |
---------------------------------------------------------------------------*/ |
| 149 |
for (i = 0;;) |
| 150 |
{ |
| 151 |
u = pr[ip1 + 3] - pr[ip1 + 1]; |
| 152 |
v = pr[ip1 + 3] - 2.0 * pr[ip1 + 2] + pr[ip1 + 1]; |
| 153 |
t = 2.0 * (fabs(yy) - pr[ip1 + 2]) / u; |
| 154 |
c = v / u; |
| 155 |
p2 = t * (1.0 - c * t * (1.0 - 2.0 * c * t)); |
| 156 |
|
| 157 |
if ((p2 >= 0.0) || (ip1 == 1)) |
| 158 |
{ |
| 159 |
if (y >= 0) |
| 160 |
phid = (p2 + (double) ip1 ) * 5.0; |
| 161 |
else |
| 162 |
phid = -(p2 + (double) ip1 ) * 5.0; |
| 163 |
|
| 164 |
do |
| 165 |
{ |
| 166 |
p2 = fabs(phid / 5.0); |
| 167 |
ip1 = (long) (p2 - EPSLN); |
| 168 |
p2 -= (double) ip1; |
| 169 |
|
| 170 |
if (y >= 0) |
| 171 |
y1 = R * (pr[ip1 +2] + p2 *(pr[ip1 + 3] - pr[ip1 +1]) / 2.0 + p2 |
| 172 |
* p2 * (pr[ip1 + 3] - 2.0 * pr[ip1 + 2] + pr[ip1 + 1])/2.0) |
| 173 |
* PI / 2.0; |
| 174 |
else |
| 175 |
y1 = -R * (pr[ip1 +2] + p2 *(pr[ip1 + 3] - pr[ip1 +1]) / 2.0 + p2 |
| 176 |
* p2 * (pr[ip1 + 3] - 2.0 * pr[ip1 + 2] + pr[ip1 + 1])/2.0) |
| 177 |
* PI / 2.0; |
| 178 |
phid += -180.0 * (y1 - y) / PI / R; |
| 179 |
i++; |
| 180 |
if (i > 75) |
| 181 |
{ |
| 182 |
p_error("Too many iterations in inverse","robinv-conv"); |
| 183 |
return(234); |
| 184 |
} |
| 185 |
} |
| 186 |
while (fabs(y1 - y) > .00001); |
| 187 |
break; |
| 188 |
} |
| 189 |
else |
| 190 |
{ |
| 191 |
ip1 -= 1; |
| 192 |
if (ip1 < 0) |
| 193 |
{ |
| 194 |
p_error("Too many iterations in inverse","robinv-conv"); |
| 195 |
return(234); |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
*lat = phid * .01745329252; |
| 200 |
|
| 201 |
/* calculate LONG. using final LAT. with transposed forward Stirling's |
| 202 |
interpolation formula. |
| 203 |
---------------------------------------------------------------------*/ |
| 204 |
*lon = lon_center + x / R / (xlr[ip1 + 2] + p2 * (xlr[ip1 + 3] - xlr[ip1 + 1]) |
| 205 |
/ 2.0 + p2 * p2 * (xlr[ip1 + 3] - 2.0 * xlr[ip1 + 2] + |
| 206 |
xlr[ip1 + 1]) / 2.0); |
| 207 |
*lon = adjust_lon(*lon); |
| 208 |
|
| 209 |
return(OK); |
| 210 |
} |