[76] | 1 | |
---|
| 2 | // Initialize the Stereographic projection |
---|
| 3 | |
---|
| 4 | Proj4js.Proj.stere = { |
---|
| 5 | ssfn_: function(phit, sinphi, eccen) { |
---|
| 6 | sinphi *= eccen; |
---|
| 7 | return (Math.tan (.5 * (Proj4js.common.HALF_PI + phit)) * Math.pow((1. - sinphi) / (1. + sinphi), .5 * eccen)); |
---|
| 8 | }, |
---|
| 9 | TOL: 1.e-8, |
---|
| 10 | NITER: 8, |
---|
| 11 | CONV: 1.e-10, |
---|
| 12 | S_POLE: 0, |
---|
| 13 | N_POLE: 1, |
---|
| 14 | OBLIQ: 2, |
---|
| 15 | EQUIT: 3, |
---|
| 16 | |
---|
| 17 | init : function() { |
---|
| 18 | this.phits = this.lat_ts ? this.lat_ts : Proj4js.common.HALF_PI; |
---|
| 19 | var t = Math.abs(this.lat0); |
---|
| 20 | if ((Math.abs(t) - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) { |
---|
| 21 | this.mode = this.lat0 < 0. ? this.S_POLE : this.N_POLE; |
---|
| 22 | } else { |
---|
| 23 | this.mode = t > Proj4js.common.EPSLN ? this.OBLIQ : this.EQUIT; |
---|
| 24 | } |
---|
| 25 | this.phits = Math.abs(this.phits); |
---|
| 26 | if (this.es) { |
---|
| 27 | var X; |
---|
| 28 | |
---|
| 29 | switch (this.mode) { |
---|
| 30 | case this.N_POLE: |
---|
| 31 | case this.S_POLE: |
---|
| 32 | if (Math.abs(this.phits - Proj4js.common.HALF_PI) < Proj4js.common.EPSLN) { |
---|
| 33 | this.akm1 = 2. * this.k0 / Math.sqrt(Math.pow(1+this.e,1+this.e)*Math.pow(1-this.e,1-this.e)); |
---|
| 34 | } else { |
---|
| 35 | t = Math.sin(this.phits); |
---|
| 36 | this.akm1 = Math.cos(this.phits) / Proj4js.common.tsfnz(this.e, this.phits, t); |
---|
| 37 | t *= this.e; |
---|
| 38 | this.akm1 /= Math.sqrt(1. - t * t); |
---|
| 39 | } |
---|
| 40 | break; |
---|
| 41 | case this.EQUIT: |
---|
| 42 | this.akm1 = 2. * this.k0; |
---|
| 43 | break; |
---|
| 44 | case this.OBLIQ: |
---|
| 45 | t = Math.sin(this.lat0); |
---|
| 46 | X = 2. * Math.atan(this.ssfn_(this.lat0, t, this.e)) - Proj4js.common.HALF_PI; |
---|
| 47 | t *= this.e; |
---|
| 48 | this.akm1 = 2. * this.k0 * Math.cos(this.lat0) / Math.sqrt(1. - t * t); |
---|
| 49 | this.sinX1 = Math.sin(X); |
---|
| 50 | this.cosX1 = Math.cos(X); |
---|
| 51 | break; |
---|
| 52 | } |
---|
| 53 | } else { |
---|
| 54 | switch (this.mode) { |
---|
| 55 | case this.OBLIQ: |
---|
| 56 | this.sinph0 = Math.sin(this.lat0); |
---|
| 57 | this.cosph0 = Math.cos(this.lat0); |
---|
| 58 | case this.EQUIT: |
---|
| 59 | this.akm1 = 2. * this.k0; |
---|
| 60 | break; |
---|
| 61 | case this.S_POLE: |
---|
| 62 | case this.N_POLE: |
---|
| 63 | this.akm1 = Math.abs(this.phits - Proj4js.common.HALF_PI) >= Proj4js.common.EPSLN ? |
---|
| 64 | Math.cos(this.phits) / Math.tan(Proj4js.common.FORTPI - .5 * this.phits) : |
---|
| 65 | 2. * this.k0 ; |
---|
| 66 | break; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | }, |
---|
| 70 | |
---|
| 71 | // Stereographic forward equations--mapping lat,long to x,y |
---|
| 72 | forward: function(p) { |
---|
| 73 | var lon = p.x; |
---|
| 74 | lon = Proj4js.common.adjust_lon(lon - this.long0); |
---|
| 75 | var lat = p.y; |
---|
| 76 | var x, y; |
---|
| 77 | |
---|
| 78 | if (this.sphere) { |
---|
| 79 | var sinphi, cosphi, coslam, sinlam; |
---|
| 80 | |
---|
| 81 | sinphi = Math.sin(lat); |
---|
| 82 | cosphi = Math.cos(lat); |
---|
| 83 | coslam = Math.cos(lon); |
---|
| 84 | sinlam = Math.sin(lon); |
---|
| 85 | switch (this.mode) { |
---|
| 86 | case this.EQUIT: |
---|
| 87 | y = 1. + cosphi * coslam; |
---|
| 88 | if (y <= Proj4js.common.EPSLN) { |
---|
| 89 | F_ERROR; |
---|
| 90 | } |
---|
| 91 | y = this.akm1 / y; |
---|
| 92 | x = y * cosphi * sinlam; |
---|
| 93 | y *= sinphi; |
---|
| 94 | break; |
---|
| 95 | case this.OBLIQ: |
---|
| 96 | y = 1. + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam; |
---|
| 97 | if (y <= Proj4js.common.EPSLN) { |
---|
| 98 | F_ERROR; |
---|
| 99 | } |
---|
| 100 | y = this.akm1 / y; |
---|
| 101 | x = y * cosphi * sinlam; |
---|
| 102 | y *= this.cosph0 * sinphi - this.sinph0 * cosphi * coslam; |
---|
| 103 | break; |
---|
| 104 | case this.N_POLE: |
---|
| 105 | coslam = -coslam; |
---|
| 106 | lat = -lat; |
---|
| 107 | //Note no break here so it conitnues through S_POLE |
---|
| 108 | case this.S_POLE: |
---|
| 109 | if (Math.abs(lat - Proj4js.common.HALF_PI) < this.TOL) { |
---|
| 110 | F_ERROR; |
---|
| 111 | } |
---|
| 112 | y = this.akm1 * Math.tan(Proj4js.common.FORTPI + .5 * lat); |
---|
| 113 | x = sinlam * y; |
---|
| 114 | y *= coslam; |
---|
| 115 | break; |
---|
| 116 | } |
---|
| 117 | } else { |
---|
| 118 | coslam = Math.cos(lon); |
---|
| 119 | sinlam = Math.sin(lon); |
---|
| 120 | sinphi = Math.sin(lat); |
---|
| 121 | if (this.mode == this.OBLIQ || this.mode == this.EQUIT) { |
---|
| 122 | X = 2. * Math.atan(this.ssfn_(lat, sinphi, this.e)); |
---|
| 123 | sinX = Math.sin(X - Proj4js.common.HALF_PI); |
---|
| 124 | cosX = Math.cos(X); |
---|
| 125 | } |
---|
| 126 | switch (this.mode) { |
---|
| 127 | case this.OBLIQ: |
---|
| 128 | A = this.akm1 / (this.cosX1 * (1. + this.sinX1 * sinX + this.cosX1 * cosX * coslam)); |
---|
| 129 | y = A * (this.cosX1 * sinX - this.sinX1 * cosX * coslam); |
---|
| 130 | x = A * cosX; |
---|
| 131 | break; |
---|
| 132 | case this.EQUIT: |
---|
| 133 | A = 2. * this.akm1 / (1. + cosX * coslam); |
---|
| 134 | y = A * sinX; |
---|
| 135 | x = A * cosX; |
---|
| 136 | break; |
---|
| 137 | case this.S_POLE: |
---|
| 138 | lat = -lat; |
---|
| 139 | coslam = - coslam; |
---|
| 140 | sinphi = -sinphi; |
---|
| 141 | case this.N_POLE: |
---|
| 142 | x = this.akm1 * Proj4js.common.tsfnz(this.e, lat, sinphi); |
---|
| 143 | y = - x * coslam; |
---|
| 144 | break; |
---|
| 145 | } |
---|
| 146 | x = x * sinlam; |
---|
| 147 | } |
---|
| 148 | p.x = x*this.a + this.x0; |
---|
| 149 | p.y = y*this.a + this.y0; |
---|
| 150 | return p; |
---|
| 151 | }, |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | //* Stereographic inverse equations--mapping x,y to lat/long |
---|
| 155 | inverse: function(p) { |
---|
| 156 | var x = (p.x - this.x0)/this.a; /* descale and de-offset */ |
---|
| 157 | var y = (p.y - this.y0)/this.a; |
---|
| 158 | var lon, lat; |
---|
| 159 | |
---|
| 160 | var cosphi, sinphi, tp=0.0, phi_l=0.0, rho, halfe=0.0, pi2=0.0; |
---|
| 161 | var i; |
---|
| 162 | |
---|
| 163 | if (this.sphere) { |
---|
| 164 | var c, rh, sinc, cosc; |
---|
| 165 | |
---|
| 166 | rh = Math.sqrt(x*x + y*y); |
---|
| 167 | c = 2. * Math.atan(rh / this.akm1); |
---|
| 168 | sinc = Math.sin(c); |
---|
| 169 | cosc = Math.cos(c); |
---|
| 170 | lon = 0.; |
---|
| 171 | switch (this.mode) { |
---|
| 172 | case this.EQUIT: |
---|
| 173 | if (Math.abs(rh) <= Proj4js.common.EPSLN) { |
---|
| 174 | lat = 0.; |
---|
| 175 | } else { |
---|
| 176 | lat = Math.asin(y * sinc / rh); |
---|
| 177 | } |
---|
| 178 | if (cosc != 0. || x != 0.) lon = Math.atan2(x * sinc, cosc * rh); |
---|
| 179 | break; |
---|
| 180 | case this.OBLIQ: |
---|
| 181 | if (Math.abs(rh) <= Proj4js.common.EPSLN) { |
---|
| 182 | lat = this.phi0; |
---|
| 183 | } else { |
---|
| 184 | lat = Math.asin(cosc * sinph0 + y * sinc * cosph0 / rh); |
---|
| 185 | } |
---|
| 186 | c = cosc - sinph0 * Math.sin(lat); |
---|
| 187 | if (c != 0. || x != 0.) { |
---|
| 188 | lon = Math.atan2(x * sinc * cosph0, c * rh); |
---|
| 189 | } |
---|
| 190 | break; |
---|
| 191 | case this.N_POLE: |
---|
| 192 | y = -y; |
---|
| 193 | case this.S_POLE: |
---|
| 194 | if (Math.abs(rh) <= Proj4js.common.EPSLN) { |
---|
| 195 | lat = this.phi0; |
---|
| 196 | } else { |
---|
| 197 | lat = Math.asin(this.mode == this.S_POLE ? -cosc : cosc); |
---|
| 198 | } |
---|
| 199 | lon = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y); |
---|
| 200 | break; |
---|
| 201 | } |
---|
| 202 | p.x = Proj4js.common.adjust_lon(lon + this.long0); |
---|
| 203 | p.y = lat; |
---|
| 204 | } else { |
---|
| 205 | rho = Math.sqrt(x*x + y*y); |
---|
| 206 | switch (this.mode) { |
---|
| 207 | case this.OBLIQ: |
---|
| 208 | case this.EQUIT: |
---|
| 209 | tp = 2. * Math.atan2(rho * this.cosX1 , this.akm1); |
---|
| 210 | cosphi = Math.cos(tp); |
---|
| 211 | sinphi = Math.sin(tp); |
---|
| 212 | if( rho == 0.0 ) { |
---|
| 213 | phi_l = Math.asin(cosphi * this.sinX1); |
---|
| 214 | } else { |
---|
| 215 | phi_l = Math.asin(cosphi * this.sinX1 + (y * sinphi * this.cosX1 / rho)); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | tp = Math.tan(.5 * (Proj4js.common.HALF_PI + phi_l)); |
---|
| 219 | x *= sinphi; |
---|
| 220 | y = rho * this.cosX1 * cosphi - y * this.sinX1* sinphi; |
---|
| 221 | pi2 = Proj4js.common.HALF_PI; |
---|
| 222 | halfe = .5 * this.e; |
---|
| 223 | break; |
---|
| 224 | case this.N_POLE: |
---|
| 225 | y = -y; |
---|
| 226 | case this.S_POLE: |
---|
| 227 | tp = - rho / this.akm1; |
---|
| 228 | phi_l = Proj4js.common.HALF_PI - 2. * Math.atan(tp); |
---|
| 229 | pi2 = -Proj4js.common.HALF_PI; |
---|
| 230 | halfe = -.5 * this.e; |
---|
| 231 | break; |
---|
| 232 | } |
---|
| 233 | for (i = this.NITER; i--; phi_l = lat) { //check this |
---|
| 234 | sinphi = this.e * Math.sin(phi_l); |
---|
| 235 | lat = 2. * Math.atan(tp * Math.pow((1.+sinphi)/(1.-sinphi), halfe)) - pi2; |
---|
| 236 | if (Math.abs(phi_l - lat) < this.CONV) { |
---|
| 237 | if (this.mode == this.S_POLE) lat = -lat; |
---|
| 238 | lon = (x == 0. && y == 0.) ? 0. : Math.atan2(x, y); |
---|
| 239 | p.x = Proj4js.common.adjust_lon(lon + this.long0); |
---|
| 240 | p.y = lat; |
---|
| 241 | return p; |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | }; |
---|