Debian Codegraph @

gctp/src/merfor.c

raw
1 /*******************************************************************************
2 NAME MERCATOR
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Mercator projection. The
6 longitude and latitude must be in radians. The Easting
7 and Northing values will be returned in meters.
8
9 PROGRAMMER DATE
10 ---------- ----
11 D. Steinwand, EROS Nov, 1991
12 T. Mittan Mar, 1993
13
14 ALGORITHM REFERENCES
15
16 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
17 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
18 State Government Printing Office, Washington D.C., 1987.
19
20 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
21 U.S. Geological Survey Professional Paper 1453 , United State Government
22 Printing Office, Washington D.C., 1989.
23 *******************************************************************************/
24 #include <stdio.h>
25 #include "cproj.h"
26
27 /* Variables common to all subroutines in this code file
28 -----------------------------------------------------*/
29 static double r_major; /* major axis */
30 static double r_minor; /* minor axis */
31 static double lon_center; /* Center longitude (projection center) */
32 static double lat_origin; /* center latitude */
33 static double e,es; /* eccentricity constants */
34 static double m1; /* small value m */
35 static double false_northing; /* y offset in meters */
36 static double false_easting; /* x offset in meters */
37
38
39 /* Initialize the Mercator projection
40 -------------------------------------------------*/
41 int merforint(
42 double r_maj, /* major axis */
43 double r_min, /* minor axis */
44 double center_lon, /* center longitude */
45 double center_lat, /* center latitude */
46 double false_east, /* x offset in meters */
47 double false_north) /* y offset in meters */
48 {
49 double temp; /* temporary variable */
50 double e0fn(),e1fn(),e2fn(),e3fn(); /* functions */
51
52 /* Place parameters in static storage for common use
53 -------------------------------------------------*/
54 r_major = r_maj;
55 r_minor = r_min;
56 lon_center = center_lon;
57 lat_origin = center_lat;
58 false_northing = false_north;
59 false_easting = false_east;
60
61 temp = r_minor / r_major;
62 es = 1.0 - SQUARE(temp);
63 e = sqrt(es);
64 m1 = cos(center_lat)/(sqrt(1.0 - es * sin(center_lat) * sin(center_lat)));
65
66 /* Report parameters to the user
67 -----------------------------*/
68 ptitle("MERCATOR");
69 radius2(r_major, r_minor);
70 cenlonmer(lon_center);
71 origin(lat_origin);
72 offsetp(false_easting,false_northing);
73 return(OK);
74 }
75
76
77 /* Mercator forward equations--mapping lat,long to x,y
78 --------------------------------------------------*/
79 int merfor(
80 double lon, /* (I) Longitude */
81 double lat, /* (I) Latitude */
82 double *x, /* (O) X projection coordinate */
83 double *y) /* (O) Y projection coordinate */
84 {
85 double ts; /* small t value */
86 double sinphi; /* sin value */
87
88 /* Forward equations
89 -----------------*/
90 if (fabs(fabs(lat) - HALF_PI) <= EPSLN)
91 {
92 p_error("Transformation cannot be computed at the poles","mer-forward");
93 return(53);
94 }
95 else
96 {
97 sinphi = sin(lat);
98 ts = tsfnz(e,lat,sinphi);
99 *x = false_easting + r_major * m1 * adjust_lon(lon - lon_center);
100 *y = false_northing - r_major * m1 * log(ts);
101 }
102 return(OK);
103 }