1 | /***************************************************************************** |
---|
2 | NAME GNOMONIC |
---|
3 | |
---|
4 | PURPOSE: Transforms input longitude and latitude to Easting and |
---|
5 | Northing for the Gnomonic Projection. |
---|
6 | Implementation based on the existing sterea and ortho |
---|
7 | implementations. |
---|
8 | |
---|
9 | PROGRAMMER DATE |
---|
10 | ---------- ---- |
---|
11 | Richard Marsden November 2009 |
---|
12 | |
---|
13 | ALGORITHM REFERENCES |
---|
14 | |
---|
15 | 1. Snyder, John P., "Flattening the Earth - Two Thousand Years of Map |
---|
16 | Projections", University of Chicago Press 1993 |
---|
17 | |
---|
18 | 2. Wolfram Mathworld "Gnomonic Projection" |
---|
19 | http://mathworld.wolfram.com/GnomonicProjection.html |
---|
20 | Accessed: 12th November 2009 |
---|
21 | ******************************************************************************/ |
---|
22 | |
---|
23 | Proj4js.Proj.gnom = { |
---|
24 | |
---|
25 | /* Initialize the Gnomonic projection |
---|
26 | -------------------------------------*/ |
---|
27 | init: function(def) { |
---|
28 | |
---|
29 | /* Place parameters in static storage for common use |
---|
30 | -------------------------------------------------*/ |
---|
31 | this.sin_p14=Math.sin(this.lat0); |
---|
32 | this.cos_p14=Math.cos(this.lat0); |
---|
33 | // Approximation for projecting points to the horizon (infinity) |
---|
34 | this.infinity_dist = 1000 * this.a; |
---|
35 | this.rc = 1; |
---|
36 | }, |
---|
37 | |
---|
38 | |
---|
39 | /* Gnomonic forward equations--mapping lat,long to x,y |
---|
40 | ---------------------------------------------------*/ |
---|
41 | forward: function(p) { |
---|
42 | var sinphi, cosphi; /* sin and cos value */ |
---|
43 | var dlon; /* delta longitude value */ |
---|
44 | var coslon; /* cos of longitude */ |
---|
45 | var ksp; /* scale factor */ |
---|
46 | var g; |
---|
47 | var lon=p.x; |
---|
48 | var lat=p.y; |
---|
49 | /* Forward equations |
---|
50 | -----------------*/ |
---|
51 | dlon = Proj4js.common.adjust_lon(lon - this.long0); |
---|
52 | |
---|
53 | sinphi=Math.sin(lat); |
---|
54 | cosphi=Math.cos(lat); |
---|
55 | |
---|
56 | coslon = Math.cos(dlon); |
---|
57 | g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon; |
---|
58 | ksp = 1.0; |
---|
59 | if ((g > 0) || (Math.abs(g) <= Proj4js.common.EPSLN)) { |
---|
60 | x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon) / g; |
---|
61 | y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon) / g; |
---|
62 | } else { |
---|
63 | Proj4js.reportError("orthoFwdPointError"); |
---|
64 | |
---|
65 | // Point is in the opposing hemisphere and is unprojectable |
---|
66 | // We still need to return a reasonable point, so we project |
---|
67 | // to infinity, on a bearing |
---|
68 | // equivalent to the northern hemisphere equivalent |
---|
69 | // This is a reasonable approximation for short shapes and lines that |
---|
70 | // straddle the horizon. |
---|
71 | |
---|
72 | x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon); |
---|
73 | y = this.y0 + this.infinity_dist * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon); |
---|
74 | |
---|
75 | } |
---|
76 | p.x=x; |
---|
77 | p.y=y; |
---|
78 | return p; |
---|
79 | }, |
---|
80 | |
---|
81 | |
---|
82 | inverse: function(p) { |
---|
83 | var rh; /* Rho */ |
---|
84 | var z; /* angle */ |
---|
85 | var sinc, cosc; |
---|
86 | var c; |
---|
87 | var lon , lat; |
---|
88 | |
---|
89 | /* Inverse equations |
---|
90 | -----------------*/ |
---|
91 | p.x = (p.x - this.x0) / this.a; |
---|
92 | p.y = (p.y - this.y0) / this.a; |
---|
93 | |
---|
94 | p.x /= this.k0; |
---|
95 | p.y /= this.k0; |
---|
96 | |
---|
97 | if ( (rh = Math.sqrt(p.x * p.x + p.y * p.y)) ) { |
---|
98 | c = Math.atan2(rh, this.rc); |
---|
99 | sinc = Math.sin(c); |
---|
100 | cosc = Math.cos(c); |
---|
101 | |
---|
102 | lat = Proj4js.common.asinz(cosc*this.sin_p14 + (p.y*sinc*this.cos_p14) / rh); |
---|
103 | lon = Math.atan2(p.x*sinc, rh*this.cos_p14*cosc - p.y*this.sin_p14*sinc); |
---|
104 | lon = Proj4js.common.adjust_lon(this.long0+lon); |
---|
105 | } else { |
---|
106 | lat = this.phic0; |
---|
107 | lon = 0.0; |
---|
108 | } |
---|
109 | |
---|
110 | p.x=lon; |
---|
111 | p.y=lat; |
---|
112 | return p; |
---|
113 | } |
---|
114 | }; |
---|
115 | |
---|
116 | |
---|