Commit a91f9039 authored by Richard Didier's avatar Richard Didier
Browse files

Addition of new support methods (part of ticket 80)

parent 904c8382
Loading
Loading
Loading
Loading
+62 −5
Original line number Diff line number Diff line
@@ -765,12 +765,12 @@ Proj4js.Proj = Proj4js.Class({
    //add in variations in the spelling as required
    switch (wktObject) {
      case 'LOCAL_CS':
        this.projName = 'identity'
        this.projName = 'identity';
        this.localCS = true;
        this.srsCode = wktName;
        break;
      case 'GEOGCS':
        this.projName = 'longlat'
        this.projName = 'longlat';
        this.geocsCode = wktName;
        if (!this.srsCode) this.srsCode = wktName;
        break;
@@ -780,7 +780,7 @@ Proj4js.Proj = Proj4js.Class({
      case 'GEOCCS':
        break;
      case 'PROJECTION':
        this.projName = Proj4js.wktProjections[wktName]
        this.projName = Proj4js.wktProjections[wktName];
        break;
      case 'DATUM':
        this.datumName = wktName;
@@ -908,6 +908,10 @@ Proj4js.Proj = Proj4js.Class({
              case "lat_2":  this.lat2 = paramVal*Proj4js.common.D2R; break;        //standard parallel 2
              case "lat_ts": this.lat_ts = paramVal*Proj4js.common.D2R; break;      // used in merc and eqc
              case "lon_0":  this.long0 = paramVal*Proj4js.common.D2R; break;       // lam0, central longitude
              case "lon_1":  this.long1 = paramVal*Proj4js.common.D2R; break;
              case "lon_2":  this.long2 = paramVal*Proj4js.common.D2R; break;
              case "no_rot": this.no_rot = true; break;
              case "no_off": this.no_off = true; break;
              case "alpha":  this.alpha =  parseFloat(paramVal)*Proj4js.common.D2R; break;  //for somerc projection
              case "lonc":   this.longc = paramVal*Proj4js.common.D2R; break;       //for somerc projection
              case "x_0":    this.x0 = parseFloat(paramVal); break;  // false easting
@@ -937,7 +941,7 @@ Proj4js.Proj = Proj4js.Class({
                                 legalAxis.indexOf(paramVal.substr(2,1))!=-1) {
                                this.axis= paramVal;
                             } //FIXME: be silent ?
                             break
                             break;
              case "no_defs": break;
              default: //alert("Unrecognized parameter: " + paramName);
          } // switch()
@@ -1111,6 +1115,38 @@ Proj4js.common = {
    }
  },

  /** Function to compute the inverse of qsfnz
   */
  iqsfnz : function (eccent, q) {
    var temp = 1.0-(1.0-eccent*eccent)/(2.0*eccent)*Math.log((1-eccent)/(1+eccent));
    if (Math.abs(Math.abs(q)-temp)<1.0E-6) {
      if (q<0.0) {
        return (-1.0*Proj4js.common.HALF_PI);
      } else {
        return Proj4js.common.HALF_PI;
      }
    }
    //var phi = 0.5* q/(1-eccent*eccent);
    var phi = Math.asin(0.5*q);
    var dphi;
    var sin_phi;
    var cos_phi;
    var con;
    for (var i=0;i<30;i++){
      sin_phi = Math.sin(phi);
      cos_phi = Math.cos(phi);
      con = eccent*sin_phi;
      dphi=Math.pow(1.0-con*con,2.0)/(2.0*cos_phi)*(q/(1-eccent*eccent)-sin_phi/(1.0-con*con)+0.5/eccent*Math.log((1.0-con)/(1.0+con)));
      phi+=dphi;
      if (Math.abs(dphi) <= .0000000001) {
        return phi;
      }
    }

    alert("IQSFN-CONV:Latitude failed to converge after 30 iterations");
    return (NaN);
  },

/* Function to eliminate roundoff errors in asin
----------------------------------------------*/
  asinz : function(x) {
@@ -1126,6 +1162,27 @@ Proj4js.common = {
  e2fn : function(x) {return(0.05859375*x*x*(1.0+0.75*x));},
  e3fn : function(x) {return(x*x*x*(35.0/3072.0));},
  mlfn : function(e0,e1,e2,e3,phi) {return(e0*phi-e1*Math.sin(2.0*phi)+e2*Math.sin(4.0*phi)-e3*Math.sin(6.0*phi));},
  e0fn  : function(x) {return(1.0-0.25*x*(1.0+x/16.0*(3.0+1.25*x)));},
  e1fn  : function(x) {return(0.375*x*(1.0+0.25*x*(1.0+0.46875*x)));},
  e2fn  : function(x) {return(0.05859375*x*x*(1.0+0.75*x));},
  e3fn  : function(x) {return(x*x*x*(35.0/3072.0));},
  mlfn  : function(e0,e1,e2,e3,phi) {return(e0*phi-e1*Math.sin(2.0*phi)+e2*Math.sin(4.0*phi)-e3*Math.sin(6.0*phi));},
  imlfn : function(ml, e0, e1, e2, e3) {
    var phi;
    var dphi;

    phi=ml/e0;
    for (var i=0;i<15;i++){
      dphi=(ml-(e0*phi-e1*Math.sin(2.0*phi)+e2*Math.sin(4.0*phi)-e3*Math.sin(6.0*phi)))/(e0-2.0*e1*Math.cos(2.0*phi)+4.0*e2*Math.cos(4.0*phi)-6.0*e3*Math.cos(6.0*phi));
      phi+=dphi;
      if (Math.abs(dphi) <= .0000000001) {
        return phi;
      }
    }

    Proj4js.reportError("IMLFN-CONV:Latitude failed to converge after 15 iterations");
    return NaN;
  },

  srat : function(esinp, exp) {
    return(Math.pow((1.0-esinp)/(1.0+esinp), exp));