| 1 |
/******************************************************************************* |
| 2 |
NAME UNIVERSAL TRANSVERSE MERCATOR |
| 3 |
|
| 4 |
PURPOSE: Transforms input longitude and latitude to Easting and |
| 5 |
Northing for the Universal Transverse Mercator projection. |
| 6 |
The longitude and latitude must be in radians. The Easting |
| 7 |
and Northing values will be returned in meters. |
| 8 |
|
| 9 |
PROGRAMMER DATE REASON |
| 10 |
---------- ---- ------ |
| 11 |
D. Steinwand, EROS Nov, 1991 |
| 12 |
T. Mittan Mar, 1993 |
| 13 |
S. Nelson Feb, 1995 Divided tmfor.c into two files, one |
| 14 |
for UTM (utmfor.c) and one for |
| 15 |
TM (tmfor.c). This was a |
| 16 |
necessary change to run forward |
| 17 |
projection conversions for both |
| 18 |
UTM and TM in the same process. |
| 19 |
|
| 20 |
ALGORITHM REFERENCES |
| 21 |
|
| 22 |
1. 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 |
2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections", |
| 27 |
U.S. Geological Survey Professional Paper 1453 , United State Government |
| 28 |
Printing Office, Washington D.C., 1989. |
| 29 |
*******************************************************************************/ |
| 30 |
#include <stdio.h> |
| 31 |
#include <stdlib.h> |
| 32 |
#include "cproj.h" |
| 33 |
|
| 34 |
/* Variables common to all subroutines in this code file |
| 35 |
-----------------------------------------------------*/ |
| 36 |
static double r_major; /* major axis */ |
| 37 |
static double r_minor; /* minor axis */ |
| 38 |
static double scale_factor; /* scale factor */ |
| 39 |
static double lon_center; /* Center longitude (projection center) */ |
| 40 |
static double lat_origin; /* center latitude */ |
| 41 |
static double e0,e1,e2,e3; /* eccentricity constants */ |
| 42 |
static double es,esp; /* eccentricity constants */ |
| 43 |
static double ml0; /* small value m */ |
| 44 |
static double false_northing; /* y offset in meters */ |
| 45 |
static double false_easting; /* x offset in meters */ |
| 46 |
static double ind; /* spherical flag */ |
| 47 |
|
| 48 |
/* Initialize the Universal Transverse Mercator (UTM) projection |
| 49 |
-------------------------------------------------------------*/ |
| 50 |
int utmforint( |
| 51 |
double r_maj, /* major axis */ |
| 52 |
double r_min, /* minor axis */ |
| 53 |
double scale_fact, /* scale factor */ |
| 54 |
long zone) /* zone number */ |
| 55 |
{ |
| 56 |
double temp; /* temporary variable */ |
| 57 |
|
| 58 |
if ((labs(zone) < 1) || (labs(zone) > 60)) |
| 59 |
{ |
| 60 |
p_error("Illegal zone number","utm-forint"); |
| 61 |
return(11); |
| 62 |
} |
| 63 |
r_major = r_maj; |
| 64 |
r_minor = r_min; |
| 65 |
scale_factor = scale_fact; |
| 66 |
lat_origin = 0.0; |
| 67 |
lon_center = ((6 * labs(zone)) - 183) * D2R; |
| 68 |
false_easting = 500000.0; |
| 69 |
false_northing = (zone < 0) ? 10000000.0 : 0.0; |
| 70 |
|
| 71 |
temp = r_minor / r_major; |
| 72 |
es = 1.0 - SQUARE(temp); |
| 73 |
e0 = e0fn(es); |
| 74 |
e1 = e1fn(es); |
| 75 |
e2 = e2fn(es); |
| 76 |
e3 = e3fn(es); |
| 77 |
ml0 = r_major * mlfn(e0, e1, e2, e3, lat_origin); |
| 78 |
esp = es / (1.0 - es); |
| 79 |
|
| 80 |
if (es < .00001) |
| 81 |
ind = 1; |
| 82 |
|
| 83 |
/* Report parameters to the user |
| 84 |
-----------------------------*/ |
| 85 |
ptitle("UNIVERSAL TRANSVERSE MERCATOR (UTM)"); |
| 86 |
genrpt_long(zone, "Zone: "); |
| 87 |
radius2(r_major, r_minor); |
| 88 |
genrpt(scale_factor,"Scale Factor at C. Meridian: "); |
| 89 |
cenlonmer(lon_center); |
| 90 |
return(OK); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
/* Universal Transverse Mercator forward equations--mapping lat,long to x,y |
| 95 |
Note: The algorithm for UTM is exactly the same as TM and therefore |
| 96 |
if a change is implemented, also make the change to TMFOR.c |
| 97 |
-----------------------------------------------------------------------*/ |
| 98 |
int utmfor( |
| 99 |
double lon, /* (I) Longitude */ |
| 100 |
double lat, /* (I) Latitude */ |
| 101 |
double *x, /* (O) X projection coordinate */ |
| 102 |
double *y) /* (O) Y projection coordinate */ |
| 103 |
{ |
| 104 |
double delta_lon; /* Delta longitude (Given longitude - center */ |
| 105 |
double sin_phi, cos_phi;/* sin and cos value */ |
| 106 |
double al, als; /* temporary values */ |
| 107 |
double b; /* temporary values */ |
| 108 |
double c, t, tq; /* temporary values */ |
| 109 |
double con, n, ml; /* cone constant, small m */ |
| 110 |
|
| 111 |
/* Forward equations |
| 112 |
-----------------*/ |
| 113 |
delta_lon = adjust_lon(lon - lon_center); |
| 114 |
tsincos(lat, &sin_phi, &cos_phi); |
| 115 |
|
| 116 |
/* This part was in the fortran code and is for the spherical form |
| 117 |
----------------------------------------------------------------*/ |
| 118 |
if (ind != 0) |
| 119 |
{ |
| 120 |
b = cos_phi * sin(delta_lon); |
| 121 |
if ((fabs(fabs(b) - 1.0)) < .0000000001) |
| 122 |
{ |
| 123 |
p_error("Point projects into infinity","utm-for"); |
| 124 |
return(93); |
| 125 |
} |
| 126 |
else |
| 127 |
{ |
| 128 |
*x = .5 * r_major * scale_factor * log((1.0 + b)/(1.0 - b)); |
| 129 |
con = acos(cos_phi * cos(delta_lon)/sqrt(1.0 - b*b)); |
| 130 |
if (lat < 0) |
| 131 |
con = - con; |
| 132 |
*y = r_major * scale_factor * (con - lat_origin); |
| 133 |
return(OK); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
al = cos_phi * delta_lon; |
| 138 |
als = SQUARE(al); |
| 139 |
c = esp * SQUARE(cos_phi); |
| 140 |
tq = tan(lat); |
| 141 |
t = SQUARE(tq); |
| 142 |
con = 1.0 - es * SQUARE(sin_phi); |
| 143 |
n = r_major / sqrt(con); |
| 144 |
ml = r_major * mlfn(e0, e1, e2, e3, lat); |
| 145 |
|
| 146 |
*x = scale_factor * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 * |
| 147 |
(5.0 - 18.0 * t + SQUARE(t) + 72.0 * c - 58.0 * esp))) + false_easting; |
| 148 |
|
| 149 |
*y = scale_factor * (ml - ml0 + n * tq * (als * (0.5 + als / 24.0 * |
| 150 |
(5.0 - t + 9.0 * c + 4.0 * SQUARE(c) + als / 30.0 * (61.0 - 58.0 * t |
| 151 |
+ SQUARE(t) + 600.0 * c - 330.0 * esp))))) + false_northing; |
| 152 |
|
| 153 |
return(OK); |
| 154 |
} |