| 1 |
/******************************************************************************* |
| 2 |
NAME GNOMONIC |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Gnomonic 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 |
This function was adapted from the Gnomonic projection code (FORTRAN) |
| 14 |
in the General Cartographic Transformation Package software which is |
| 15 |
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 lon_center; /* Center longitude (projection center) */ |
| 35 |
static double lat_center; /* Center latitude (projection center) */ |
| 36 |
static double R; /* Radius of the earth (sphere) */ |
| 37 |
static double sin_p13; /* Sine of the center latitude */ |
| 38 |
static double cos_p13; /* Cosine of the center latitude */ |
| 39 |
static double false_easting; /* x offset in meters */ |
| 40 |
static double false_northing; /* y offset in meters */ |
| 41 |
|
| 42 |
/* Initialize the Gnomonic projection |
| 43 |
---------------------------------*/ |
| 44 |
int gnominvint( |
| 45 |
double r, /* (I) Radius of the earth (sphere) */ |
| 46 |
double center_long, /* (I) Center longitude */ |
| 47 |
double center_lat, /* (I) Center latitude */ |
| 48 |
double false_east, /* x offset in meters */ |
| 49 |
double false_north) /* y offset in meters */ |
| 50 |
{ |
| 51 |
/* Place parameters in static storage for common use |
| 52 |
-------------------------------------------------*/ |
| 53 |
R = r; |
| 54 |
lon_center = center_long; |
| 55 |
lat_center = center_lat; |
| 56 |
false_easting = false_east; |
| 57 |
false_northing = false_north; |
| 58 |
tsincos(center_lat, &sin_p13, &cos_p13); |
| 59 |
|
| 60 |
/* Report parameters to the user |
| 61 |
-----------------------------*/ |
| 62 |
ptitle("GNOMONIC"); |
| 63 |
radius(r); |
| 64 |
cenlon(center_long); |
| 65 |
cenlat(center_lat); |
| 66 |
offsetp(false_easting,false_northing); |
| 67 |
return(OK); |
| 68 |
} |
| 69 |
|
| 70 |
/* Gnomonic inverse equations--mapping x,y to lat/long |
| 71 |
--------------------------------------------------*/ |
| 72 |
int gnominv( |
| 73 |
double x, /* (O) X projection coordinate */ |
| 74 |
double y, /* (O) Y projection coordinate */ |
| 75 |
double *lon, /* (I) Longitude */ |
| 76 |
double *lat) /* (I) Latitude */ |
| 77 |
|
| 78 |
{ |
| 79 |
double rh; |
| 80 |
double z,sinz,cosz; |
| 81 |
double con; |
| 82 |
|
| 83 |
|
| 84 |
/* Inverse equations |
| 85 |
-----------------*/ |
| 86 |
x -= false_easting; |
| 87 |
y -= false_northing; |
| 88 |
rh = sqrt(x * x + y * y); |
| 89 |
z = atan(rh / R); |
| 90 |
tsincos(z,&sinz,&cosz); |
| 91 |
*lon = lon_center; |
| 92 |
|
| 93 |
if (fabs(rh) <= EPSLN) |
| 94 |
{ |
| 95 |
*lat = lat_center; |
| 96 |
return(OK); |
| 97 |
} |
| 98 |
*lat = asinz(cosz * sin_p13 + (y * sinz * cos_p13) / rh); |
| 99 |
con = fabs(lat_center) - HALF_PI; |
| 100 |
if (fabs(con) <= EPSLN) |
| 101 |
{ |
| 102 |
if (lat_center >= 0.0) |
| 103 |
{ |
| 104 |
*lon = adjust_lon(lon_center + atan2(x, -y)); |
| 105 |
return(OK); |
| 106 |
} |
| 107 |
else |
| 108 |
{ |
| 109 |
*lon = adjust_lon(lon_center - atan2(-x, y)); |
| 110 |
return(OK); |
| 111 |
} |
| 112 |
} |
| 113 |
con = cosz - sin_p13 * sin(*lat); |
| 114 |
if ((fabs(con) < EPSLN) && (fabs(x) < EPSLN)) |
| 115 |
return(OK); |
| 116 |
*lon = adjust_lon(lon_center + atan2((x * sinz * cos_p13), (con * rh))); |
| 117 |
|
| 118 |
|
| 119 |
return(OK); |
| 120 |
} |