Commit 9d59b0fc authored by Calvin Metcalf's avatar Calvin Metcalf
Browse files

replace imports of common with imports of individual things

parent 7bc9d2b7
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
var extend = require('./extend');
var common = require('./common');
var defs = require('./defs');
var constants = require('./constants/index');
var datum = require('./datum');
var projections = require('./projections/index');
var wkt = require('./wkt');
var projStr = require('./projString');

var EPSLN = 1.0e-10;
// ellipoid pj_set_ell.c
var SIXTH = 0.1666666666666666667;
/* 1/6 */
var RA4 = 0.04722222222222222222;
/* 17/360 */
var RA6 = 0.02215608465608465608;
function Projection(srsCode) {
  if (!(this instanceof Projection)) {
    return new Projection(srsCode);
@@ -104,7 +109,7 @@ Projection.prototype = {
    if (self.rf && !self.b) {
      self.b = (1.0 - 1.0 / self.rf) * self.a;
    }
    if (self.rf === 0 || Math.abs(self.a - self.b) < common.EPSLN) {
    if (self.rf === 0 || Math.abs(self.a - self.b) < EPSLN) {
      self.sphere = true;
      self.b = self.a;
    }
@@ -113,7 +118,7 @@ Projection.prototype = {
    self.es = (self.a2 - self.b2) / self.a2; // e ^ 2
    self.e = Math.sqrt(self.es); // eccentricity
    if (self.R_A) {
      self.a *= 1 - self.es * (common.SIXTH + self.es * (common.RA4 + self.es * common.RA6));
      self.a *= 1 - self.es * (SIXTH + self.es * (RA4 + self.es * RA6));
      self.a2 = self.a * self.a;
      self.b2 = self.b * self.b;
      self.es = 0;

lib/apply_gridshift.js

deleted100644 → 0
+0 −60
Original line number Diff line number Diff line
var common = require('./common');
module.exports = function(srs, inverse, point) {
  var i, l, gi, ct, epsilon;
  if (srs.grids === null || srs.grids.length === 0) {
    return -38; //are these error codes?
  }
  var input = {
    "x": point.x,
    "y": point.y
  };
  var output = {
    "x": Number.NaN,
    "y": Number.NaN
  };
  /* keep trying till we find a table that works */
  var onlyMandatoryGrids = false;
  for (i = 0, l = srs.grids.length; i < l; i++) {
    gi = srs.grids[i];
    onlyMandatoryGrids = gi.mandatory;
    ct = gi.grid;
    if (ct === null) {
      if (gi.mandatory) {
        this.reportError("unable to find '" + gi.name + "' grid.");
        return -48; //are these error codes?
      }
      continue; //optional grid
    }
    /* skip tables that don't match our point at all.  */
    epsilon = (Math.abs(ct.del[1]) + Math.abs(ct.del[0])) / 10000;
    if (ct.ll[1] - epsilon > input.y || ct.ll[0] - epsilon > input.x || ct.ll[1] + (ct.lim[1] - 1) * ct.del[1] + epsilon < input.y || ct.ll[0] + (ct.lim[0] - 1) * ct.del[0] + epsilon < input.x) {
      continue;
    }
    /* If we have child nodes, check to see if any of them apply. */
    /* TODO : only plain grid has been implemented ... */
    /* we found a more refined child node to use */
    /* load the grid shift info if we don't have it. */
    /* TODO : ..grids pre-loaded (as they can be huge ...) */
    /* skip numerical computing error when "null" grid (identity grid): */
    if (gi.name === "null") {
      output.x = input.x;
      output.y = input.y;
    }
    else {
      output = common.nad_cvt(input, inverse, ct);
    }
    if (!isNaN(output.x)) {
      break;
    }
  }
  if (isNaN(output.x)) {
    if (!onlyMandatoryGrids) {
      this.reportError("failed to find a grid shift table for location '" + input.x * common.R2D + " " + input.y * common.R2D + " tried: '" + srs.nadgrids + "'");
      return -48;
    }
    return -1; //FIXME: no shift applied ...
  }
  point.x = output.x;
  point.y = output.y;
  return 0;
};

lib/common.js

deleted100644 → 0
+0 −151
Original line number Diff line number Diff line
exports.PI = 3.141592653589793238; //Math.PI;
exports.HALF_PI = 1.570796326794896619; //Math.PI*0.5;
exports.TWO_PI = 6.283185307179586477; //Math.PI*2;
exports.FORTPI = 0.78539816339744833;
exports.R2D = 57.29577951308232088;
exports.D2R = 0.01745329251994329577;
exports.SEC_TO_RAD = 4.84813681109535993589914102357e-6;
/* SEC_TO_RAD = Pi/180/3600 */
exports.EPSLN = 1.0e-10;
exports.MAX_ITER = 20;
// following constants from geocent.c
exports.COS_67P5 = 0.38268343236508977;
/* cosine of 67.5 degrees */
exports.AD_C = 1.0026000;
/* Toms region 1 constant */

/* datum_type values */
exports.PJD_UNKNOWN = 0;
exports.PJD_3PARAM = 1;
exports.PJD_7PARAM = 2;
exports.PJD_GRIDSHIFT = 3;
exports.PJD_WGS84 = 4; // WGS84 or equivalent
exports.PJD_NODATUM = 5; // WGS84 or equivalent
exports.SRS_WGS84_SEMIMAJOR = 6378137; // only used in grid shift transforms
exports.SRS_WGS84_ESQUARED = 0.006694379990141316; //DGR: 2012-07-29

// ellipoid pj_set_ell.c
exports.SIXTH = 0.1666666666666666667;
/* 1/6 */
exports.RA4 = 0.04722222222222222222;
/* 17/360 */
exports.RA6 = 0.02215608465608465608;
/* 67/3024 */
exports.RV4 = 0.06944444444444444444;
/* 5/72 */
exports.RV6 = 0.04243827160493827160;
/* 55/1296 */

// Function to compute the constant small m which is the radius of
//   a parallel of latitude; phi; divided by the semimajor axis.
// -----------------------------------------------------------------
exports.msfnz = require('./common/msfnz');

// Function to compute the constant small t for use in the forward
//   computations in the Lambert Conformal Conic and the Polar
//   Stereographic projections.
// -----------------------------------------------------------------
exports.tsfnz = require('./common/tsfnz');

// Function to compute the latitude angle; phi2; for the inverse of the
//   Lambert Conformal Conic and Polar Stereographic projections.
// ----------------------------------------------------------------
exports.phi2z = require('./common/phi2z');

/* Function to compute constant small q which is the radius of a 
   parallel of latitude, phi, divided by the semimajor axis. 
------------------------------------------------------------*/
exports.qsfnz = require('./common/qsfnz');

/* Function to compute the inverse of qsfnz
------------------------------------------------------------*/
exports.iqsfnz = require('./common/iqsfnz');

/* Function to eliminate roundoff errors in asin
----------------------------------------------*/
exports.asinz = require('./common/asinz');

// following functions from gctpc cproj.c for transverse mercator projections
exports.e0fn = require('./common/e0fn');
exports.e1fn = require('./common/e1fn');
exports.e2fn = require('./common/e2fn');
exports.e3fn = require('./common/e3fn');
exports.mlfn = require('./common/mlfn');
exports.imlfn = require('./common/imlfn');

exports.srat = require('./common/srat');

// Function to return the sign of an argument
exports.sign = require('./common/sign');

// Function to adjust longitude to -180 to 180; input in radians
exports.adjust_lon = require('./common/adjust_lon');

// IGNF - DGR : algorithms used by IGN France

// Function to adjust latitude to -90 to 90; input in radians
exports.adjust_lat = require('./common/adjust_lat');

// Latitude Isometrique - close to tsfnz ...
exports.latiso = require('./common/latiso');

exports.fL = require('./common/fL');

// Inverse Latitude Isometrique - close to ph2z
exports.invlatiso = require('./common/invlatiso');

// Needed for Gauss Schreiber
// Original:  Denis Makarov (info@binarythings.com)
// Web Site:  http://www.binarythings.com
exports.sinh = require('./common/sinh');

exports.cosh = require('./common/cosh');

exports.tanh = require('./common/tanh');

exports.asinh = require('./common/asinh');

exports.acosh = require('./common/acosh');

exports.atanh = require('./common/atanh');

// Grande Normale
exports.gN = require('./common/gN');

//code from the PROJ.4 pj_mlfn.c file;  this may be useful for other projections
exports.pj_enfn = require('./common/pj_enfn');

exports.pj_mlfn = require('./common/pj_mlfn');

exports.pj_inv_mlfn = require('./common/pj_inv_mlfn');
exports.nadInterBreakout = require('./common/nadInterBreakout');
/**
 * Determine correction values
 * source: nad_intr.c (DGR: 2012-07-29)
 */
exports.nad_intr = require('./common/nad_intr');

/**
 * Correct value
 * source: nad_cvt.c (DGR: 2012-07-29)
 */
exports.inverseNadCvt = require('./common/inverseNadCvt');
exports.nad_cvt = require('./common/nad_cvt');

/* meridinal distance for ellipsoid and inverse
 **    8th degree - accurate to < 1e-5 meters when used in conjuction
 **		with typical major axis values.
 **	Inverse determines phi to EPS (1e-11) radians, about 1e-6 seconds.
 */
exports.C00 = 1;
exports.C02 = 0.25;
exports.C04 = 0.046875;
exports.C06 = 0.01953125;
exports.C08 = 0.01068115234375;
exports.C22 = 0.75;
exports.C44 = 0.46875;
exports.C46 = 0.01302083333333333333;
exports.C48 = 0.00712076822916666666;
exports.C66 = 0.36458333333333333333;
exports.C68 = 0.00569661458333333333;
exports.C88 = 0.3076171875;
+41 −33
Original line number Diff line number Diff line
var common = require('./common');
var HALF_PI = Math.PI/2;
var PJD_3PARAM = 1;
var PJD_7PARAM = 2;
var PJD_GRIDSHIFT = 3;
var PJD_WGS84 = 4; // WGS84 or equivalent
var PJD_NODATUM = 5; // WGS84 or equivalent
var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
var AD_C = 1.0026000;
var COS_67P5 = 0.38268343236508977;
var datum = function(proj) {
  if (!(this instanceof datum)) {
    return new datum(proj);
  }
  this.datum_type = common.PJD_WGS84; //default setting
  this.datum_type = PJD_WGS84; //default setting
  if (!proj) {
    return;
  }
  if (proj.datumCode && proj.datumCode === 'none') {
    this.datum_type = common.PJD_NODATUM;
    this.datum_type = PJD_NODATUM;
  }
  if (proj.datum_params) {
    for (var i = 0; i < proj.datum_params.length; i++) {
      proj.datum_params[i] = parseFloat(proj.datum_params[i]);
    }
    if (proj.datum_params[0] !== 0 || proj.datum_params[1] !== 0 || proj.datum_params[2] !== 0) {
      this.datum_type = common.PJD_3PARAM;
      this.datum_type = 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) {
        this.datum_type = common.PJD_7PARAM;
        proj.datum_params[3] *= common.SEC_TO_RAD;
        proj.datum_params[4] *= common.SEC_TO_RAD;
        proj.datum_params[5] *= common.SEC_TO_RAD;
        this.datum_type = PJD_7PARAM;
        proj.datum_params[3] *= SEC_TO_RAD;
        proj.datum_params[4] *= SEC_TO_RAD;
        proj.datum_params[5] *= SEC_TO_RAD;
        proj.datum_params[6] = (proj.datum_params[6] / 1000000.0) + 1.0;
      }
    }
  }
  // DGR 2011-03-21 : nadgrids support
  this.datum_type = proj.grids ? common.PJD_GRIDSHIFT : this.datum_type;
  this.datum_type = proj.grids ? 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 === common.PJD_GRIDSHIFT) {
  if (this.datum_type === PJD_GRIDSHIFT) {
    this.grids = proj.grids;
  }
};
@@ -54,13 +62,13 @@ datum.prototype = {
      // are considered identical
      return false;
    }
    else if (this.datum_type === common.PJD_3PARAM) {
    else if (this.datum_type === 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 === common.PJD_7PARAM) {
    else if (this.datum_type === 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 === common.PJD_GRIDSHIFT || dest.datum_type === common.PJD_GRIDSHIFT) {
    else if (this.datum_type === PJD_GRIDSHIFT || dest.datum_type === PJD_GRIDSHIFT) {
      //alert("ERROR: Grid shift transformations are not implemented.");
      //return false
      //DGR 2012-07-29 lazy ...
@@ -103,20 +111,20 @@ datum.prototype = {
     ** range as it may just be a rounding issue.  Also removed longitude
     ** test, it should be wrapped by Math.cos() and Math.sin().  NFW for PROJ.4, Sep/2001.
     */
    if (Latitude < -common.HALF_PI && Latitude > -1.001 * common.HALF_PI) {
      Latitude = -common.HALF_PI;
    if (Latitude < -HALF_PI && Latitude > -1.001 * HALF_PI) {
      Latitude = -HALF_PI;
    }
    else if (Latitude > common.HALF_PI && Latitude < 1.001 * common.HALF_PI) {
      Latitude = common.HALF_PI;
    else if (Latitude > HALF_PI && Latitude < 1.001 * HALF_PI) {
      Latitude = HALF_PI;
    }
    else if ((Latitude < -common.HALF_PI) || (Latitude > common.HALF_PI)) {
    else if ((Latitude < -HALF_PI) || (Latitude > HALF_PI)) {
      /* Latitude out of range */
      //..reportError('geocent:lat out of range:' + Latitude);
      return null;
    }

    if (Longitude > common.PI) {
      Longitude -= (2 * common.PI);
    if (Longitude > Math.PI) {
      Longitude -= (2 * Math.PI);
    }
    Sin_Lat = Math.sin(Latitude);
    Cos_Lat = Math.cos(Latitude);
@@ -176,7 +184,7 @@ datum.prototype = {
      /*  if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
       *  of ellipsoid (=center of mass), Latitude becomes PI/2 */
      if (RR / this.a < genau) {
        Latitude = common.HALF_PI;
        Latitude = HALF_PI;
        Height = -this.b;
        return;
      }
@@ -268,22 +276,22 @@ datum.prototype = {
    }
    else {
      if (Y > 0) {
        Longitude = common.HALF_PI;
        Longitude = HALF_PI;
      }
      else if (Y < 0) {
        Longitude = -common.HALF_PI;
        Longitude = -HALF_PI;
      }
      else {
        At_Pole = true;
        Longitude = 0.0;
        if (Z > 0.0) { /* north pole */
          Latitude = common.HALF_PI;
          Latitude = HALF_PI;
        }
        else if (Z < 0.0) { /* south pole */
          Latitude = -common.HALF_PI;
          Latitude = -HALF_PI;
        }
        else { /* center of earth */
          Latitude = common.HALF_PI;
          Latitude = HALF_PI;
          Height = -this.b;
          return;
        }
@@ -291,7 +299,7 @@ datum.prototype = {
    }
    W2 = X * X + Y * Y;
    W = Math.sqrt(W2);
    T0 = Z * common.AD_C;
    T0 = Z * AD_C;
    S0 = Math.sqrt(T0 * T0 + W2);
    Sin_B0 = T0 / S0;
    Cos_B0 = W / S0;
@@ -302,10 +310,10 @@ datum.prototype = {
    Sin_p1 = T1 / S1;
    Cos_p1 = Sum / S1;
    Rn = this.a / Math.sqrt(1.0 - this.es * Sin_p1 * Sin_p1);
    if (Cos_p1 >= common.COS_67P5) {
    if (Cos_p1 >= COS_67P5) {
      Height = W / Cos_p1 - Rn;
    }
    else if (Cos_p1 <= -common.COS_67P5) {
    else if (Cos_p1 <= -COS_67P5) {
      Height = W / -Cos_p1 - Rn;
    }
    else {
@@ -326,7 +334,7 @@ datum.prototype = {
  //  p = point to transform in geocentric coordinates (x,y,z)
  geocentric_to_wgs84: function(p) {

    if (this.datum_type === common.PJD_3PARAM) {
    if (this.datum_type === PJD_3PARAM) {
      // if( x[io] === HUGE_VAL )
      //    continue;
      p.x += this.datum_params[0];
@@ -334,7 +342,7 @@ datum.prototype = {
      p.z += this.datum_params[2];

    }
    else if (this.datum_type === common.PJD_7PARAM) {
    else if (this.datum_type === PJD_7PARAM) {
      var Dx_BF = this.datum_params[0];
      var Dy_BF = this.datum_params[1];
      var Dz_BF = this.datum_params[2];
@@ -359,7 +367,7 @@ datum.prototype = {
  //  point to transform in geocentric coordinates (x,y,z)
  geocentric_from_wgs84: function(p) {

    if (this.datum_type === common.PJD_3PARAM) {
    if (this.datum_type === PJD_3PARAM) {
      //if( x[io] === HUGE_VAL )
      //    continue;
      p.x -= this.datum_params[0];
@@ -367,7 +375,7 @@ datum.prototype = {
      p.z -= this.datum_params[2];

    }
    else if (this.datum_type === common.PJD_7PARAM) {
    else if (this.datum_type === PJD_7PARAM) {
      var Dx_BF = this.datum_params[0];
      var Dy_BF = this.datum_params[1];
      var Dz_BF = this.datum_params[2];
+17 −12
Original line number Diff line number Diff line
var common = require('./common');
var PJD_3PARAM = 1;
var PJD_7PARAM = 2;
var PJD_GRIDSHIFT = 3;
var PJD_NODATUM = 5; // WGS84 or equivalent
var SRS_WGS84_SEMIMAJOR = 6378137; // only used in grid shift transforms
var SRS_WGS84_ESQUARED = 0.006694379990141316; //DGR: 2012-07-29
module.exports = function(source, dest, point) {
  var wp, i, l;

  function checkParams(fallback) {
    return (fallback === common.PJD_3PARAM || fallback === common.PJD_7PARAM);
    return (fallback === PJD_3PARAM || fallback === PJD_7PARAM);
  }
  // Short cut if the datums are identical.
  if (source.compare_datums(dest)) {
@@ -13,7 +18,7 @@ module.exports = function(source, dest, point) {
  }

  // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
  if (source.datum_type === common.PJD_NODATUM || dest.datum_type === common.PJD_NODATUM) {
  if (source.datum_type === PJD_NODATUM || dest.datum_type === PJD_NODATUM) {
    return point;
  }

@@ -26,10 +31,10 @@ module.exports = function(source, dest, point) {

  var fallback = source.datum_type;
  // If this datum requires grid shifts, then apply it to geodetic coordinates.
  if (fallback === common.PJD_GRIDSHIFT) {
  if (fallback === PJD_GRIDSHIFT) {
    if (this.apply_gridshift(source, 0, point) === 0) {
      source.a = common.SRS_WGS84_SEMIMAJOR;
      source.es = common.SRS_WGS84_ESQUARED;
      source.a = SRS_WGS84_SEMIMAJOR;
      source.es = SRS_WGS84_ESQUARED;
    }
    else {
      // try 3 or 7 params transformation or nothing ?
@@ -48,16 +53,16 @@ module.exports = function(source, dest, point) {
        return point;
      }
      if (source.datum_params.length > 3) {
        fallback = common.PJD_7PARAM;
        fallback = PJD_7PARAM;
      }
      else {
        fallback = common.PJD_3PARAM;
        fallback = PJD_3PARAM;
      }
    }
  }
  if (dest.datum_type === common.PJD_GRIDSHIFT) {
    dest.a = common.SRS_WGS84_SEMIMAJOR;
    dest.es = common.SRS_WGS84_ESQUARED;
  if (dest.datum_type === PJD_GRIDSHIFT) {
    dest.a = SRS_WGS84_SEMIMAJOR;
    dest.es = SRS_WGS84_ESQUARED;
  }
  // Do we need to go through geocentric coordinates?
  if (source.es !== dest.es || source.a !== dest.a || checkParams(fallback) || checkParams(dest.datum_type)) {
@@ -79,7 +84,7 @@ module.exports = function(source, dest, point) {
    // CHECK_RETURN;
  }
  // Apply grid shift to destination if required
  if (dest.datum_type === common.PJD_GRIDSHIFT) {
  if (dest.datum_type === PJD_GRIDSHIFT) {
    this.apply_gridshift(dest, 1, point);
    // CHECK_RETURN;
  }
Loading