| 1 |
/******************************************************************************* |
| 2 |
NAME OBLIQUE MERCATOR (HOTINE) |
| 3 |
|
| 4 |
PURPOSE: Transforms input longitude and latitude to Easting and |
| 5 |
Northing for the Oblique Mercator 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 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 d; |
| 40 |
static double el,u; |
| 41 |
static double singam,cosgam; |
| 42 |
static double sinaz,cosaz; |
| 43 |
|
| 44 |
|
| 45 |
/* Initialize the Oblique Mercator projection |
| 46 |
------------------------------------------*/ |
| 47 |
int omerforint( |
| 48 |
double r_maj, /* major axis */ |
| 49 |
double r_min, /* minor axis */ |
| 50 |
double scale_fact, /* scale factor */ |
| 51 |
double azimuth, /* azimuth east of north */ |
| 52 |
double lon_orig, /* longitude of origin */ |
| 53 |
double lat_orig, /* center latitude */ |
| 54 |
double false_east, /* x offset in meters */ |
| 55 |
double false_north, /* y offset in meters */ |
| 56 |
double lon1, /* fist point to define central line */ |
| 57 |
double lat1, /* fist point to define central line */ |
| 58 |
double lon2, /* second point to define central line */ |
| 59 |
double lat2, /* second point to define central line */ |
| 60 |
long mode) /* which format type A or B */ |
| 61 |
{ |
| 62 |
double temp; /* temporary variable */ |
| 63 |
double con,com; |
| 64 |
double ts; |
| 65 |
double ts1,ts2; |
| 66 |
double h,l; |
| 67 |
double j,p,dlon; |
| 68 |
double f,g,gama; |
| 69 |
double sinphi; |
| 70 |
|
| 71 |
/* Place parameters in static storage for common use |
| 72 |
-------------------------------------------------*/ |
| 73 |
r_major = r_maj; |
| 74 |
r_minor = r_min; |
| 75 |
scale_factor = scale_fact; |
| 76 |
lat_origin = lat_orig; |
| 77 |
false_northing = false_north; |
| 78 |
false_easting = false_east; |
| 79 |
|
| 80 |
temp = r_minor / r_major; |
| 81 |
es = 1.0 - SQUARE(temp); |
| 82 |
e = sqrt(es); |
| 83 |
|
| 84 |
tsincos(lat_origin,&sin_p20,&cos_p20); |
| 85 |
con = 1.0 - es * sin_p20 * sin_p20; |
| 86 |
com = sqrt(1.0 - es); |
| 87 |
bl = sqrt(1.0 + es * pow(cos_p20,4.0)/(1.0 - es)); |
| 88 |
al = r_major * bl * scale_factor * com / con; |
| 89 |
if (fabs(lat_origin) < EPSLN) |
| 90 |
{ |
| 91 |
ts = 1.0; |
| 92 |
d = 1.0; |
| 93 |
el = 1.0; |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
ts = tsfnz(e,lat_origin,sin_p20); |
| 98 |
con = sqrt(con); |
| 99 |
d = bl * com / (cos_p20 * con); |
| 100 |
if ((d * d - 1.0) > 0.0) |
| 101 |
{ |
| 102 |
if (lat_origin >= 0.0) |
| 103 |
f = d + sqrt(d * d - 1.0); |
| 104 |
else |
| 105 |
f = d - sqrt(d * d - 1.0); |
| 106 |
} |
| 107 |
else |
| 108 |
f = d; |
| 109 |
el = f * pow(ts,bl); |
| 110 |
} |
| 111 |
|
| 112 |
/* Report parameters to the user that are the same for both formats |
| 113 |
---------------------------------------------------------------*/ |
| 114 |
ptitle("OBLIQUE MERCATOR (HOTINE)"); |
| 115 |
radius2(r_major, r_minor); |
| 116 |
genrpt(scale_factor,"Scale Factor at C. Meridian: "); |
| 117 |
offsetp(false_easting,false_northing); |
| 118 |
|
| 119 |
if (mode != 0) |
| 120 |
{ |
| 121 |
g = .5 * (f - 1.0/f); |
| 122 |
gama = asinz(sin(azimuth) / d); |
| 123 |
lon_origin = lon_orig - asinz(g * tan(gama))/bl; |
| 124 |
|
| 125 |
/* Report parameters common to format B |
| 126 |
-------------------------------------*/ |
| 127 |
genrpt(azimuth * R2D,"Azimuth of Central Line: "); |
| 128 |
cenlon(lon_origin); |
| 129 |
cenlat(lat_origin); |
| 130 |
|
| 131 |
con = fabs(lat_origin); |
| 132 |
if ((con > EPSLN) && (fabs(con - HALF_PI) > EPSLN)) |
| 133 |
{ |
| 134 |
tsincos(gama,&singam,&cosgam); |
| 135 |
tsincos(azimuth,&sinaz,&cosaz); |
| 136 |
if (lat_origin >= 0) |
| 137 |
u = (al / bl) * atan(sqrt(d*d - 1.0)/cosaz); |
| 138 |
else |
| 139 |
u = -(al / bl) * atan(sqrt(d*d - 1.0)/cosaz); |
| 140 |
} |
| 141 |
else |
| 142 |
{ |
| 143 |
p_error("Input data error","omer-init"); |
| 144 |
return(201); |
| 145 |
} |
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
sinphi = sin(lat1); |
| 150 |
ts1 = tsfnz(e,lat1,sinphi); |
| 151 |
sinphi = sin(lat2); |
| 152 |
ts2 = tsfnz(e,lat2,sinphi); |
| 153 |
h = pow(ts1,bl); |
| 154 |
l = pow(ts2,bl); |
| 155 |
f = el/h; |
| 156 |
g = .5 * (f - 1.0/f); |
| 157 |
j = (el * el - l * h)/(el * el + l * h); |
| 158 |
p = (l - h) / (l + h); |
| 159 |
dlon = lon1 - lon2; |
| 160 |
if (dlon < -PI) |
| 161 |
lon2 = lon2 - 2.0 * PI; |
| 162 |
if (dlon > PI) |
| 163 |
lon2 = lon2 + 2.0 * PI; |
| 164 |
dlon = lon1 - lon2; |
| 165 |
lon_origin = .5 * (lon1 + lon2) - atan(j * tan(.5 * bl * dlon)/p)/bl; |
| 166 |
dlon = adjust_lon(lon1 - lon_origin); |
| 167 |
gama = atan(sin(bl * dlon)/g); |
| 168 |
azimuth = asinz(d * sin(gama)); |
| 169 |
|
| 170 |
/* Report parameters common to format A |
| 171 |
-------------------------------------*/ |
| 172 |
genrpt(lon1 * R2D,"Longitude of First Point: "); |
| 173 |
genrpt(lat1 * R2D,"Latitude of First Point: "); |
| 174 |
genrpt(lon2 * R2D,"Longitude of Second Point: "); |
| 175 |
genrpt(lat2 * R2D,"Latitude of Second Point: "); |
| 176 |
|
| 177 |
if (fabs(lat1 - lat2) <= EPSLN) |
| 178 |
{ |
| 179 |
p_error("Input data error","omer-init"); |
| 180 |
return(202); |
| 181 |
} |
| 182 |
else |
| 183 |
con = fabs(lat1); |
| 184 |
if ((con <= EPSLN) || (fabs(con - HALF_PI) <= EPSLN)) |
| 185 |
{ |
| 186 |
p_error("Input data error","omer-init"); |
| 187 |
return(202); |
| 188 |
} |
| 189 |
else |
| 190 |
if (fabs(fabs(lat_origin) - HALF_PI) <= EPSLN) |
| 191 |
{ |
| 192 |
p_error("Input data error","omer-init"); |
| 193 |
return(202); |
| 194 |
} |
| 195 |
|
| 196 |
tsincos(gama,&singam,&cosgam); |
| 197 |
tsincos(azimuth,&sinaz,&cosaz); |
| 198 |
if (lat_origin >= 0) |
| 199 |
u = (al/bl) * atan(sqrt(d * d - 1.0)/cosaz); |
| 200 |
else |
| 201 |
u = -(al/bl) * atan(sqrt(d * d - 1.0)/cosaz); |
| 202 |
} |
| 203 |
return(OK); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
/* Oblique Mercator forward equations--mapping lat,long to x,y |
| 208 |
----------------------------------------------------------*/ |
| 209 |
int omerfor( |
| 210 |
double lon, /* (I) Longitude */ |
| 211 |
double lat, /* (I) Latitude */ |
| 212 |
double *x, /* (O) X projection coordinate */ |
| 213 |
double *y) /* (O) Y projection coordinate */ |
| 214 |
{ |
| 215 |
double sin_phi; /* sin */ |
| 216 |
double t; /* temporary values */ |
| 217 |
double con; /* cone constant, small m */ |
| 218 |
double q,us,vl; |
| 219 |
double ul,vs; |
| 220 |
double s; |
| 221 |
double dlon; |
| 222 |
double ts1; |
| 223 |
|
| 224 |
/* Forward equations |
| 225 |
-----------------*/ |
| 226 |
sin_phi = sin(lat); |
| 227 |
dlon = adjust_lon(lon - lon_origin); |
| 228 |
vl = sin(bl * dlon); |
| 229 |
if (fabs(fabs(lat) - HALF_PI) > EPSLN) |
| 230 |
{ |
| 231 |
ts1 = tsfnz(e,lat,sin_phi); |
| 232 |
q = el / (pow(ts1,bl)); |
| 233 |
s = .5 * (q - 1.0 / q); |
| 234 |
t = .5 * (q + 1.0/ q); |
| 235 |
ul = (s * singam - vl * cosgam) / t; |
| 236 |
con = cos(bl * dlon); |
| 237 |
if (fabs(con) < .0000001) |
| 238 |
{ |
| 239 |
us = al * bl * dlon; |
| 240 |
} |
| 241 |
else |
| 242 |
{ |
| 243 |
us = al * atan((s * cosgam + vl * singam) / con)/bl; |
| 244 |
if (con < 0) |
| 245 |
us = us + PI * al / bl; |
| 246 |
} |
| 247 |
} |
| 248 |
else |
| 249 |
{ |
| 250 |
if (lat >= 0) |
| 251 |
ul = singam; |
| 252 |
else |
| 253 |
ul = -singam; |
| 254 |
us = al * lat / bl; |
| 255 |
} |
| 256 |
if (fabs(fabs(ul) - 1.0) <= EPSLN) |
| 257 |
{ |
| 258 |
p_error("Point projects into infinity","omer-for"); |
| 259 |
return(205); |
| 260 |
} |
| 261 |
vs = .5 * al * log((1.0 - ul)/(1.0 + ul)) / bl; |
| 262 |
us = us - u; |
| 263 |
*x = false_easting + vs * cosaz + us * sinaz; |
| 264 |
*y = false_northing + us * cosaz - vs * sinaz; |
| 265 |
|
| 266 |
return(OK); |
| 267 |
} |