Commit 4a1ee418 authored by Calvin Metcalf's avatar Calvin Metcalf
Browse files

datum done

parent 56a9a6a7
Loading
Loading
Loading
Loading
+393 −410
Original line number Diff line number Diff line
@@ -4,8 +4,10 @@ proj4.datum = proj4.Class({

  initialize: function(proj) {
    this.datum_type = proj4.common.PJD_WGS84; //default setting
    if (!proj) { return; }
    if (proj.datumCode && proj.datumCode == 'none') {
    if (!proj) {
      return;
    }
    if (proj.datumCode && proj.datumCode === 'none') {
      this.datum_type = proj4.common.PJD_NODATUM;
    }
    if (proj.datum_params) {
@@ -16,8 +18,7 @@ proj4.datum = proj4.Class({
        this.datum_type = proj4.common.PJD_3PARAM;
      }
      if (proj.datum_params.length > 3) {
        if (proj.datum_params[3] !== 0 || proj.datum_params[4] !== 0 ||
            proj.datum_params[5] !== 0 || proj.datum_params[6] !== 0 ) {
        if (proj.datum_params[3] !== 0 || proj.datum_params[4] !== 0 || proj.datum_params[5] !== 0 || proj.datum_params[6] !== 0) {
          this.datum_type = proj4.common.PJD_7PARAM;
          proj.datum_params[3] *= proj4.common.SEC_TO_RAD;
          proj.datum_params[4] *= proj4.common.SEC_TO_RAD;
@@ -27,16 +28,14 @@ proj4.datum = proj4.Class({
      }
    }
    // DGR 2011-03-21 : nadgrids support
    this.datum_type = proj.grids?
      proj4.common.PJD_GRIDSHIFT
    : this.datum_type;
    this.datum_type = proj.grids ? proj4.common.PJD_GRIDSHIFT : this.datum_type;

    this.a = proj.a; //datum object also uses these values
    this.b = proj.b;
    this.es = proj.es;
    this.ep2 = proj.ep2;
    this.datum_params = proj.datum_params;
    if (this.datum_type==proj4.common.PJD_GRIDSHIFT) {
    if (this.datum_type === proj4.common.PJD_GRIDSHIFT) {
      this.grids = proj.grids;
    }
  },
@@ -47,29 +46,25 @@ proj4.datum = proj4.Class({
  compare_datums: function(dest) {
    if (this.datum_type !== dest.datum_type) {
      return false; // false, datums are not equal
    } else if( this.a !== dest.a || Math.abs(this.es-dest.es) > 0.000000000050 ) {
    }
    else if (this.a !== dest.a || Math.abs(this.es - dest.es) > 0.000000000050) {
      // the tolerence for es is to ensure that GRS80 and WGS84
      // are considered identical
      return false;
    } else if( this.datum_type == proj4.common.PJD_3PARAM ) {
      return (this.datum_params[0] == dest.datum_params[0] &&
              this.datum_params[1] == dest.datum_params[1] &&
              this.datum_params[2] == dest.datum_params[2]);
    } else if( this.datum_type == proj4.common.PJD_7PARAM ) {
      return (this.datum_params[0] == dest.datum_params[0] &&
              this.datum_params[1] == dest.datum_params[1] &&
              this.datum_params[2] == dest.datum_params[2] &&
              this.datum_params[3] == dest.datum_params[3] &&
              this.datum_params[4] == dest.datum_params[4] &&
              this.datum_params[5] == dest.datum_params[5] &&
              this.datum_params[6] == dest.datum_params[6]);
    } else if ( this.datum_type == proj4.common.PJD_GRIDSHIFT ||
                dest.datum_type == proj4.common.PJD_GRIDSHIFT ) {
    }
    else if (this.datum_type === proj4.common.PJD_3PARAM) {
      return (this.datum_params[0] === dest.datum_params[0] && this.datum_params[1] === dest.datum_params[1] && this.datum_params[2] === dest.datum_params[2]);
    }
    else if (this.datum_type === proj4.common.PJD_7PARAM) {
      return (this.datum_params[0] === dest.datum_params[0] && this.datum_params[1] === dest.datum_params[1] && this.datum_params[2] === dest.datum_params[2] && this.datum_params[3] === dest.datum_params[3] && this.datum_params[4] === dest.datum_params[4] && this.datum_params[5] === dest.datum_params[5] && this.datum_params[6] === dest.datum_params[6]);
    }
    else if (this.datum_type === proj4.common.PJD_GRIDSHIFT || dest.datum_type === proj4.common.PJD_GRIDSHIFT) {
      //alert("ERROR: Grid shift transformations are not implemented.");
      //return false
      //DGR 2012-07-29 lazy ...
      return this.nadgrids == dest.nadgrids;
    } else {
      return this.nadgrids === dest.nadgrids;
    }
    else {
      return true; // datums are equal
    }
  }, // cs_compare_datums()
@@ -108,15 +103,19 @@ proj4.datum = proj4.Class({
     */
    if (Latitude < -proj4.common.HALF_PI && Latitude > -1.001 * proj4.common.HALF_PI) {
      Latitude = -proj4.common.HALF_PI;
    } else if( Latitude > proj4.common.HALF_PI && Latitude < 1.001 * proj4.common.HALF_PI ) {
    }
    else if (Latitude > proj4.common.HALF_PI && Latitude < 1.001 * proj4.common.HALF_PI) {
      Latitude = proj4.common.HALF_PI;
    } else if ((Latitude < -proj4.common.HALF_PI) || (Latitude > proj4.common.HALF_PI)) {
    }
    else if ((Latitude < -proj4.common.HALF_PI) || (Latitude > proj4.common.HALF_PI)) {
      /* Latitude out of range */
      proj4.reportError('geocent:lat out of range:' + Latitude);
      return null;
    }

    if (Longitude > proj4.common.PI) Longitude -= (2*proj4.common.PI);
    if (Longitude > proj4.common.PI){
      Longitude -= (2 * proj4.common.PI);
    }
    Sin_Lat = Math.sin(Latitude);
    Cos_Lat = Math.cos(Latitude);
    Sin2_Lat = Sin_Lat * Sin_Lat;
@@ -135,7 +134,7 @@ proj4.datum = proj4.Class({
  geocentric_to_geodetic: function(p) {
    /* local defintions and variables */
    /* end-criterium of loop, accuracy of sin(Latitude) */
var genau = 1.E-12;
    var genau = 1e-12;
    var genau2 = (genau * genau);
    var maxiter = 30;

@@ -179,7 +178,8 @@ var maxiter = 30;
        Height = -this.b;
        return;
      }
    } else {
    }
    else {
      /*  ellipsoidal (geodetic) longitude
       *  interval: -PI < Longitude <= +PI */
      Longitude = Math.atan2(Y, X);
@@ -203,8 +203,7 @@ var maxiter = 30;

    /* loop to find sin(Latitude) resp. Latitude
     * until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
    do
    {
    do {
      iter++;
      RN = this.a / Math.sqrt(1.0 - this.es * SPHI0 * SPHI0);

@@ -262,34 +261,26 @@ var maxiter = 30;
    Z = parseFloat(Z);

    At_Pole = false;
    if (X !== 0.0)
    {
    if (X !== 0.0) {
      Longitude = Math.atan2(Y, X);
    }
    else
    {
        if (Y > 0)
        {
    else {
      if (Y > 0) {
        Longitude = proj4.common.HALF_PI;
      }
        else if (Y < 0)
        {
      else if (Y < 0) {
        Longitude = -proj4.common.HALF_PI;
      }
        else
        {
      else {
        At_Pole = true;
        Longitude = 0.0;
            if (Z > 0.0)
            {  /* north pole */
        if (Z > 0.0) { /* north pole */
          Latitude = proj4.common.HALF_PI;
        }
            else if (Z < 0.0)
            {  /* south pole */
        else if (Z < 0.0) { /* south pole */
          Latitude = -proj4.common.HALF_PI;
        }
            else
            {  /* center of earth */
        else { /* center of earth */
          Latitude = proj4.common.HALF_PI;
          Height = -this.b;
          return;
@@ -309,20 +300,16 @@ var maxiter = 30;
    Sin_p1 = T1 / S1;
    Cos_p1 = Sum / S1;
    Rn = this.a / Math.sqrt(1.0 - this.es * Sin_p1 * Sin_p1);
    if (Cos_p1 >= proj4.common.COS_67P5)
    {
    if (Cos_p1 >= proj4.common.COS_67P5) {
      Height = W / Cos_p1 - Rn;
    }
    else if (Cos_p1 <= -proj4.common.COS_67P5)
    {
    else if (Cos_p1 <= -proj4.common.COS_67P5) {
      Height = W / -Cos_p1 - Rn;
    }
    else
    {
    else {
      Height = Z / Sin_p1 + Rn * (this.es - 1.0);
    }
    if (At_Pole === false)
    {
    if (At_Pole === false) {
      Latitude = Math.atan(Sin_p1 / Cos_p1);
    }

@@ -337,17 +324,15 @@ var maxiter = 30;
  //  p = point to transform in geocentric coordinates (x,y,z)
  geocentric_to_wgs84: function(p) {

    if( this.datum_type == proj4.common.PJD_3PARAM )
    {
      // if( x[io] == HUGE_VAL )
    if (this.datum_type === proj4.common.PJD_3PARAM) {
      // if( x[io] === HUGE_VAL )
      //    continue;
      p.x += this.datum_params[0];
      p.y += this.datum_params[1];
      p.z += this.datum_params[2];

    }
    else if (this.datum_type == proj4.common.PJD_7PARAM)
    {
    else if (this.datum_type === proj4.common.PJD_7PARAM) {
      var Dx_BF = this.datum_params[0];
      var Dy_BF = this.datum_params[1];
      var Dz_BF = this.datum_params[2];
@@ -355,7 +340,7 @@ var maxiter = 30;
      var Ry_BF = this.datum_params[4];
      var Rz_BF = this.datum_params[5];
      var M_BF = this.datum_params[6];
      // if( x[io] == HUGE_VAL )
      // if( x[io] === HUGE_VAL )
      //    continue;
      var x_out = M_BF * (p.x - Rz_BF * p.y + Ry_BF * p.z) + Dx_BF;
      var y_out = M_BF * (Rz_BF * p.x + p.y - Rx_BF * p.z) + Dy_BF;
@@ -372,17 +357,15 @@ var maxiter = 30;
  //  point to transform in geocentric coordinates (x,y,z)
  geocentric_from_wgs84: function(p) {

    if( this.datum_type == proj4.common.PJD_3PARAM )
    {
      //if( x[io] == HUGE_VAL )
    if (this.datum_type === proj4.common.PJD_3PARAM) {
      //if( x[io] === HUGE_VAL )
      //    continue;
      p.x -= this.datum_params[0];
      p.y -= this.datum_params[1];
      p.z -= this.datum_params[2];

    }
    else if (this.datum_type == proj4.common.PJD_7PARAM)
    {
    else if (this.datum_type === proj4.common.PJD_7PARAM) {
      var Dx_BF = this.datum_params[0];
      var Dy_BF = this.datum_params[1];
      var Dz_BF = this.datum_params[2];
@@ -393,7 +376,7 @@ var maxiter = 30;
      var x_tmp = (p.x - Dx_BF) / M_BF;
      var y_tmp = (p.y - Dy_BF) / M_BF;
      var z_tmp = (p.z - Dz_BF) / M_BF;
      //if( x[io] == HUGE_VAL )
      //if( x[io] === HUGE_VAL )
      //    continue;

      p.x = x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp;