| 1 |
/******************************************************************************* |
| 2 |
NAME GNOMONIC |
| 3 |
|
| 4 |
PURPOSE: Transforms input longitude and latitude to Easting and |
| 5 |
Northing for the Gnomonic projection. The longitude |
| 6 |
and latitude must be in radians. The Easting and |
| 7 |
Northing values will be returned in meters. |
| 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 R; /* Radius of the earth (sphere) */ |
| 36 |
static double sin_p13; /* Sine of the center latitude */ |
| 37 |
static double cos_p13; /* Cosine of the center latitude */ |
| 38 |
static double false_easting; /* x offset in meters */ |
| 39 |
static double false_northing; /* y offset in meters */ |
| 40 |
|
| 41 |
/* Initialize the Gnomonic projection |
| 42 |
---------------------------------*/ |
| 43 |
int gnomforint( |
| 44 |
double r, /* (I) Radius of the earth (sphere) */ |
| 45 |
double center_long, /* (I) Center longitude */ |
| 46 |
double center_lat, /* (I) Center latitude */ |
| 47 |
double false_east, /* x offset in meters */ |
| 48 |
double false_north) /* y offset in meters */ |
| 49 |
{ |
| 50 |
/* Place parameters in static storage for common use |
| 51 |
-------------------------------------------------*/ |
| 52 |
R = r; |
| 53 |
lon_center = center_long; |
| 54 |
false_easting = false_east; |
| 55 |
false_northing = false_north; |
| 56 |
tsincos(center_lat, &sin_p13, &cos_p13); |
| 57 |
|
| 58 |
/* Report parameters to the user |
| 59 |
-----------------------------*/ |
| 60 |
ptitle("GNOMONIC"); |
| 61 |
radius(r); |
| 62 |
cenlon(center_long); |
| 63 |
cenlat(center_lat); |
| 64 |
offsetp(false_easting,false_northing); |
| 65 |
return(OK); |
| 66 |
} |
| 67 |
|
| 68 |
/* Gnomonic forward equations--mapping lat,long to x,y |
| 69 |
--------------------------------------------------*/ |
| 70 |
int gnomfor( |
| 71 |
double lon, /* (I) Longitude */ |
| 72 |
double lat, /* (I) Latitude */ |
| 73 |
double *x, /* (O) X projection coordinate */ |
| 74 |
double *y) /* (O) Y projection coordinate */ |
| 75 |
|
| 76 |
{ |
| 77 |
double dlon; |
| 78 |
double sinphi,cosphi; |
| 79 |
double coslon; |
| 80 |
double g; |
| 81 |
double ksp; |
| 82 |
|
| 83 |
|
| 84 |
/* Forward equations |
| 85 |
-----------------*/ |
| 86 |
dlon = adjust_lon(lon - lon_center); |
| 87 |
tsincos(lat,&sinphi,&cosphi); |
| 88 |
coslon = cos(dlon); |
| 89 |
g = sin_p13 * sinphi + cos_p13 * cosphi * coslon; |
| 90 |
if (g <= 0.0) |
| 91 |
{ |
| 92 |
p_error("Point projects into infinity","gnomfor-conv"); |
| 93 |
return(133); |
| 94 |
} |
| 95 |
ksp = 1.0 / g; |
| 96 |
*x = false_easting + R * ksp * cosphi * sin(dlon); |
| 97 |
*y = false_northing + R * ksp * (cos_p13 * sinphi - sin_p13 * cosphi * |
| 98 |
coslon); |
| 99 |
|
| 100 |
return(OK); |
| 101 |
} |