| 1 |
/******************************************************************************* |
| 2 |
NAME OBLIQUE MERCATOR (HOTINE) |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Oblique Mercator 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 Mar, 1993 |
| 12 |
|
| 13 |
ALGORITHM REFERENCES |
| 14 |
|
| 15 |
1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 16 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 17 |
State Government Printing Office, Washington D.C., 1987. |
| 18 |
|
| 19 |
2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections", |
| 20 |
U.S. Geological Survey Professional Paper 1453 , United State Government |
| 21 |
Printing Office, Washington D.C., 1989. |
| 22 |
*******************************************************************************/ |
| 23 |
#include <stdio.h> |
| 24 |
#include "cproj.h" |
| 25 |
|
| 26 |
/* Variables common to all subroutines in this code file |
| 27 |
-----------------------------------------------------*/ |
| 28 |
static double r_major; /* major axis */ |
| 29 |
static double r_minor; /* minor axis */ |
| 30 |
static double scale_factor; /* scale factor */ |
| 31 |
static double lon_origin; /* center longitude */ |
| 32 |
static double lat_origin; /* center latitude */ |
| 33 |
static double e,es; /* eccentricity constants */ |
| 34 |
static double false_northing; /* y offset in meters */ |
| 35 |
static double false_easting; /* x offset in meters */ |
| 36 |
static double sin_p20,cos_p20; /* sin and cos values */ |
| 37 |
static double bl; |
| 38 |
static double al; |
| 39 |
static double ts; |
| 40 |
static double d; |
| 41 |
static double el,u; |
| 42 |
static double singam,cosgam; |
| 43 |
static double sinaz,cosaz; |
| 44 |
|
| 45 |
|
| 46 |
/* Initialize the Oblique Mercator projection |
| 47 |
------------------------------------------*/ |
| 48 |
int omerinvint( |
| 49 |
double r_maj, /* major axis */ |
| 50 |
double r_min, /* minor axis */ |
| 51 |
double scale_fact, /* scale factor */ |
| 52 |
double azimuth, /* azimuth east of north */ |
| 53 |
double lon_orig, /* longitude of origin */ |
| 54 |
double lat_orig, /* center latitude */ |
| 55 |
double false_east, /* x offset in meters */ |
| 56 |
double false_north, /* y offset in meters */ |
| 57 |
double lon1, /* fist point to define central line */ |
| 58 |
double lat1, /* fist point to define central line */ |
| 59 |
double lon2, /* second point to define central line */ |
| 60 |
double lat2, /* second point to define central line */ |
| 61 |
long mode) /* which format type A or B */ |
| 62 |
{ |
| 63 |
double temp; /* temporary variable */ |
| 64 |
double con,com; |
| 65 |
double h,l,ts1,ts2; |
| 66 |
double j,p,dlon; |
| 67 |
double f,g,gama; |
| 68 |
double sinphi; |
| 69 |
|
| 70 |
/* Place parameters in static storage for common use |
| 71 |
-------------------------------------------------*/ |
| 72 |
r_major = r_maj; |
| 73 |
r_minor = r_min; |
| 74 |
scale_factor = scale_fact; |
| 75 |
lat_origin = lat_orig; |
| 76 |
false_northing = false_north; |
| 77 |
false_easting = false_east; |
| 78 |
|
| 79 |
temp = r_minor / r_major; |
| 80 |
es = 1.0 - SQUARE(temp); |
| 81 |
e = sqrt(es); |
| 82 |
|
| 83 |
tsincos(lat_origin,&sin_p20,&cos_p20); |
| 84 |
con = 1.0 - es * sin_p20 * sin_p20; |
| 85 |
com = sqrt(1.0 - es); |
| 86 |
bl = sqrt(1.0 + es * pow(cos_p20,4.0)/(1.0 - es)); |
| 87 |
al = r_major * bl * scale_factor * com / con; |
| 88 |
if (fabs(lat_origin) < EPSLN) |
| 89 |
{ |
| 90 |
ts = 1.0; |
| 91 |
d = 1.0; |
| 92 |
el = 1.0; |
| 93 |
} |
| 94 |
else |
| 95 |
{ |
| 96 |
ts = tsfnz(e,lat_origin,sin_p20); |
| 97 |
con = sqrt(con); |
| 98 |
d = bl * com / (cos_p20 * con); |
| 99 |
if ((d * d - 1.0) > 0.0) |
| 100 |
{ |
| 101 |
if (lat_origin >= 0.0) |
| 102 |
f = d + sqrt(d * d - 1.0); |
| 103 |
else |
| 104 |
f = d - sqrt(d * d - 1.0); |
| 105 |
} |
| 106 |
else |
| 107 |
f = d; |
| 108 |
el = f * pow(ts,bl); |
| 109 |
} |
| 110 |
|
| 111 |
/* Report parameters to the user that are the same for both formats |
| 112 |
---------------------------------------------------------------*/ |
| 113 |
ptitle("OBLIQUE MERCATOR (HOTINE)"); |
| 114 |
radius2(r_major, r_minor); |
| 115 |
genrpt(scale_factor,"Scale Factor at C. Meridian: "); |
| 116 |
offsetp(false_easting,false_northing); |
| 117 |
|
| 118 |
if (mode != 0) |
| 119 |
{ |
| 120 |
g = .5 * (f - 1.0/f); |
| 121 |
gama = asinz(sin(azimuth) / d); |
| 122 |
lon_origin = lon_orig - asinz(g * tan(gama))/bl; |
| 123 |
|
| 124 |
/* Report parameters common to format B |
| 125 |
-------------------------------------*/ |
| 126 |
genrpt(azimuth * R2D,"Azimuth of Central Line: "); |
| 127 |
cenlon(lon_origin); |
| 128 |
cenlat(lat_origin); |
| 129 |
|
| 130 |
con = fabs(lat_origin); |
| 131 |
if ((con > EPSLN) && (fabs(con - HALF_PI) > EPSLN)) |
| 132 |
{ |
| 133 |
tsincos(gama,&singam,&cosgam); |
| 134 |
tsincos(azimuth,&sinaz,&cosaz); |
| 135 |
if (lat_origin >= 0) |
| 136 |
u = (al / bl) * atan(sqrt(d*d - 1.0)/cosaz); |
| 137 |
else |
| 138 |
u = -(al / bl) * atan(sqrt(d*d - 1.0)/cosaz); |
| 139 |
} |
| 140 |
else |
| 141 |
{ |
| 142 |
p_error("Input data error","omer-init"); |
| 143 |
return(201); |
| 144 |
} |
| 145 |
} |
| 146 |
else |
| 147 |
{ |
| 148 |
sinphi = sin(lat1); |
| 149 |
ts1 = tsfnz(e,lat1,sinphi); |
| 150 |
sinphi = sin(lat2); |
| 151 |
ts2 = tsfnz(e,lat2,sinphi); |
| 152 |
h = pow(ts1,bl); |
| 153 |
l = pow(ts2,bl); |
| 154 |
f = el/h; |
| 155 |
g = .5 * (f - 1.0/f); |
| 156 |
j = (el * el - l * h)/(el * el + l * h); |
| 157 |
p = (l - h) / (l + h); |
| 158 |
dlon = lon1 - lon2; |
| 159 |
if (dlon < -PI) |
| 160 |
lon2 = lon2 - 2.0 * PI; |
| 161 |
if (dlon > PI) |
| 162 |
lon2 = lon2 + 2.0 * PI; |
| 163 |
dlon = lon1 - lon2; |
| 164 |
lon_origin = .5 * (lon1 + lon2) - atan(j * tan(.5 * bl * dlon)/p)/bl; |
| 165 |
dlon = adjust_lon(lon1 - lon_origin); |
| 166 |
gama = atan(sin(bl * dlon)/g); |
| 167 |
azimuth = asinz(d * sin(gama)); |
| 168 |
|
| 169 |
/* Report parameters common to format A |
| 170 |
-------------------------------------*/ |
| 171 |
genrpt(lon1 * R2D,"Longitude of First Point: "); |
| 172 |
genrpt(lat1 * R2D,"Latitude of First Point: "); |
| 173 |
genrpt(lon2 * R2D,"Longitude of Second Point: "); |
| 174 |
genrpt(lat2 * R2D,"Latitude of Second Point: "); |
| 175 |
|
| 176 |
if (fabs(lat1 - lat2) <= EPSLN) |
| 177 |
{ |
| 178 |
p_error("Input data error","omer-init"); |
| 179 |
return(202); |
| 180 |
} |
| 181 |
else |
| 182 |
con = fabs(lat1); |
| 183 |
if ((con <= EPSLN) || (fabs(con - HALF_PI) <= EPSLN)) |
| 184 |
{ |
| 185 |
p_error("Input data error","omer-init"); |
| 186 |
return(202); |
| 187 |
} |
| 188 |
else |
| 189 |
if (fabs(fabs(lat_origin) - HALF_PI) <= EPSLN) |
| 190 |
{ |
| 191 |
p_error("Input data error","omer-init"); |
| 192 |
return(202); |
| 193 |
} |
| 194 |
|
| 195 |
tsincos(gama,&singam,&cosgam); |
| 196 |
tsincos(azimuth,&sinaz,&cosaz); |
| 197 |
if (lat_origin >= 0) |
| 198 |
u = (al/bl) * atan(sqrt(d * d - 1.0)/cosaz); |
| 199 |
else |
| 200 |
u = -(al/bl) * atan(sqrt(d * d - 1.0)/cosaz); |
| 201 |
} |
| 202 |
return(OK); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
/* Oblique Mercator inverse equations--mapping x,y to lat/long |
| 207 |
----------------------------------------------------------*/ |
| 208 |
int omerinv( |
| 209 |
double x, /* (O) X projection coordinate */ |
| 210 |
double y, /* (O) Y projection coordinate */ |
| 211 |
double *lon, /* (I) Longitude */ |
| 212 |
double *lat) /* (I) Latitude */ |
| 213 |
{ |
| 214 |
double theta; /* angle */ |
| 215 |
double t; /* temporary values */ |
| 216 |
double con; /* cone constant, small m */ |
| 217 |
double vs,us,q,s,ts1; |
| 218 |
double vl,ul; |
| 219 |
long flag; |
| 220 |
|
| 221 |
/* Inverse equations |
| 222 |
-----------------*/ |
| 223 |
x -= false_easting; |
| 224 |
y -= false_northing; |
| 225 |
flag = 0; |
| 226 |
vs = x * cosaz - y * sinaz; |
| 227 |
us = y * cosaz + x * sinaz; |
| 228 |
us = us + u; |
| 229 |
q = exp(-bl * vs / al); |
| 230 |
s = .5 * (q - 1.0/q); |
| 231 |
t = .5 * (q + 1.0/q); |
| 232 |
vl = sin(bl * us / al); |
| 233 |
ul = (vl * cosgam + s * singam)/t; |
| 234 |
if (fabs(fabs(ul) - 1.0) <= EPSLN) |
| 235 |
{ |
| 236 |
*lon = lon_origin; |
| 237 |
if (ul >= 0.0) |
| 238 |
*lat = HALF_PI; |
| 239 |
else |
| 240 |
*lat = -HALF_PI; |
| 241 |
} |
| 242 |
else |
| 243 |
{ |
| 244 |
con = 1.0 / bl; |
| 245 |
ts1 = pow((el / sqrt((1.0 + ul) / (1.0 - ul))),con); |
| 246 |
*lat = phi2z(e,ts1,&flag); |
| 247 |
if (flag != 0) |
| 248 |
return(flag); |
| 249 |
con = cos(bl * us /al); |
| 250 |
theta = lon_origin - atan2((s * cosgam - vl * singam) , con)/bl; |
| 251 |
*lon = adjust_lon(theta); |
| 252 |
} |
| 253 |
return(OK); |
| 254 |
} |