| 1 |
/******************************************************************************* |
| 2 |
NAME ALASKA CONFORMAL |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Alaska Conformal 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 |
| 10 |
---------- ---- |
| 11 |
T. Mittan March, 1993 |
| 12 |
|
| 13 |
This function was adapted from the Alaska Conformal projection code |
| 14 |
(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 r_major; /* major axis */ |
| 35 |
static double r_minor; /* minor axis */ |
| 36 |
static double lon_center; /* Center longitude (projection center) */ |
| 37 |
static double lat_center; /* center latitude */ |
| 38 |
static double false_easting; /* x offset in meters */ |
| 39 |
static double false_northing; /* y offset in meters */ |
| 40 |
static double acoef[7]; |
| 41 |
static double bcoef[7]; |
| 42 |
static double sin_p26; |
| 43 |
static double cos_p26; |
| 44 |
static double e; |
| 45 |
static long n; |
| 46 |
|
| 47 |
/* Initialize the ALASKA CONFORMAL projection |
| 48 |
-----------------------------------------*/ |
| 49 |
int alconinvint( |
| 50 |
double r_maj, /* Major axis */ |
| 51 |
double r_min, /* Minor axis */ |
| 52 |
double false_east, /* x offset in meters */ |
| 53 |
double false_north) /* y offset in meters */ |
| 54 |
{ |
| 55 |
double es; |
| 56 |
double chi; |
| 57 |
double esphi; |
| 58 |
|
| 59 |
/* Place parameters in static storage for common use |
| 60 |
-------------------------------------------------*/ |
| 61 |
r_major = r_maj; |
| 62 |
r_minor = r_min; |
| 63 |
false_easting = false_east; |
| 64 |
false_northing = false_north; |
| 65 |
lon_center = -152.0 * D2R; |
| 66 |
lat_center = 64.0 * D2R; |
| 67 |
n = 6; |
| 68 |
|
| 69 |
es = .006768657997291094; |
| 70 |
e = sqrt(es); |
| 71 |
|
| 72 |
acoef[1]= 0.9945303; |
| 73 |
acoef[2]= 0.0052083; |
| 74 |
acoef[3]= 0.0072721; |
| 75 |
acoef[4]= -0.0151089; |
| 76 |
acoef[5]= 0.0642675; |
| 77 |
acoef[6]= 0.3582802; |
| 78 |
bcoef[1]= 0.0; |
| 79 |
bcoef[2]= -.0027404; |
| 80 |
bcoef[3]= 0.0048181; |
| 81 |
bcoef[4]= -0.1932526; |
| 82 |
bcoef[5]= -0.1381226; |
| 83 |
bcoef[6]= -0.2884586; |
| 84 |
esphi = e * sin(lat_center); |
| 85 |
chi = 2.0 * atan(tan((HALF_PI + lat_center)/2.0) * |
| 86 |
pow(((1.0 - esphi)/(1.0 + esphi)),(e/2.0))) - HALF_PI; |
| 87 |
tsincos(chi,&sin_p26,&cos_p26); |
| 88 |
|
| 89 |
|
| 90 |
/* Report parameters to the user |
| 91 |
-----------------------------*/ |
| 92 |
ptitle("ALASKA CONFORMAL"); |
| 93 |
radius2(r_major,r_minor); |
| 94 |
cenlon(lon_center); |
| 95 |
cenlat(lat_center); |
| 96 |
offsetp(false_easting,false_northing); |
| 97 |
return(OK); |
| 98 |
} |
| 99 |
|
| 100 |
/* ALASKA CONFORMAL inverse equations--mapping x,y to lat/long |
| 101 |
----------------------------------------------------------*/ |
| 102 |
int alconinv( |
| 103 |
double x, /* (O) X projection coordinate */ |
| 104 |
double y, /* (O) Y projection coordinate */ |
| 105 |
double *lon, /* (I) Longitude */ |
| 106 |
double *lat) /* (I) Latitude */ |
| 107 |
|
| 108 |
{ |
| 109 |
double esphi; |
| 110 |
double r; |
| 111 |
double s; |
| 112 |
double br; |
| 113 |
double bi; |
| 114 |
double ai; |
| 115 |
double ar; |
| 116 |
double ci; |
| 117 |
double cr; |
| 118 |
double di; |
| 119 |
double dr; |
| 120 |
double arn; |
| 121 |
double ain; |
| 122 |
double crn; |
| 123 |
double cin; |
| 124 |
double fxyr; |
| 125 |
double fxyi; |
| 126 |
double fpxyr; |
| 127 |
double fpxyi; |
| 128 |
double xp,yp; |
| 129 |
double den; |
| 130 |
double dxp; |
| 131 |
double dyp; |
| 132 |
double ds; |
| 133 |
double z; |
| 134 |
double cosz; |
| 135 |
double sinz; |
| 136 |
double rh; |
| 137 |
double chi; |
| 138 |
double dphi; |
| 139 |
double phi; |
| 140 |
long j; |
| 141 |
long nn; |
| 142 |
|
| 143 |
/* Inverse equations |
| 144 |
-----------------*/ |
| 145 |
x = (x - false_easting) / r_major; |
| 146 |
y = (y - false_northing) / r_major; |
| 147 |
xp = x; |
| 148 |
yp = y; |
| 149 |
nn = 0; |
| 150 |
|
| 151 |
/* Use Knuth algorithm for summing complex terms, to convert Modified- |
| 152 |
Stereographic conformal to Oblique Stereographic coordinates. |
| 153 |
--------------------------------------------------------------------*/ |
| 154 |
do |
| 155 |
{ |
| 156 |
r = xp + xp; |
| 157 |
s = xp * xp + yp * yp; |
| 158 |
ar = acoef[n]; |
| 159 |
ai = bcoef[n]; |
| 160 |
br = acoef[n -1]; |
| 161 |
bi = bcoef[n - 1]; |
| 162 |
cr = (double) (n) * ar; |
| 163 |
ci = (double) (n) * ai; |
| 164 |
dr = (double) (n -1) * br; |
| 165 |
di = (double) (n -1) * bi; |
| 166 |
|
| 167 |
for (j = 2; j <= n; j++) |
| 168 |
{ |
| 169 |
arn = br + r * ar; |
| 170 |
ain = bi + r * ai; |
| 171 |
if (j < n) |
| 172 |
{ |
| 173 |
br = acoef[n -j] - s * ar; |
| 174 |
bi = bcoef[n - j] - s * ai; |
| 175 |
ar = arn; |
| 176 |
ai = ain; |
| 177 |
crn = dr + r * cr; |
| 178 |
cin = di + r * ci; |
| 179 |
dr = (double) (n - j) * acoef[n -j] - s * cr; |
| 180 |
di = (double) (n - j) * bcoef[n -j] - s * ci; |
| 181 |
cr = crn; |
| 182 |
ci = cin; |
| 183 |
} |
| 184 |
} |
| 185 |
br = -s * ar; |
| 186 |
bi = -s * ai; |
| 187 |
ar = arn; |
| 188 |
ai = ain; |
| 189 |
fxyr = xp * ar - yp * ai + br - x; |
| 190 |
fxyi = yp * ar + xp * ai + bi - y; |
| 191 |
fpxyr = xp * cr - yp * ci + dr; |
| 192 |
fpxyi = yp * cr + xp * ci + ci; |
| 193 |
den = fpxyr * fpxyr + fpxyi * fpxyi; |
| 194 |
dxp = -(fxyr * fpxyr + fxyi * fpxyi) / den; |
| 195 |
dyp = -(fxyi * fpxyr - fxyr * fpxyi) / den; |
| 196 |
xp = xp + dxp; |
| 197 |
yp = yp + dyp; |
| 198 |
ds = fabs(dxp) + fabs(dyp); |
| 199 |
nn++; |
| 200 |
if (nn > 20) |
| 201 |
{ |
| 202 |
p_error("Too many iterations in inverse","alcon-inv"); |
| 203 |
return(235); |
| 204 |
} |
| 205 |
} |
| 206 |
while (ds > EPSLN); |
| 207 |
|
| 208 |
/* convert Oblique Stereographic coordinates to LAT/LONG |
| 209 |
------------------------------------------------------*/ |
| 210 |
rh = sqrt(xp * xp + yp * yp); |
| 211 |
z = 2.0 * atan(rh / 2.0); |
| 212 |
tsincos(z,&sinz,&cosz); |
| 213 |
*lon = lon_center; |
| 214 |
if (fabs(rh) <= EPSLN) |
| 215 |
{ |
| 216 |
*lat = lat_center; |
| 217 |
return(OK); |
| 218 |
} |
| 219 |
chi = asinz(cosz * sin_p26 + (yp * sinz * cos_p26) / rh); |
| 220 |
nn = 0; |
| 221 |
phi = chi; |
| 222 |
do |
| 223 |
{ |
| 224 |
esphi = e * sin(phi); |
| 225 |
dphi = 2.0 * atan(tan((HALF_PI + chi) / 2.0) * |
| 226 |
pow(((1.0 + esphi) / (1.0 - esphi)),(e / 2.0))) - HALF_PI - phi; |
| 227 |
phi += dphi; |
| 228 |
nn++; |
| 229 |
if (nn > 20) |
| 230 |
{ |
| 231 |
p_error("Too many iterations in inverse","alcon-inv"); |
| 232 |
return(236); |
| 233 |
} |
| 234 |
} |
| 235 |
while(fabs(dphi) > EPSLN); |
| 236 |
|
| 237 |
*lat = phi; |
| 238 |
*lon = adjust_lon (lon_center + atan2((xp * sinz), (rh * cos_p26 * cosz - yp * |
| 239 |
sin_p26 * sinz))); |
| 240 |
|
| 241 |
|
| 242 |
return(OK); |
| 243 |
} |