Debian Codegraph @

gctp/src/polyinv.c

raw
1 /*******************************************************************************
2 NAME POLYCONIC
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the Polyconic 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 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 lon_center; /* Center longitude (projection center) */
31 static double lat_origin; /* center latitude */
32 static double e0,e1,e2,e3; /* eccentricity constants */
33 static double es; /* eccentricity constants */
34 static double ml0; /* small value m */
35 static double false_northing; /* y offset in meters */
36 static double false_easting; /* x offset in meters */
37
38 /* Initialize the POLYCONIC projection
39 ----------------------------------*/
40 int polyinvint(
41 double r_maj, /* major axis */
42 double r_min, /* minor axis */
43 double center_lon, /* center longitude */
44 double center_lat, /* center latitude */
45 double false_east, /* x offset in meters */
46 double false_north) /* y offset in meters */
47 {
48 double temp; /* temporary variable */
49
50 /* Place parameters in static storage for common use
51 -------------------------------------------------*/
52 r_major = r_maj;
53 r_minor = r_min;
54 lon_center = center_lon;
55 lat_origin = center_lat;
56 false_northing = false_north;
57 false_easting = false_east;
58
59 temp = r_minor / r_major;
60 es = 1.0 - SQUARE(temp);
61 e0 = e0fn(es);
62 e1 = e1fn(es);
63 e2 = e2fn(es);
64 e3 = e3fn(es);
65 ml0 = mlfn(e0, e1, e2, e3, lat_origin);
66
67 /* Report parameters to the user
68 -----------------------------*/
69 ptitle("POLYCONIC");
70 radius2(r_major, r_minor);
71 cenlonmer(lon_center);
72 origin(lat_origin);
73 offsetp(false_easting,false_northing);
74 return(OK);
75 }
76
77
78 /* Polyconic inverse equations--mapping x,y to lat/long
79 ---------------------------------------------------*/
80 int polyinv(
81 double x, /* (O) X projection coordinate */
82 double y, /* (O) Y projection coordinate */
83 double *lon, /* (I) Longitude */
84 double *lat) /* (I) Latitude */
85 {
86 double al; /* temporary values */
87 double b; /* temporary values */
88 double c; /* temporary values */
89 long iflg; /* error flag */
90
91 /* Inverse equations
92 -----------------*/
93 x -= false_easting;
94 y -= false_northing;
95 al = ml0 + y/r_major;
96 iflg = 0;
97 if (fabs(al) <= .0000001)
98 {
99 *lon = x/r_major + lon_center;
100 *lat = 0.0;
101 }
102 else
103 {
104 b = al * al + (x/r_major) * (x/r_major);
105 iflg = (long) phi4z(es,e0,e1,e2,e3,al,b,&c,lat);
106 if (iflg != 0)
107 return(74);
108 *lon = adjust_lon((asinz(x * c / r_major) / sin(*lat)) + lon_center);
109 }
110
111 return(OK);
112 }