Debian Codegraph @

gctp/src/gvnspinv.c

raw
1 /*******************************************************************************
2 NAME GENERAL VERTICAL NEAR-SIDE PERSPECTIVE
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the General Vertical Near-Side Perspective
6 projection. The Easting and Northing must be in meters.
7 The longitude 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 General Vertical Near-side projection
14 code (FORTRAN) in the General Cartographic Transformation Package software
15 which is 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 p; /* Height above sphere */
38 static double sin_p15; /* Sine of the center latitude */
39 static double cos_p15; /* Cosine of the center latitude */
40 static double false_easting; /* x offset in meters */
41 static double false_northing; /* y offset in meters */
42
43 /* Initialize the General Vertical Near-Side Perspective projection
44 ---------------------------------------------------------------*/
45 int gvnspinvint(
46 double r, /* (I) Radius of the earth (sphere) */
47 double h, /* height above sphere */
48 double center_long, /* (I) Center longitude */
49 double center_lat, /* (I) Center latitude */
50 double false_east, /* x offset in meters */
51 double false_north) /* y offset in meters */
52 {
53 /* Place parameters in static storage for common use
54 -------------------------------------------------*/
55 R = r;
56 p = 1.0 + h / R;
57 lon_center = center_long;
58 lat_center = center_lat;
59 false_easting = false_east;
60 false_northing = false_north;
61 tsincos(center_lat, &sin_p15, &cos_p15);
62
63 /* Report parameters to the user
64 -----------------------------*/
65 ptitle("GENERAL VERTICAL NEAR-SIDE PERSPECTIVE");
66 radius(r);
67 genrpt(h,"Height of Point Above Surface of Sphere: ");
68 cenlon(center_long);
69 cenlat(center_lat);
70 offsetp(false_easting,false_northing);
71 return(OK);
72 }
73
74 /* General Vertical Near-Side Perspective inverse equations--mapping
75 x,y to lat/long
76 ----------------------------------------------------------------*/
77 int gvnspinv(
78 double x, /* (O) X projection coordinate */
79 double y, /* (O) Y projection coordinate */
80 double *lon, /* (I) Longitude */
81 double *lat) /* (I) Latitude */
82
83 {
84 double rh;
85 double r;
86 double con;
87 double com;
88 double z,sinz,cosz;
89
90
91 /* Inverse equations
92 -----------------*/
93 x -= false_easting;
94 y -= false_northing;
95 rh = sqrt(x * x + y * y);
96 r = rh / R;
97 con = p - 1.0;
98 com = p + 1.0;
99 if (r > sqrt(con/com))
100 {
101 p_error("Input data error","gvnsp-for");
102 return(155);
103 }
104 sinz = (p - sqrt(1.0 - (r * r * com) / con)) / (con / r + r/con);
105 z = asinz(sinz);
106 tsincos(z,&sinz,&cosz);
107 *lon = lon_center;
108 if (fabs(rh) <= EPSLN)
109 {
110 *lat = lat_center;
111 return(OK);
112 }
113 *lat = asinz(cosz * sin_p15 + ( y * sinz * cos_p15)/rh);
114 con = fabs(lat_center) - HALF_PI;
115 if (fabs(con) <= EPSLN)
116 {
117 if (lat_center >= 0.0)
118 {
119 *lon = adjust_lon(lon_center + atan2(x, -y));
120 return(OK);
121 }
122 else
123 {
124 *lon = adjust_lon(lon_center - atan2(-x, y));
125 return(OK);
126 }
127 }
128 con = cosz - sin_p15 * sin(*lat);
129 if ((fabs(con) < EPSLN) && (fabs(x) < EPSLN))
130 return(OK);
131 *lon = adjust_lon(lon_center + atan2((x * sinz * cos_p15), (con * rh)));
132
133 return(OK);
134 }