Loading src/projCode/stere.js +162 −165 Original line number Diff line number Diff line // Initialize the Stereographic projection proj4.Proj.stere = { ssfn_: function(phit, sinphi, eccen) { sinphi *= eccen; return (Math.tan (.5 * (proj4.common.HALF_PI + phit)) * Math.pow((1. - sinphi) / (1. + sinphi), .5 * eccen)); return (Math.tan(0.5 * (proj4.common.HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen)); }, init: function() { this.coslat0 = Math.cos(this.lat0); this.sinlat0 = Math.sin(this.lat0); if (this.sphere) { if (this.k0==1.0 && !isNaN(this.lat_ts) && Math.abs(this.coslat0)<=proj4.common.EPSLN){ this.k0=0.5*(1.0+proj4.common.sign(this.lat0)*Math.sin(this.lat_ts)); if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= proj4.common.EPSLN) { this.k0 = 0.5 * (1 + proj4.common.sign(this.lat0) * Math.sin(this.lat_ts)); } } else { Loading @@ -21,14 +20,15 @@ proj4.Proj.stere = { //North pole //trace('stere:north pole'); this.con = 1.0; } else { } else { //South pole //trace('stere:south pole'); this.con = -1.0; } } this.cons = Math.sqrt(Math.pow(1 + this.e, 1 + this.e) * Math.pow(1 - this.e, 1 - this.e)); if (this.k0==1.0 && !isNaN(this.lat_ts) && Math.abs(this.coslat0)<=proj4.common.EPSLN){ if (this.k0 === 1.0 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= proj4.common.EPSLN) { this.k0 = 0.5 * this.cons * proj4.common.msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts)) / proj4.common.tsfnz(this.e, this.con * this.lat_ts, this.con * Math.sin(this.lat_ts)); } this.ms1 = proj4.common.msfnz(this.e, this.sinlat0, this.coslat0); Loading @@ -44,7 +44,7 @@ proj4.Proj.stere = { var lat = p.y; var sinlat = Math.sin(lat); var coslat = Math.cos(lat); var x, y, A, X,sinX,cosX; var A, X, sinX, cosX, ts, rh; var dlon = proj4.common.adjust_lon(lon - this.long0); if (Math.abs(Math.abs(lon - this.long0) - proj4.common.PI) <= proj4.common.EPSLN && Math.abs(lat + this.lat0) <= proj4.common.EPSLN) { Loading @@ -54,40 +54,39 @@ proj4.Proj.stere = { p.y = NaN; return p; } if (this.sphere) { //trace('stere:sphere case'); A = 2 * this.k0 / (1.0 + this.sinlat0 * sinlat + this.coslat0 * coslat * Math.cos(dlon)); p.x = this.a * A * coslat * Math.sin(dlon) + this.x0; p.y = this.a * A * (this.coslat0 * sinlat - this.sinlat0 * coslat * Math.cos(dlon)) + this.y0; return p; } else { } else { X = 2.0 * Math.atan(this.ssfn_(lat, sinlat, this.e)) - proj4.common.HALF_PI; cosX = Math.cos(X); sinX = Math.sin(X); if (Math.abs(this.coslat0) <= proj4.common.EPSLN) { var ts = proj4.common.tsfnz(this.e, lat*this.con, this.con*sinlat); var rh=2.0*this.a*this.k0*ts/this.cons; ts = proj4.common.tsfnz(this.e, lat * this.con, this.con * sinlat); rh = 2.0 * this.a * this.k0 * ts / this.cons; p.x = this.x0 + rh * Math.sin(lon - this.long0); p.y = this.y0 - this.con * rh * Math.cos(lon - this.long0); //trace(p.toString()); return p; } else if (Math.abs(this.sinlat0)<proj4.common.EPSLN) { } else if (Math.abs(this.sinlat0) < proj4.common.EPSLN) { //Eq //trace('stere:equateur'); A = 2.0 * this.a * this.k0 / (1.0 + cosX * Math.cos(dlon)); p.y = A * sinX; }else { } else { //other case //trace('stere:normal case'); A = 2.0 * this.a * this.k0 * this.ms1 / (this.cosX0 * (1.0 + this.sinX0 * sinX + this.cosX0 * cosX * Math.cos(dlon))); p.y = A * (this.cosX0 * sinX - this.sinX0 * cosX * Math.cos(dlon)) + this.y0; } p.x = A * cosX * Math.sin(dlon) + this.x0; } //trace(p.toString()); return p; }, Loading @@ -97,7 +96,7 @@ proj4.Proj.stere = { inverse: function(p) { p.x -= this.x0; p.y -= this.y0; var lon, lat; var lon, lat, ts, ce, Chi; var rh = Math.sqrt(p.x * p.x + p.y * p.y); if (this.sphere) { var c = 2 * Math.atan(rh / (0.5 * this.a * this.k0)); Loading @@ -112,49 +111,47 @@ proj4.Proj.stere = { if (Math.abs(this.coslat0) < proj4.common.EPSLN) { if (this.lat0 > 0.0) { lon = proj4.common.adjust_lon(this.long0 + Math.atan2(p.x, - 1.0 * p.y)); } else { } else { lon = proj4.common.adjust_lon(this.long0 + Math.atan2(p.x, p.y)); } } else { } else { lon = proj4.common.adjust_lon(this.long0 + Math.atan2(p.x * Math.sin(c), rh * this.coslat0 * Math.cos(c) - p.y * this.sinlat0 * Math.sin(c))); } p.x = lon; p.y = lat; return p; } else { } else { if (Math.abs(this.coslat0) <= proj4.common.EPSLN) { if (rh <= proj4.common.EPSLN) { lat = this.lat0; lon = this.long0; p.x = lon; p.y = lat; //trace(p.toString()); return p; } p.x *= this.con; p.y *= this.con; var ts = rh*this.cons/(2.0*this.a*this.k0); ts = rh * this.cons / (2.0 * this.a * this.k0); lat = this.con * proj4.common.phi2z(this.e, ts); lon = this.con * proj4.common.adjust_lon(this.con * this.long0 + Math.atan2(p.x, - 1.0 * p.y)); } else { var ce = 2.0*Math.atan(rh*this.cosX0/(2.0*this.a*this.k0*this.ms1)); } else { ce = 2.0 * Math.atan(rh * this.cosX0 / (2.0 * this.a * this.k0 * this.ms1)); lon = this.long0; var Chi; if (rh <= proj4.common.EPSLN) { Chi = this.X0; } else { } else { Chi = Math.asin(Math.cos(ce) * this.sinX0 + p.y * Math.sin(ce) * this.cosX0 / rh); lon = proj4.common.adjust_lon(this.long0 + Math.atan2(p.x * Math.sin(ce), rh * this.cosX0 * Math.cos(ce) - p.y * this.sinX0 * Math.sin(ce))); } lat = -1.0 * proj4.common.phi2z(this.e, Math.tan(0.5 * (proj4.common.HALF_PI + Chi))); } } p.x = lon; p.y = lat; Loading Loading
src/projCode/stere.js +162 −165 Original line number Diff line number Diff line // Initialize the Stereographic projection proj4.Proj.stere = { ssfn_: function(phit, sinphi, eccen) { sinphi *= eccen; return (Math.tan (.5 * (proj4.common.HALF_PI + phit)) * Math.pow((1. - sinphi) / (1. + sinphi), .5 * eccen)); return (Math.tan(0.5 * (proj4.common.HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen)); }, init: function() { this.coslat0 = Math.cos(this.lat0); this.sinlat0 = Math.sin(this.lat0); if (this.sphere) { if (this.k0==1.0 && !isNaN(this.lat_ts) && Math.abs(this.coslat0)<=proj4.common.EPSLN){ this.k0=0.5*(1.0+proj4.common.sign(this.lat0)*Math.sin(this.lat_ts)); if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= proj4.common.EPSLN) { this.k0 = 0.5 * (1 + proj4.common.sign(this.lat0) * Math.sin(this.lat_ts)); } } else { Loading @@ -21,14 +20,15 @@ proj4.Proj.stere = { //North pole //trace('stere:north pole'); this.con = 1.0; } else { } else { //South pole //trace('stere:south pole'); this.con = -1.0; } } this.cons = Math.sqrt(Math.pow(1 + this.e, 1 + this.e) * Math.pow(1 - this.e, 1 - this.e)); if (this.k0==1.0 && !isNaN(this.lat_ts) && Math.abs(this.coslat0)<=proj4.common.EPSLN){ if (this.k0 === 1.0 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= proj4.common.EPSLN) { this.k0 = 0.5 * this.cons * proj4.common.msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts)) / proj4.common.tsfnz(this.e, this.con * this.lat_ts, this.con * Math.sin(this.lat_ts)); } this.ms1 = proj4.common.msfnz(this.e, this.sinlat0, this.coslat0); Loading @@ -44,7 +44,7 @@ proj4.Proj.stere = { var lat = p.y; var sinlat = Math.sin(lat); var coslat = Math.cos(lat); var x, y, A, X,sinX,cosX; var A, X, sinX, cosX, ts, rh; var dlon = proj4.common.adjust_lon(lon - this.long0); if (Math.abs(Math.abs(lon - this.long0) - proj4.common.PI) <= proj4.common.EPSLN && Math.abs(lat + this.lat0) <= proj4.common.EPSLN) { Loading @@ -54,40 +54,39 @@ proj4.Proj.stere = { p.y = NaN; return p; } if (this.sphere) { //trace('stere:sphere case'); A = 2 * this.k0 / (1.0 + this.sinlat0 * sinlat + this.coslat0 * coslat * Math.cos(dlon)); p.x = this.a * A * coslat * Math.sin(dlon) + this.x0; p.y = this.a * A * (this.coslat0 * sinlat - this.sinlat0 * coslat * Math.cos(dlon)) + this.y0; return p; } else { } else { X = 2.0 * Math.atan(this.ssfn_(lat, sinlat, this.e)) - proj4.common.HALF_PI; cosX = Math.cos(X); sinX = Math.sin(X); if (Math.abs(this.coslat0) <= proj4.common.EPSLN) { var ts = proj4.common.tsfnz(this.e, lat*this.con, this.con*sinlat); var rh=2.0*this.a*this.k0*ts/this.cons; ts = proj4.common.tsfnz(this.e, lat * this.con, this.con * sinlat); rh = 2.0 * this.a * this.k0 * ts / this.cons; p.x = this.x0 + rh * Math.sin(lon - this.long0); p.y = this.y0 - this.con * rh * Math.cos(lon - this.long0); //trace(p.toString()); return p; } else if (Math.abs(this.sinlat0)<proj4.common.EPSLN) { } else if (Math.abs(this.sinlat0) < proj4.common.EPSLN) { //Eq //trace('stere:equateur'); A = 2.0 * this.a * this.k0 / (1.0 + cosX * Math.cos(dlon)); p.y = A * sinX; }else { } else { //other case //trace('stere:normal case'); A = 2.0 * this.a * this.k0 * this.ms1 / (this.cosX0 * (1.0 + this.sinX0 * sinX + this.cosX0 * cosX * Math.cos(dlon))); p.y = A * (this.cosX0 * sinX - this.sinX0 * cosX * Math.cos(dlon)) + this.y0; } p.x = A * cosX * Math.sin(dlon) + this.x0; } //trace(p.toString()); return p; }, Loading @@ -97,7 +96,7 @@ proj4.Proj.stere = { inverse: function(p) { p.x -= this.x0; p.y -= this.y0; var lon, lat; var lon, lat, ts, ce, Chi; var rh = Math.sqrt(p.x * p.x + p.y * p.y); if (this.sphere) { var c = 2 * Math.atan(rh / (0.5 * this.a * this.k0)); Loading @@ -112,49 +111,47 @@ proj4.Proj.stere = { if (Math.abs(this.coslat0) < proj4.common.EPSLN) { if (this.lat0 > 0.0) { lon = proj4.common.adjust_lon(this.long0 + Math.atan2(p.x, - 1.0 * p.y)); } else { } else { lon = proj4.common.adjust_lon(this.long0 + Math.atan2(p.x, p.y)); } } else { } else { lon = proj4.common.adjust_lon(this.long0 + Math.atan2(p.x * Math.sin(c), rh * this.coslat0 * Math.cos(c) - p.y * this.sinlat0 * Math.sin(c))); } p.x = lon; p.y = lat; return p; } else { } else { if (Math.abs(this.coslat0) <= proj4.common.EPSLN) { if (rh <= proj4.common.EPSLN) { lat = this.lat0; lon = this.long0; p.x = lon; p.y = lat; //trace(p.toString()); return p; } p.x *= this.con; p.y *= this.con; var ts = rh*this.cons/(2.0*this.a*this.k0); ts = rh * this.cons / (2.0 * this.a * this.k0); lat = this.con * proj4.common.phi2z(this.e, ts); lon = this.con * proj4.common.adjust_lon(this.con * this.long0 + Math.atan2(p.x, - 1.0 * p.y)); } else { var ce = 2.0*Math.atan(rh*this.cosX0/(2.0*this.a*this.k0*this.ms1)); } else { ce = 2.0 * Math.atan(rh * this.cosX0 / (2.0 * this.a * this.k0 * this.ms1)); lon = this.long0; var Chi; if (rh <= proj4.common.EPSLN) { Chi = this.X0; } else { } else { Chi = Math.asin(Math.cos(ce) * this.sinX0 + p.y * Math.sin(ce) * this.cosX0 / rh); lon = proj4.common.adjust_lon(this.long0 + Math.atan2(p.x * Math.sin(ce), rh * this.cosX0 * Math.cos(ce) - p.y * this.sinX0 * Math.sin(ce))); } lat = -1.0 * proj4.common.phi2z(this.e, Math.tan(0.5 * (proj4.common.HALF_PI + Chi))); } } p.x = lon; p.y = lat; Loading