Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

proj4

Package Overview
Dependencies
Maintainers
2
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proj4 - npm Package Compare versions

Comparing version 2.3.15 to 2.3.16

lib/common/adjust_zone.js

4

bower.json
{
"name": "proj4",
"version": "2.3.15",
"version": "2.3.16-alpha",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",

@@ -24,2 +24,2 @@ "homepage": "https://github.com/proj4js/proj4js",

]
}
}
{
"name": "proj4",
"version": "2.3.15",
"version": "2.3.16-alpha",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",

@@ -17,2 +17,2 @@ "repo": "proj4js/proj4js",

]
}
}

@@ -64,3 +64,4 @@ var projs = [

alias: [
'./projs:./includedProjections'
'./projs:./includedProjections',
'./lib/version-browser:./lib/version'
]

@@ -67,0 +68,0 @@ }

@@ -6,2 +6,3 @@ module.exports = function(crs, denorm, point) {

var v, t, i;
var out = {};
for (i = 0; i < 3; i++) {

@@ -25,16 +26,16 @@ if (denorm && i === 2 && point.z === undefined) {

case 'e':
point[t] = v;
out[t] = v;
break;
case 'w':
point[t] = -v;
out[t] = -v;
break;
case 'n':
point[t] = v;
out[t] = v;
break;
case 's':
point[t] = -v;
out[t] = -v;
break;
case 'u':
if (point[t] !== undefined) {
point.z = v;
out.z = v;
}

@@ -44,3 +45,3 @@ break;

if (point[t] !== undefined) {
point.z = -v;
out.z = -v;
}

@@ -53,3 +54,3 @@ break;

}
return point;
return out;
};
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
var datum = require('./datumUtils');
function checkParams(type) {
return (type === PJD_3PARAM || type === PJD_7PARAM);
}
module.exports = function(source, dest, point) {
var wp, i, l;
function checkParams(fallback) {
return (fallback === PJD_3PARAM || fallback === PJD_7PARAM);
}
// Short cut if the datums are identical.
if (source.compare_datums(dest)) {
if (datum.compareDatums(source, dest)) {
return point; // in this case, zero is sucess,

@@ -25,76 +21,20 @@ // whereas cs_compare_datums returns 1 to indicate TRUE

//DGR: 2012-07-29 : add nadgrids support (begin)
var src_a = source.a;
var src_es = source.es;
// If this datum requires grid shifts, then apply it to geodetic coordinates.
var dst_a = dest.a;
var dst_es = dest.es;
// Do we need to go through geocentric coordinates?
if (source.es === dest.es && source.a === dest.a && !checkParams(source.datum_type) && !checkParams(dest.datum_type)) {
return point;
}
var fallback = source.datum_type;
// If this datum requires grid shifts, then apply it to geodetic coordinates.
if (fallback === PJD_GRIDSHIFT) {
if (this.apply_gridshift(source, 0, point) === 0) {
source.a = SRS_WGS84_SEMIMAJOR;
source.es = SRS_WGS84_ESQUARED;
}
else {
// try 3 or 7 params transformation or nothing ?
if (!source.datum_params) {
source.a = src_a;
source.es = source.es;
return point;
}
wp = 1;
for (i = 0, l = source.datum_params.length; i < l; i++) {
wp *= source.datum_params[i];
}
if (wp === 0) {
source.a = src_a;
source.es = source.es;
return point;
}
if (source.datum_params.length > 3) {
fallback = PJD_7PARAM;
}
else {
fallback = PJD_3PARAM;
}
}
// Convert to geocentric coordinates.
point = datum.geodeticToGeocentric(point, source.es, source.a);
// Convert between datums
if (checkParams(source.datum_type)) {
point = datum.geocentricToWgs84(point, source.datum_type, source.datum_params);
}
if (dest.datum_type === PJD_GRIDSHIFT) {
dest.a = SRS_WGS84_SEMIMAJOR;
dest.es = SRS_WGS84_ESQUARED;
if (checkParams(dest.datum_type)) {
point = datum.geocentricFromWgs84(point, dest.datum_type, dest.datum_params);
}
// Do we need to go through geocentric coordinates?
if (source.es !== dest.es || source.a !== dest.a || checkParams(fallback) || checkParams(dest.datum_type)) {
//DGR: 2012-07-29 : add nadgrids support (end)
// Convert to geocentric coordinates.
source.geodetic_to_geocentric(point);
// CHECK_RETURN;
// Convert between datums
if (checkParams(source.datum_type)) {
source.geocentric_to_wgs84(point);
// CHECK_RETURN;
}
if (checkParams(dest.datum_type)) {
dest.geocentric_from_wgs84(point);
// CHECK_RETURN;
}
// Convert back to geodetic coordinates
dest.geocentric_to_geodetic(point);
// CHECK_RETURN;
}
// Apply grid shift to destination if required
if (dest.datum_type === PJD_GRIDSHIFT) {
this.apply_gridshift(dest, 1, point);
// CHECK_RETURN;
}
return datum.geocentricToGeodetic(point, dest.es, dest.a, dest.b);
source.a = src_a;
source.es = src_es;
dest.a = dst_a;
dest.es = dst_es;
return point;
};

@@ -1,34 +0,26 @@

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);
function datum(datumCode, datum_params, a, b, es, ep2) {
var out = {};
out.datum_type = PJD_WGS84; //default setting
if (datumCode && datumCode === 'none') {
out.datum_type = PJD_NODATUM;
}
this.datum_type = PJD_WGS84; //default setting
if (!proj) {
return;
}
if (proj.datumCode && proj.datumCode === 'none') {
this.datum_type = PJD_NODATUM;
}
if (proj.datum_params) {
this.datum_params = proj.datum_params.map(parseFloat);
if (this.datum_params[0] !== 0 || this.datum_params[1] !== 0 || this.datum_params[2] !== 0) {
this.datum_type = PJD_3PARAM;
if (datum_params) {
out.datum_params = datum_params.map(parseFloat);
if (out.datum_params[0] !== 0 || out.datum_params[1] !== 0 || out.datum_params[2] !== 0) {
out.datum_type = PJD_3PARAM;
}
if (this.datum_params.length > 3) {
if (this.datum_params[3] !== 0 || this.datum_params[4] !== 0 || this.datum_params[5] !== 0 || this.datum_params[6] !== 0) {
this.datum_type = PJD_7PARAM;
this.datum_params[3] *= SEC_TO_RAD;
this.datum_params[4] *= SEC_TO_RAD;
this.datum_params[5] *= SEC_TO_RAD;
this.datum_params[6] = (this.datum_params[6] / 1000000.0) + 1.0;
if (out.datum_params.length > 3) {
if (out.datum_params[3] !== 0 || out.datum_params[4] !== 0 || out.datum_params[5] !== 0 || out.datum_params[6] !== 0) {
out.datum_type = PJD_7PARAM;
out.datum_params[3] *= SEC_TO_RAD;
out.datum_params[4] *= SEC_TO_RAD;
out.datum_params[5] *= SEC_TO_RAD;
out.datum_params[6] = (out.datum_params[6] / 1000000.0) + 1.0;
}

@@ -38,367 +30,10 @@ }

// DGR 2011-03-21 : nadgrids support
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;
if (this.datum_type === PJD_GRIDSHIFT) {
this.grids = proj.grids;
}
};
datum.prototype = {
out.a = a; //datum object also uses these values
out.b = b;
out.es = es;
out.ep2 = ep2;
return out;
}
/****************************************************************/
// cs_compare_datums()
// Returns TRUE if the two datums match, otherwise FALSE.
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) {
// the tolerence for es is to ensure that GRS80 and WGS84
// are considered identical
return false;
}
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 === 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 === PJD_GRIDSHIFT || dest.datum_type === PJD_GRIDSHIFT) {
//alert("ERROR: Grid shift transformations are not implemented.");
//return false
//DGR 2012-07-29 lazy ...
return this.nadgrids === dest.nadgrids;
}
else {
return true; // datums are equal
}
}, // cs_compare_datums()
/*
* The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
* (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
* according to the current ellipsoid parameters.
*
* Latitude : Geodetic latitude in radians (input)
* Longitude : Geodetic longitude in radians (input)
* Height : Geodetic height, in meters (input)
* X : Calculated Geocentric X coordinate, in meters (output)
* Y : Calculated Geocentric Y coordinate, in meters (output)
* Z : Calculated Geocentric Z coordinate, in meters (output)
*
*/
geodetic_to_geocentric: function(p) {
var Longitude = p.x;
var Latitude = p.y;
var Height = p.z ? p.z : 0; //Z value not always supplied
var X; // output
var Y;
var Z;
var Error_Code = 0; // GEOCENT_NO_ERROR;
var Rn; /* Earth radius at location */
var Sin_Lat; /* Math.sin(Latitude) */
var Sin2_Lat; /* Square of Math.sin(Latitude) */
var Cos_Lat; /* Math.cos(Latitude) */
/*
** Don't blow up if Latitude is just a little out of the value
** 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 < -HALF_PI && Latitude > -1.001 * HALF_PI) {
Latitude = -HALF_PI;
}
else if (Latitude > HALF_PI && Latitude < 1.001 * HALF_PI) {
Latitude = 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 > Math.PI) {
Longitude -= (2 * Math.PI);
}
Sin_Lat = Math.sin(Latitude);
Cos_Lat = Math.cos(Latitude);
Sin2_Lat = Sin_Lat * Sin_Lat;
Rn = this.a / (Math.sqrt(1.0e0 - this.es * Sin2_Lat));
X = (Rn + Height) * Cos_Lat * Math.cos(Longitude);
Y = (Rn + Height) * Cos_Lat * Math.sin(Longitude);
Z = ((Rn * (1 - this.es)) + Height) * Sin_Lat;
p.x = X;
p.y = Y;
p.z = Z;
return Error_Code;
}, // cs_geodetic_to_geocentric()
geocentric_to_geodetic: function(p) {
/* local defintions and variables */
/* end-criterium of loop, accuracy of sin(Latitude) */
var genau = 1e-12;
var genau2 = (genau * genau);
var maxiter = 30;
var P; /* distance between semi-minor axis and location */
var RR; /* distance between center and location */
var CT; /* sin of geocentric latitude */
var ST; /* cos of geocentric latitude */
var RX;
var RK;
var RN; /* Earth radius at location */
var CPHI0; /* cos of start or old geodetic latitude in iterations */
var SPHI0; /* sin of start or old geodetic latitude in iterations */
var CPHI; /* cos of searched geodetic latitude */
var SPHI; /* sin of searched geodetic latitude */
var SDPHI; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
var At_Pole; /* indicates location is in polar region */
var iter; /* # of continous iteration, max. 30 is always enough (s.a.) */
var X = p.x;
var Y = p.y;
var Z = p.z ? p.z : 0.0; //Z value not always supplied
var Longitude;
var Latitude;
var Height;
At_Pole = false;
P = Math.sqrt(X * X + Y * Y);
RR = Math.sqrt(X * X + Y * Y + Z * Z);
/* special cases for latitude and longitude */
if (P / this.a < genau) {
/* special case, if P=0. (X=0., Y=0.) */
At_Pole = true;
Longitude = 0.0;
/* 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 = HALF_PI;
Height = -this.b;
return;
}
}
else {
/* ellipsoidal (geodetic) longitude
* interval: -PI < Longitude <= +PI */
Longitude = Math.atan2(Y, X);
}
/* --------------------------------------------------------------
* Following iterative algorithm was developped by
* "Institut for Erdmessung", University of Hannover, July 1988.
* Internet: www.ife.uni-hannover.de
* Iterative computation of CPHI,SPHI and Height.
* Iteration of CPHI and SPHI to 10**-12 radian resp.
* 2*10**-7 arcsec.
* --------------------------------------------------------------
*/
CT = Z / RR;
ST = P / RR;
RX = 1.0 / Math.sqrt(1.0 - this.es * (2.0 - this.es) * ST * ST);
CPHI0 = ST * (1.0 - this.es) * RX;
SPHI0 = CT * RX;
iter = 0;
/* loop to find sin(Latitude) resp. Latitude
* until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
do {
iter++;
RN = this.a / Math.sqrt(1.0 - this.es * SPHI0 * SPHI0);
/* ellipsoidal (geodetic) height */
Height = P * CPHI0 + Z * SPHI0 - RN * (1.0 - this.es * SPHI0 * SPHI0);
RK = this.es * RN / (RN + Height);
RX = 1.0 / Math.sqrt(1.0 - RK * (2.0 - RK) * ST * ST);
CPHI = ST * (1.0 - RK) * RX;
SPHI = CT * RX;
SDPHI = SPHI * CPHI0 - CPHI * SPHI0;
CPHI0 = CPHI;
SPHI0 = SPHI;
}
while (SDPHI * SDPHI > genau2 && iter < maxiter);
/* ellipsoidal (geodetic) latitude */
Latitude = Math.atan(SPHI / Math.abs(CPHI));
p.x = Longitude;
p.y = Latitude;
p.z = Height;
return p;
}, // cs_geocentric_to_geodetic()
/** Convert_Geocentric_To_Geodetic
* The method used here is derived from 'An Improved Algorithm for
* Geocentric to Geodetic Coordinate Conversion', by Ralph Toms, Feb 1996
*/
geocentric_to_geodetic_noniter: function(p) {
var X = p.x;
var Y = p.y;
var Z = p.z ? p.z : 0; //Z value not always supplied
var Longitude;
var Latitude;
var Height;
var W; /* distance from Z axis */
var W2; /* square of distance from Z axis */
var T0; /* initial estimate of vertical component */
var T1; /* corrected estimate of vertical component */
var S0; /* initial estimate of horizontal component */
var S1; /* corrected estimate of horizontal component */
var Sin_B0; /* Math.sin(B0), B0 is estimate of Bowring aux variable */
var Sin3_B0; /* cube of Math.sin(B0) */
var Cos_B0; /* Math.cos(B0) */
var Sin_p1; /* Math.sin(phi1), phi1 is estimated latitude */
var Cos_p1; /* Math.cos(phi1) */
var Rn; /* Earth radius at location */
var Sum; /* numerator of Math.cos(phi1) */
var At_Pole; /* indicates location is in polar region */
X = parseFloat(X); // cast from string to float
Y = parseFloat(Y);
Z = parseFloat(Z);
At_Pole = false;
if (X !== 0.0) {
Longitude = Math.atan2(Y, X);
}
else {
if (Y > 0) {
Longitude = HALF_PI;
}
else if (Y < 0) {
Longitude = -HALF_PI;
}
else {
At_Pole = true;
Longitude = 0.0;
if (Z > 0.0) { /* north pole */
Latitude = HALF_PI;
}
else if (Z < 0.0) { /* south pole */
Latitude = -HALF_PI;
}
else { /* center of earth */
Latitude = HALF_PI;
Height = -this.b;
return;
}
}
}
W2 = X * X + Y * Y;
W = Math.sqrt(W2);
T0 = Z * AD_C;
S0 = Math.sqrt(T0 * T0 + W2);
Sin_B0 = T0 / S0;
Cos_B0 = W / S0;
Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;
T1 = Z + this.b * this.ep2 * Sin3_B0;
Sum = W - this.a * this.es * Cos_B0 * Cos_B0 * Cos_B0;
S1 = Math.sqrt(T1 * T1 + Sum * Sum);
Sin_p1 = T1 / S1;
Cos_p1 = Sum / S1;
Rn = this.a / Math.sqrt(1.0 - this.es * Sin_p1 * Sin_p1);
if (Cos_p1 >= COS_67P5) {
Height = W / Cos_p1 - Rn;
}
else if (Cos_p1 <= -COS_67P5) {
Height = W / -Cos_p1 - Rn;
}
else {
Height = Z / Sin_p1 + Rn * (this.es - 1.0);
}
if (At_Pole === false) {
Latitude = Math.atan(Sin_p1 / Cos_p1);
}
p.x = Longitude;
p.y = Latitude;
p.z = Height;
return p;
}, // geocentric_to_geodetic_noniter()
/****************************************************************/
// pj_geocentic_to_wgs84( p )
// p = point to transform in geocentric coordinates (x,y,z)
geocentric_to_wgs84: function(p) {
if (this.datum_type === 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 === PJD_7PARAM) {
var Dx_BF = this.datum_params[0];
var Dy_BF = this.datum_params[1];
var Dz_BF = this.datum_params[2];
var Rx_BF = this.datum_params[3];
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 )
// 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;
var z_out = M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF;
p.x = x_out;
p.y = y_out;
p.z = z_out;
}
}, // cs_geocentric_to_wgs84
/****************************************************************/
// pj_geocentic_from_wgs84()
// coordinate system definition,
// point to transform in geocentric coordinates (x,y,z)
geocentric_from_wgs84: function(p) {
if (this.datum_type === 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 === PJD_7PARAM) {
var Dx_BF = this.datum_params[0];
var Dy_BF = this.datum_params[1];
var Dz_BF = this.datum_params[2];
var Rx_BF = this.datum_params[3];
var Ry_BF = this.datum_params[4];
var Rz_BF = this.datum_params[5];
var M_BF = this.datum_params[6];
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 )
// continue;
p.x = x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp;
p.y = -Rz_BF * x_tmp + y_tmp + Rx_BF * z_tmp;
p.z = Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp;
} //cs_geocentric_from_wgs84()
}
};
/** point object, nothing fancy, just allows values to be
passed back and forth by reference rather than by value.
Other point classes may be used as long as they have
x and y properties, which will get modified in the transform method.
*/
module.exports = datum;

@@ -1,6 +0,1 @@

var Datum = require('./constants/Datum');
var Ellipsoid = require('./constants/Ellipsoid');
var extend = require('./extend');
var datum = require('./datum');
var EPSLN = 1.0e-10;
// ellipoid pj_set_ell.c

@@ -12,46 +7,48 @@ var SIXTH = 0.1666666666666666667;

var RA6 = 0.02215608465608465608;
module.exports = function(json) {
// DGR 2011-03-20 : nagrids -> nadgrids
if (json.datumCode && json.datumCode !== 'none') {
var datumDef = Datum[json.datumCode];
if (datumDef) {
json.datum_params = datumDef.towgs84 ? datumDef.towgs84.split(',') : null;
json.ellps = datumDef.ellipse;
json.datumName = datumDef.datumName ? datumDef.datumName : json.datumCode;
var EPSLN = 1.0e-10;
var Ellipsoid = require('./constants/Ellipsoid');
exports.eccentricity = function(a, b, rf, R_A) {
var a2 = a * a; // used in geocentric
var b2 = b * b; // used in geocentric
var es = (a2 - b2) / a2; // e ^ 2
var e = 0;
if (R_A) {
a *= 1 - es * (SIXTH + es * (RA4 + es * RA6));
a2 = a * a;
es = 0;
} else {
e = Math.sqrt(es); // eccentricity
}
var ep2 = (a2 - b2) / b2; // used in geocentric
return {
es: es,
e: e,
ep2: ep2
};
};
exports.sphere = function (a, b, rf, ellps, sphere) {
if (!a) { // do we have an ellipsoid?
var ellipse = Ellipsoid[ellps];
if (!ellipse) {
ellipse = Ellipsoid.WGS84;
}
a = ellipse.a;
b = ellipse.b;
rf = ellipse.rf;
}
if (!json.a) { // do we have an ellipsoid?
var ellipse = Ellipsoid[json.ellps] ? Ellipsoid[json.ellps] : Ellipsoid.WGS84;
extend(json, ellipse);
if (rf && !b) {
b = (1.0 - 1.0 / rf) * a;
}
if (json.rf && !json.b) {
json.b = (1.0 - 1.0 / json.rf) * json.a;
if (rf === 0 || Math.abs(a - b) < EPSLN) {
sphere = true;
b = a;
}
if (json.rf === 0 || Math.abs(json.a - json.b) < EPSLN) {
json.sphere = true;
json.b = json.a;
}
json.a2 = json.a * json.a; // used in geocentric
json.b2 = json.b * json.b; // used in geocentric
json.es = (json.a2 - json.b2) / json.a2; // e ^ 2
json.e = Math.sqrt(json.es); // eccentricity
if (json.R_A) {
json.a *= 1 - json.es * (SIXTH + json.es * (RA4 + json.es * RA6));
json.a2 = json.a * json.a;
json.b2 = json.b * json.b;
json.es = 0;
}
json.ep2 = (json.a2 - json.b2) / json.b2; // used in geocentric
if (!json.k0) {
json.k0 = 1.0; //default value
}
//DGR 2010-11-12: axis
if (!json.axis) {
json.axis = "enu";
}
if (!json.datum) {
json.datum = datum(json);
}
return json;
return {
a: a,
b: b,
rf: rf,
sphere: sphere
};
};

@@ -6,8 +6,8 @@ var proj4 = require('./core');

proj4.Point = require('./Point');
proj4.toPoint = require("./common/toPoint");
proj4.toPoint = require('./common/toPoint');
proj4.defs = require('./defs');
proj4.transform = require('./transform');
proj4.mgrs = require('mgrs');
proj4.version = require('../package.json').version;
proj4.version = require('./version');
require('./includedProjections')(proj4);
module.exports = proj4;
module.exports = proj4;

@@ -10,7 +10,8 @@ var defs = require('./defs');

}
var codeWords = ['GEOGCS','GEOCCS','PROJCS','LOCAL_CS'];
function testWKT(code){
var codeWords = ['GEOGCS','GEOCCS','PROJCS','LOCAL_CS'];
return codeWords.reduce(function(a,b){
return a+1+code.indexOf(b);
},0);
return codeWords.some(function (word) {
return code.indexOf(word) > -1;
});
}

@@ -26,6 +27,6 @@ function testProj(code){

}
else if (testWKT(code)) {
if (testWKT(code)) {
return wkt(code);
}
else if (testProj(code)) {
if (testProj(code)) {
return projStr(code);

@@ -38,2 +39,2 @@ }

module.exports = parse;
module.exports = parse;

@@ -1,6 +0,9 @@

var parseCode = require("./parseCode");
var parseCode = require('./parseCode');
var extend = require('./extend');
var projections = require('./projections');
var deriveConstants = require('./deriveConstants');
var Datum = require('./constants/Datum');
var datum = require('./datum');
function Projection(srsCode,callback) {

@@ -20,12 +23,45 @@ if (!(this instanceof Projection)) {

}
var modifiedJSON = deriveConstants(json);
var ourProj = Projection.projections.get(modifiedJSON.projName);
if(ourProj){
extend(this, modifiedJSON);
extend(this, ourProj);
this.init();
callback(null, this);
}else{
var ourProj = Projection.projections.get(json.projName);
if(!ourProj){
callback(srsCode);
return;
}
if (json.datumCode && json.datumCode !== 'none') {
var datumDef = Datum[json.datumCode];
if (datumDef) {
json.datum_params = datumDef.towgs84 ? datumDef.towgs84.split(',') : null;
json.ellps = datumDef.ellipse;
json.datumName = datumDef.datumName ? datumDef.datumName : json.datumCode;
}
}
json.k0 = json.k0 || 1.0;
json.axis = json.axis || 'enu';
var sphere = deriveConstants.sphere(json.a, json.b, json.rf, json.ellps, json.sphere);
var ecc = deriveConstants.eccentricity(sphere.a, sphere.b, sphere.rf, json.R_A);
var datumObj = json.datum || datum(json.datumCode, json.datum_params, sphere.a, sphere.b, ecc.es, ecc.ep2);
extend(this, json); // transfer everything over from the projection because we don't know what we'll need
extend(this, ourProj); // transfer all the methods from the projection
// copy the 4 things over we calulated in deriveConstants.sphere
this.a = sphere.a;
this.b = sphere.b;
this.rf = sphere.rf;
this.sphere = sphere.sphere;
// copy the 3 things we calculated in deriveConstants.eccentricity
this.es = ecc.es;
this.e = ecc.e;
this.ep2 = ecc.ep2;
// add in the datum object
this.datum = datumObj;
// init the projection
this.init();
// legecy callback from back in the day when it went to spatialreference.org
callback(null, this);
}

@@ -32,0 +68,0 @@ Projection.projections = projections;

@@ -1,18 +0,22 @@

var e0fn = require('../common/e0fn');
var e1fn = require('../common/e1fn');
var e2fn = require('../common/e2fn');
var e3fn = require('../common/e3fn');
var mlfn = require('../common/mlfn');
// Heavily based on this tmerc projection implementation
// https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/tmerc.js
var pj_enfn = require('../common/pj_enfn');
var pj_mlfn = require('../common/pj_mlfn');
var pj_inv_mlfn = require('../common/pj_inv_mlfn');
var adjust_lon = require('../common/adjust_lon');
var HALF_PI = Math.PI/2;
var HALF_PI = Math.PI / 2;
var EPSLN = 1.0e-10;
var sign = require('../common/sign');
var asinz = require('../common/asinz');
exports.init = function() {
this.e0 = e0fn(this.es);
this.e1 = e1fn(this.es);
this.e2 = e2fn(this.es);
this.e3 = e3fn(this.es);
this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
this.x0 = this.x0 !== undefined ? this.x0 : 0;
this.y0 = this.y0 !== undefined ? this.y0 : 0;
this.long0 = this.long0 !== undefined ? this.long0 : 0;
this.lat0 = this.lat0 !== undefined ? this.lat0 : 0;
if (this.es) {
this.en = pj_enfn(this.es);
this.ml0 = pj_mlfn(this.lat0, Math.sin(this.lat0), Math.cos(this.lat0), this.en);
}
};

@@ -34,14 +38,30 @@

if (this.sphere) {
if (!this.es) {
var b = cos_phi * Math.sin(delta_lon);
if ((Math.abs(Math.abs(b) - 1)) < 0.0000000001) {
if ((Math.abs(Math.abs(b) - 1)) < EPSLN) {
return (93);
}
else {
x = 0.5 * this.a * this.k0 * Math.log((1 + b) / (1 - b));
con = Math.acos(cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - b * b));
x = 0.5 * this.a * this.k0 * Math.log((1 + b) / (1 - b)) + this.x0;
y = cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - Math.pow(b, 2));
b = Math.abs(y);
if (b >= 1) {
if ((b - 1) > EPSLN) {
return (93);
}
else {
y = 0;
}
}
else {
y = Math.acos(y);
}
if (lat < 0) {
con = -con;
y = -y;
}
y = this.a * this.k0 * (con - this.lat0);
y = this.a * this.k0 * (y - this.lat0) + this.y0;
}

@@ -53,14 +73,27 @@ }

var c = this.ep2 * Math.pow(cos_phi, 2);
var tq = Math.tan(lat);
var cs = Math.pow(c, 2);
var tq = Math.abs(cos_phi) > EPSLN ? Math.tan(lat) : 0;
var t = Math.pow(tq, 2);
var ts = Math.pow(t, 2);
con = 1 - this.es * Math.pow(sin_phi, 2);
var n = this.a / Math.sqrt(con);
var ml = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, lat);
al = al / Math.sqrt(con);
var ml = pj_mlfn(lat, sin_phi, cos_phi, this.en);
x = this.k0 * n * al * (1 + als / 6 * (1 - t + c + als / 20 * (5 - 18 * t + Math.pow(t, 2) + 72 * c - 58 * this.ep2))) + this.x0;
y = this.k0 * (ml - this.ml0 + n * tq * (als * (0.5 + als / 24 * (5 - t + 9 * c + 4 * Math.pow(c, 2) + als / 30 * (61 - 58 * t + Math.pow(t, 2) + 600 * c - 330 * this.ep2))))) + this.y0;
x = this.a * (this.k0 * al * (1 +
als / 6 * (1 - t + c +
als / 20 * (5 - 18 * t + ts + 14 * c - 58 * t * c +
als / 42 * (61 + 179 * ts - ts * t - 479 * t))))) +
this.x0;
y = this.a * (this.k0 * (ml - this.ml0 +
sin_phi * delta_lon * al / 2 * (1 +
als / 12 * (5 - t + 9 * c + 4 * cs +
als / 30 * (61 + ts - 58 * t + 270 * c - 330 * t * c +
als / 56 * (1385 + 543 * ts - ts * t - 3111 * t)))))) +
this.y0;
}
p.x = x;
p.y = y;
return p;

@@ -74,19 +107,20 @@ };

var con, phi;
var delta_phi;
var i;
var max_iter = 6;
var lat, lon;
var x = (p.x - this.x0) * (1 / this.a);
var y = (p.y - this.y0) * (1 / this.a);
if (this.sphere) {
var f = Math.exp(p.x / (this.a * this.k0));
if (!this.es) {
var f = Math.exp(x / this.k0);
var g = 0.5 * (f - 1 / f);
var temp = this.lat0 + p.y / (this.a * this.k0);
var temp = this.lat0 + y / this.k0;
var h = Math.cos(temp);
con = Math.sqrt((1 - h * h) / (1 + g * g));
lat = asinz(con);
if (temp < 0) {
con = Math.sqrt((1 - Math.pow(h, 2)) / (1 + Math.pow(g, 2)));
lat = Math.asin(con);
if (y < 0) {
lat = -lat;
}
if ((g === 0) && (h === 0)) {
lon = this.long0;
lon = 0;
}

@@ -98,21 +132,9 @@ else {

else { // ellipsoidal form
var x = p.x - this.x0;
var y = p.y - this.y0;
con = this.ml0 + y / this.k0;
phi = pj_inv_mlfn(con, this.es, this.en);
con = (this.ml0 + y / this.k0) / this.a;
phi = con;
for (i = 0; true; i++) {
delta_phi = ((con + this.e1 * Math.sin(2 * phi) - this.e2 * Math.sin(4 * phi) + this.e3 * Math.sin(6 * phi)) / this.e0) - phi;
phi += delta_phi;
if (Math.abs(delta_phi) <= EPSLN) {
break;
}
if (i >= max_iter) {
return (95);
}
} // for()
if (Math.abs(phi) < HALF_PI) {
var sin_phi = Math.sin(phi);
var cos_phi = Math.cos(phi);
var tan_phi = Math.tan(phi);
var tan_phi = Math.abs(cos_phi) > EPSLN ? Math.tan(phi) : 0;
var c = this.ep2 * Math.pow(cos_phi, 2);

@@ -123,18 +145,28 @@ var cs = Math.pow(c, 2);

con = 1 - this.es * Math.pow(sin_phi, 2);
var n = this.a / Math.sqrt(con);
var r = n * (1 - this.es) / con;
var d = x / (n * this.k0);
var d = x * Math.sqrt(con) / this.k0;
var ds = Math.pow(d, 2);
lat = phi - (n * tan_phi * ds / r) * (0.5 - ds / 24 * (5 + 3 * t + 10 * c - 4 * cs - 9 * this.ep2 - ds / 30 * (61 + 90 * t + 298 * c + 45 * ts - 252 * this.ep2 - 3 * cs)));
lon = adjust_lon(this.long0 + (d * (1 - ds / 6 * (1 + 2 * t + c - ds / 20 * (5 - 2 * c + 28 * t - 3 * cs + 8 * this.ep2 + 24 * ts))) / cos_phi));
con = con * tan_phi;
lat = phi - (con * ds / (1 - this.es)) * 0.5 * (1 -
ds / 12 * (5 + 3 * t - 9 * c * t + c - 4 * cs -
ds / 30 * (61 + 90 * t - 252 * c * t + 45 * ts + 46 * c -
ds / 56 * (1385 + 3633 * t + 4095 * ts + 1574 * ts * t))));
lon = adjust_lon(this.long0 + (d * (1 -
ds / 6 * (1 + 2 * t + c -
ds / 20 * (5 + 28 * t + 24 * ts + 8 * c * t + 6 * c -
ds / 42 * (61 + 662 * t + 1320 * ts + 720 * ts * t)))) / cos_phi));
}
else {
lat = HALF_PI * sign(y);
lon = this.long0;
lon = 0;
}
}
p.x = lon;
p.y = lat;
return p;
};
exports.names = ["Transverse_Mercator", "Transverse Mercator", "tmerc"];

@@ -1,10 +0,14 @@

var D2R = 0.01745329251994329577;
var adjust_zone = require('../common/adjust_zone');
var tmerc = require('./tmerc');
exports.dependsOn = 'tmerc';
exports.init = function() {
if (!this.zone) {
var zone = adjust_zone(this.zone, this.long0);
if (!zone) {
return;
}
this.lat0 = 0;
this.long0 = ((6 * Math.abs(this.zone)) - 183) * D2R;
this.long0 = (zone + 0.5) * Math.PI / 30 - Math.PI;
this.x0 = 500000;

@@ -18,2 +22,3 @@ this.y0 = this.utmSouth ? 10000000 : 0;

};
exports.names = ["Universal Transverse Mercator System", "utm"];

@@ -7,12 +7,12 @@ var D2R = 0.01745329251994329577;

var self = {};
var paramObj = {};
defData.split("+").map(function(v) {
var paramObj = defData.split('+').map(function(v) {
return v.trim();
}).filter(function(a) {
return a;
}).forEach(function(a) {
var split = a.split("=");
}).reduce(function(p, a) {
var split = a.split('=');
split.push(true);
paramObj[split[0].toLowerCase()] = split[1];
});
p[split[0].toLowerCase()] = split[1];
return p;
}, {});
var paramName, paramVal, paramOutname;

@@ -19,0 +19,0 @@ var params = {

@@ -9,2 +9,5 @@ var D2R = 0.01745329251994329577;

var toPoint = require('./common/toPoint');
function checkNotWGS(source, dest) {
return ((source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM) && dest.datumCode !== 'WGS84') || ((dest.datum.datum_type === PJD_3PARAM || dest.datum.datum_type === PJD_7PARAM) && source.datumCode !== 'WGS84');
}
module.exports = function transform(source, dest, point) {

@@ -15,27 +18,28 @@ var wgs84;

}
function checkNotWGS(source, dest) {
return ((source.datum.datum_type === PJD_3PARAM || source.datum.datum_type === PJD_7PARAM) && dest.datumCode !== "WGS84");
}
// Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
if (source.datum && dest.datum && (checkNotWGS(source, dest) || checkNotWGS(dest, source))) {
if (source.datum && dest.datum && checkNotWGS(source, dest)) {
wgs84 = new proj('WGS84');
transform(source, wgs84, point);
point = transform(source, wgs84, point);
source = wgs84;
}
// DGR, 2010/11/12
if (source.axis !== "enu") {
adjust_axis(source, false, point);
if (source.axis !== 'enu') {
point = adjust_axis(source, false, point);
}
// Transform source points to long/lat, if they aren't already.
if (source.projName === "longlat") {
point.x *= D2R; // convert degrees to radians
point.y *= D2R;
if (source.projName === 'longlat') {
point = {
x: point.x * D2R,
y: point.y * D2R
};
}
else {
if (source.to_meter) {
point.x *= source.to_meter;
point.y *= source.to_meter;
point = {
x: point.x * source.to_meter,
y: point.y * source.to_meter
};
}
source.inverse(point); // Convert Cartesian to longlat
point = source.inverse(point); // Convert Cartesian to longlat
}

@@ -52,15 +56,21 @@ // Adjust for the prime meridian if necessary

if (dest.from_greenwich) {
point.x -= dest.from_greenwich;
point = {
x: point.x - dest.grom_greenwich,
y: point.y
};
}
if (dest.projName === "longlat") {
if (dest.projName === 'longlat') {
// convert radians to decimal degrees
point.x *= R2D;
point.y *= R2D;
}
else { // else project
dest.forward(point);
point = {
x: point.x * R2D,
y: point.y * R2D
};
} else { // else project
point = dest.forward(point);
if (dest.to_meter) {
point.x /= dest.to_meter;
point.y /= dest.to_meter;
point = {
x: point.x / dest.to_meter,
y: point.y / dest.to_meter
};
}

@@ -70,7 +80,7 @@ }

// DGR, 2010/11/12
if (dest.axis !== "enu") {
adjust_axis(dest, true, point);
if (dest.axis !== 'enu') {
return adjust_axis(dest, true, point);
}
return point;
};
};
{
"name": "proj4",
"version": "2.3.15",
"version": "2.3.16",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",

@@ -19,11 +19,2 @@ "main": "lib/index.js",

"license": "MIT",
"jam": {
"main": "dist/proj4.js",
"include": [
"dist/proj4.js",
"README.md",
"AUTHORS",
"LICENSE.md"
]
},
"devDependencies": {

@@ -44,5 +35,8 @@ "grunt-cli": "~0.1.13",

},
"browser": {
"./lib/version.js": "./lib/version-browser.js"
},
"dependencies": {
"mgrs": "~0.0.2"
}
}
}

@@ -14,3 +14,2 @@ # PROJ4JS [![Build Status](https://travis-ci.org/proj4js/proj4js.svg)](https://travis-ci.org/proj4js/proj4js)

bower install proj4
jam install proj4
component install proj4js/proj4js

@@ -118,2 +117,10 @@ ```

## TypeScript
TypeScript implementation was added to the [DefinitelyTyped repository](https://github.com/DefinitelyTyped/DefinitelyTyped).
```bash
$ npm install --save @types/proj4
```
## Developing

@@ -120,0 +127,0 @@ to set up build tools make sure you have node and grunt-cli installed and then run `npm install`

@@ -28,4 +28,4 @@ // You can do this in the grunt config for each mocha task, see the `options` config

var rslt = proj4(sweref99tm, rt90).forward([319180, 6399862]);
assert.closeTo(rslt[0], 1271137.927154, 0.000001);
assert.closeTo(rslt[1], 6404230.291456, 0.000001);
assert.closeTo(rslt[0], 1271137.9275601401, 0.000001);
assert.closeTo(rslt[1], 6404230.291448903, 0.000001);
});

@@ -36,6 +36,7 @@ it('should work with a proj object', function() {

var rslt = proj4(sweref99tm, rt90).forward([319180, 6399862]);
assert.closeTo(rslt[0], 1271137.927154, 0.000001);
assert.closeTo(rslt[1], 6404230.291456, 0.000001);
assert.closeTo(rslt[0], 1271137.9275601401, 0.000001);
assert.closeTo(rslt[1], 6404230.291448903, 0.000001);
});
});
describe('proj4', function() {

@@ -42,0 +43,0 @@ describe('core', function() {

@@ -150,3 +150,3 @@ var testPoints = [

ll:[5, 25],
xy:[-308919.1462828873, 2788738.252386554],
xy:[-308919.1234711099, 2788738.255936392],
acc:{

@@ -156,11 +156,11 @@ ll:5

},
{
{
code:'PROJCS["Beduaram / TM 13 NE",GEOGCS["Beduaram",DATUM["D_Beduaram",SPHEROID["Clarke_1880_IGN",6378249.2,293.4660212936269]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",13],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]',
ll:[5, 25],
xy:[-308919.1462828873, 2788738.252386554],
xy:[-308919.1234711099, 2788738.255936392],
acc:{
ll:5
}
}
,{
},
{
code:'PROJCS["S-JTSK (Ferro) / Krovak",GEOGCS["S-JTSK (Ferro)",DATUM["S_JTSK_Ferro",SPHEROID["Bessel 1841",6377397.155,299.1528128,AUTHORITY["EPSG","7004"]],AUTHORITY["EPSG","6818"]],PRIMEM["Ferro",-17.66666666666667,AUTHORITY["EPSG","8909"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4818"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Krovak"],PARAMETER["latitude_of_center",49.5],PARAMETER["longitude_of_center",42.5],PARAMETER["azimuth",30.28813972222222],PARAMETER["pseudo_standard_parallel_1",78.5],PARAMETER["scale_factor",0.9999],PARAMETER["false_easting",0],PARAMETER["false_northing",0],AUTHORITY["EPSG","2065"],AXIS["Y",WEST],AXIS["X",SOUTH]]',

@@ -313,2 +313,76 @@ ll:[17.323583231075897, 49.39440725405376],

xy: [20037508.342789, 0]
},
// these test cases are taken from mapshaper-proj and the test results match
{
code: '+proj=tmerc +ellps=GRS80 +lat_1=0.5 +lat_2=2 +n=0.5',
ll: [2, 1],
xy: [222650.79679577847, 110642.2294119271]
},
{
code: '+proj=tmerc +a=6400000 +lat_1=0.5 +lat_2=2 +n=0.5 +datum=none',
ll: [2, 1],
xy: [223413.46640632232, 111769.14504059685]
},
{
code: '+proj=utm +zone=30 +ellps=GRS80 +lat_1=0.5 +lat_2=2 +n=0.5',
ll: [2, 1],
xy: [1057002.4052152266, 110955.14117382761]
},
// these test cases are related to the original issue on GitHub
{
code: '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs',
ll: [2, 1],
xy: [-959006.3439168662, 113457.31706492987],
acc: {
ll: 5
}
},
{
code: '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs',
ll: [31, 70],
xy: [1104629.4280255223, 7845845.076400871],
acc: {
ll: 4
}
},
// these test cases are for Norway snow flake zones
{
code: '+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs',
ll: [59.121778, 1.508527],
xy: [8055639.601582392, 297536.7150416747],
acc: {
ll: 0
}
},
{
code: '+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs',
ll: [59.121778, 1.508527],
xy: [6958363.797581035, 260155.3254079497],
acc: {
ll: 0
}
},
{
code: '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs',
ll: [59.121778, 1.508527],
xy: [5980907.454031456, 232674.60895515585],
acc: {
ll: 1
}
},
{
code: '+proj=utm +zone=34 +datum=WGS84 +units=m +no_defs',
ll: [79.070672, 20.520579],
xy: [7442887.111291251, 3910285.3071145327],
acc: {
ll: -1.5
}
},
{
code: '+proj=utm +zone=35 +datum=WGS84 +units=m +no_defs',
ll: [79.070672, 20.520579],
xy: [6555309.538050345, 3474309.0216152733],
acc: {
ll: -0.5
}
}

@@ -315,0 +389,0 @@ ];

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc