Debian Codegraph @

gctp/src/equiinv.c

raw
1 /*******************************************************************************
2 NAME EQUIRECTANGULAR
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the Equirectangular 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 lon_center; /* Center longitude (projection center) */
30 static double lat_origin; /* center latitude */
31 static double false_northing; /* y offset in meters */
32 static double false_easting; /* x offset in meters */
33
34 /* Initialize the Equirectangular projection
35 ----------------------------------------*/
36 int equiinvint(
37 double r_maj, /* major axis */
38 double center_lon, /* center longitude */
39 double lat1, /* latitude of true scale */
40 double false_east, /* x offset in meters */
41 double false_north) /* y offset in meters */
42 {
43
44 /* Place parameters in static storage for common use
45 -------------------------------------------------*/
46 r_major = r_maj;
47 lon_center = center_lon;
48 lat_origin = lat1;
49 false_northing = false_north;
50 false_easting = false_east;
51
52 /* Report parameters to the user
53 -----------------------------*/
54 ptitle("EQUIRECTANGULAR");
55 radius(r_major);
56 cenlonmer(lon_center);
57 origin(lat_origin);
58 offsetp(false_easting,false_northing);
59 return(OK);
60 }
61
62
63 /* Equirectangular inverse equations--mapping x,y to lat/long
64 ---------------------------------------------------------*/
65 int equiinv(
66 double x, /* (O) X projection coordinate */
67 double y, /* (O) Y projection coordinate */
68 double *lon, /* (I) Longitude */
69 double *lat) /* (I) Latitude */
70 {
71
72 /* Inverse equations
73 -----------------*/
74 x -= false_easting;
75 y -= false_northing;
76 *lat = y / r_major;
77 if (fabs(*lat) > HALF_PI)
78 {
79 p_error("Input data error","equi-inv");
80 return(174);
81 }
82 *lon = adjust_lon(lon_center + x / (r_major * cos(lat_origin)));
83 return(OK);
84 }