| 1 |
/******************************************************************************* |
| 2 |
NAME ALBERS CONICAL EQUAL-AREA |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Albers Conical Equal Area 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, Feb, 1992 |
| 12 |
S. Nelson Feb, 1996 Made a modification to the |
| 13 |
assignment to "con" enclosing the |
| 14 |
section 1.0 - e3 in parenthesis. |
| 15 |
|
| 16 |
ALGORITHM REFERENCES |
| 17 |
|
| 18 |
1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 19 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 20 |
State Government Printing Office, Washington D.C., 1987. |
| 21 |
|
| 22 |
2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections", |
| 23 |
U.S. Geological Survey Professional Paper 1453 , United State Government |
| 24 |
Printing Office, Washington D.C., 1989. |
| 25 |
*******************************************************************************/ |
| 26 |
#include <stdio.h> |
| 27 |
#include "cproj.h" |
| 28 |
|
| 29 |
/* Variables common to all subroutines in this code file |
| 30 |
-----------------------------------------------------*/ |
| 31 |
static double r_major; /* major axis */ |
| 32 |
static double r_minor; /* minor axis */ |
| 33 |
static double c; /* constant c */ |
| 34 |
static double e3; /* eccentricity */ |
| 35 |
static double es; /* eccentricity squared */ |
| 36 |
static double rh; /* heigth above elipsoid */ |
| 37 |
static double ns0; /* ratio between meridians */ |
| 38 |
static double lon_center; /* center longitude */ |
| 39 |
static double false_easting; /* x offset in meters */ |
| 40 |
static double false_northing; /* y offset in meters */ |
| 41 |
|
| 42 |
/* Initialize the Albers projection |
| 43 |
-------------------------------*/ |
| 44 |
int alberinvint( |
| 45 |
double r_maj, /* major axis */ |
| 46 |
double r_min, /* minor axis */ |
| 47 |
double lat1, /* first standard parallel */ |
| 48 |
double lat2, /* second standard parallel */ |
| 49 |
double lon0, /* center longitude */ |
| 50 |
double lat0, /* center lattitude */ |
| 51 |
double false_east, /* x offset in meters */ |
| 52 |
double false_north) /* y offset in meters */ |
| 53 |
{ |
| 54 |
double sin_po,cos_po; /* sine and cos values */ |
| 55 |
double con; /* temporary variable */ |
| 56 |
double temp; /* temporary variable */ |
| 57 |
double ms1; /* small m 1 */ |
| 58 |
double ms2; /* small m 2 */ |
| 59 |
double qs0; /* small q 0 */ |
| 60 |
double qs1; /* small q 1 */ |
| 61 |
double qs2; /* small q 2 */ |
| 62 |
|
| 63 |
false_easting = false_east; |
| 64 |
false_northing = false_north; |
| 65 |
lon_center = lon0; |
| 66 |
if (fabs(lat1 + lat2) < EPSLN) |
| 67 |
{ |
| 68 |
p_error("Equal latitudes for Standard Parallels on opposite sides of equator" |
| 69 |
,"alber-invinit"); |
| 70 |
return(31); |
| 71 |
} |
| 72 |
r_major = r_maj; |
| 73 |
r_minor = r_min; |
| 74 |
temp = r_minor / r_major; |
| 75 |
es = 1.0 - SQUARE(temp); |
| 76 |
e3 = sqrt(es); |
| 77 |
|
| 78 |
tsincos(lat1, &sin_po, &cos_po); |
| 79 |
con = sin_po; |
| 80 |
|
| 81 |
ms1 = msfnz(e3,sin_po,cos_po); |
| 82 |
qs1 = qsfnz(e3,sin_po,cos_po); |
| 83 |
|
| 84 |
tsincos(lat2,&sin_po,&cos_po); |
| 85 |
|
| 86 |
ms2 = msfnz(e3,sin_po,cos_po); |
| 87 |
qs2 = qsfnz(e3,sin_po,cos_po); |
| 88 |
|
| 89 |
tsincos(lat0,&sin_po,&cos_po); |
| 90 |
|
| 91 |
qs0 = qsfnz(e3,sin_po,cos_po); |
| 92 |
|
| 93 |
if (fabs(lat1 - lat2) > EPSLN) |
| 94 |
ns0 = (ms1 * ms1 - ms2 *ms2)/ (qs2 - qs1); |
| 95 |
else |
| 96 |
ns0 = con; |
| 97 |
c = ms1 * ms1 + ns0 * qs1; |
| 98 |
rh = r_major * sqrt(c - ns0 * qs0)/ns0; |
| 99 |
|
| 100 |
/* Report parameters to the user |
| 101 |
-----------------------------*/ |
| 102 |
ptitle("ALBERS CONICAL EQUAL-AREA"); |
| 103 |
radius2(r_major, r_minor); |
| 104 |
stanparl(lat1,lat2); |
| 105 |
cenlonmer(lon_center); |
| 106 |
origin(lat0); |
| 107 |
offsetp(false_easting,false_northing); |
| 108 |
|
| 109 |
return(OK); |
| 110 |
} |
| 111 |
|
| 112 |
/* Albers Conical Equal Area inverse equations--mapping x,y to lat/long |
| 113 |
-------------------------------------------------------------------*/ |
| 114 |
int alberinv( |
| 115 |
double x, /* (O) X projection coordinate */ |
| 116 |
double y, /* (O) Y projection coordinate */ |
| 117 |
double *lon, /* (I) Longitude */ |
| 118 |
double *lat) /* (I) Latitude */ |
| 119 |
{ |
| 120 |
double rh1; /* height above ellipsoid */ |
| 121 |
double qs; /* function q */ |
| 122 |
double con; /* temporary sign value */ |
| 123 |
double theta; /* angle */ |
| 124 |
long flag; /* error flag; */ |
| 125 |
|
| 126 |
|
| 127 |
flag = 0; |
| 128 |
x -= false_easting; |
| 129 |
y = rh - y + false_northing;; |
| 130 |
if (ns0 >= 0) |
| 131 |
{ |
| 132 |
rh1 = sqrt(x * x + y * y); |
| 133 |
con = 1.0; |
| 134 |
} |
| 135 |
else |
| 136 |
{ |
| 137 |
rh1 = -sqrt(x * x + y * y); |
| 138 |
con = -1.0; |
| 139 |
} |
| 140 |
theta = 0.0; |
| 141 |
if (rh1 != 0.0) |
| 142 |
theta = atan2(con * x, con * y); |
| 143 |
con = rh1 * ns0 / r_major; |
| 144 |
qs = (c - con * con) / ns0; |
| 145 |
if (e3 >= 1e-10) |
| 146 |
{ |
| 147 |
con = 1 - .5 * (1.0 - es) * log((1.0 - e3) / (1.0 + e3))/e3; |
| 148 |
if (fabs(fabs(con) - fabs(qs)) > .0000000001 ) |
| 149 |
{ |
| 150 |
*lat = phi1z(e3,qs,&flag); |
| 151 |
if (flag != 0) |
| 152 |
return(flag); |
| 153 |
} |
| 154 |
else |
| 155 |
{ |
| 156 |
if (qs >= 0) |
| 157 |
*lat = .5 * PI; |
| 158 |
else |
| 159 |
*lat = -.5 * PI; |
| 160 |
} |
| 161 |
} |
| 162 |
else |
| 163 |
{ |
| 164 |
*lat = phi1z(e3,qs,&flag); |
| 165 |
if (flag != 0) |
| 166 |
return(flag); |
| 167 |
} |
| 168 |
|
| 169 |
*lon = adjust_lon(theta/ns0 + lon_center); |
| 170 |
|
| 171 |
return(OK); |
| 172 |
} |