[proj4js] 01/05: Imported Upstream version 2.4.0+ds
Bas Couwenberg
sebastic at debian.org
Wed Mar 1 06:49:34 UTC 2017
This is an automated email from the git hooks/post-receive script.
sebastic pushed a commit to branch master
in repository proj4js.
commit a8d12a7650ad4dd1fba3a9d6798c414414d0ffcb
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date: Wed Mar 1 07:33:37 2017 +0100
Imported Upstream version 2.4.0+ds
---
.gitignore | 1 -
.jshintrc | 1 +
.travis.yml | 2 +-
Gruntfile.js | 52 +-
bower.json | 2 +-
component.json | 2 +-
dist/proj4-src.js | 11376 ++++++++++++++++++++-------------------
lib/Point.js | 8 +-
lib/Proj.js | 32 +-
lib/adjust_axis.js | 4 +-
lib/common/acosh.js | 4 +-
lib/common/adjust_lat.js | 8 +-
lib/common/adjust_lon.js | 14 +-
lib/common/adjust_zone.js | 6 +-
lib/common/asinh.js | 4 +-
lib/common/asinhy.js | 9 +
lib/common/asinz.js | 4 +-
lib/common/atanh.js | 4 +-
lib/common/clens.js | 15 +
lib/common/clens_cmplx.js | 32 +
lib/common/cosh.js | 4 +-
lib/common/e0fn.js | 4 +-
lib/common/e1fn.js | 4 +-
lib/common/e2fn.js | 4 +-
lib/common/e3fn.js | 4 +-
lib/common/fL.js | 6 +-
lib/common/gN.js | 4 +-
lib/common/gatg.js | 15 +
lib/common/hypot.js | 8 +
lib/common/imlfn.js | 4 +-
lib/common/inverseNadCvt.js | 9 +-
lib/common/invlatiso.js | 6 +-
lib/common/iqsfnz.js | 6 +-
lib/common/latiso.js | 6 +-
lib/common/log1py.js | 6 +
lib/common/mlfn.js | 4 +-
lib/common/msfnz.js | 4 +-
lib/common/nadInterBreakout.js | 4 +-
lib/common/nad_cvt.js | 10 +-
lib/common/nad_intr.js | 6 +-
lib/common/phi2z.js | 7 +-
lib/common/pj_enfn.js | 4 +-
lib/common/pj_inv_mlfn.js | 10 +-
lib/common/pj_mlfn.js | 4 +-
lib/common/qsfnz.js | 4 +-
lib/common/sign.js | 4 +-
lib/common/sinh.js | 4 +-
lib/common/srat.js | 4 +-
lib/common/tanh.js | 4 +-
lib/common/toPoint.js | 4 +-
lib/common/tsfnz.js | 6 +-
lib/constants/Datum.js | 19 +-
lib/constants/Ellipsoid.js | 46 +-
lib/constants/PrimeMeridian.js | 5 +-
lib/constants/grids.js | 23 -
lib/constants/units.js | 6 +-
lib/constants/values.js | 22 +
lib/core.js | 6 +-
lib/datum.js | 15 +-
lib/datumUtils.js | 33 +-
lib/datum_transform.js | 22 +-
lib/defs.js | 8 +-
lib/deriveConstants.js | 24 +-
lib/extend.js | 4 +-
lib/global.js | 4 +-
lib/includedProjections.js | 74 +-
lib/index.js | 29 +-
lib/match.js | 17 +
lib/parseCode.js | 11 +-
lib/projString.js | 19 +-
lib/projections.js | 21 +-
lib/projections/aea.js | 36 +-
lib/projections/aeqd.js | 44 +-
lib/projections/cass.js | 43 +-
lib/projections/cea.js | 31 +-
lib/projections/eqc.js | 25 +-
lib/projections/eqdc.js | 41 +-
lib/projections/equi.js | 26 +-
lib/projections/etmerc.js | 166 +
lib/projections/gauss.js | 25 +-
lib/projections/gnom.js | 33 +-
lib/projections/gstmerc.js | 29 +-
lib/projections/krovak.js | 22 +-
lib/projections/laea.js | 82 +-
lib/projections/lcc.js | 34 +-
lib/projections/longlat.js | 16 +-
lib/projections/merc.js | 35 +-
lib/projections/mill.js | 23 +-
lib/projections/moll.js | 22 +-
lib/projections/nzmg.js | 25 +-
lib/projections/omerc.js | 31 +-
lib/projections/ortho.js | 29 +-
lib/projections/poly.js | 41 +-
lib/projections/sinu.js | 37 +-
lib/projections/somerc.js | 22 +-
lib/projections/stere.js | 40 +-
lib/projections/sterea.js | 25 +-
lib/projections/tmerc.js | 36 +-
lib/projections/utm.js | 23 +-
lib/projections/vandg.js | 29 +-
lib/transform.js | 20 +-
lib/version-browser.js | 1 -
lib/version.js | 2 +-
lib/wkt.js | 223 -
package.json | 23 +-
publish.sh | 2 -
test/amd.html | 4 +-
test/test.js | 10 +-
test/testData.js | 76 +-
109 files changed, 7193 insertions(+), 6400 deletions(-)
diff --git a/.gitignore b/.gitignore
index 0f3e170..e7af7c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,3 @@ coverage
projs.js
.DS_STORE
dist
-lib/version-browser.js
diff --git a/.jshintrc b/.jshintrc
index c076384..86a6e6f 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -1,4 +1,5 @@
{
+ "esversion": 6,
"curly": true,
"eqeqeq": true,
"latedef": "nofunc",
diff --git a/.travis.yml b/.travis.yml
index f714fc0..e97c27a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,4 @@
language: node_js
node_js:
- - "0.10"
\ No newline at end of file
+ - "4"
diff --git a/Gruntfile.js b/Gruntfile.js
index c35d3c4..b80228c 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,5 +1,9 @@
+var json = require('rollup-plugin-json');
+var nodeResolve = require('rollup-plugin-node-resolve');
+
var projs = [
'tmerc',
+ 'etmerc',
'utm',
'sterea',
'stere',
@@ -51,21 +55,19 @@ module.exports = function(grunt) {
},
all: ['./lib/*.js', './lib/*/*.js']
},
- browserify: {
- all: {
- files: {
- 'dist/proj4-src.js': ['lib/index.js'],
- },
- options: {
- browserifyOptions: {
- standalone: 'proj4'
- },
- alias: [
- './projs:./includedProjections',
- './lib/version-browser:./lib/version'
- ]
- }
- }
+ rollup: {
+ options: {
+ format: "umd",
+ moduleName: "proj4",
+ plugins: [
+ json(),
+ nodeResolve()
+ ]
+ },
+ files: {
+ dest: './dist/proj4-src.js',
+ src: './lib/index.js',
+ },
},
uglify: {
options: {
@@ -80,29 +82,29 @@ module.exports = function(grunt) {
}
}
});
- grunt.loadNpmTasks('grunt-browserify');
+ grunt.loadNpmTasks('grunt-rollup');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-mocha-phantomjs');
grunt.registerTask('custom',function(){
- grunt.task.run('browserify', 'uglify');
+ grunt.task.run('rollup', 'uglify');
var projections = this.args;
if(projections[0]==='default'){
- grunt.file.write('./projs.js','module.exports = function(){}');
+ grunt.file.write('./projs.js','export default function(){}');
return;
}
if(projections[0]==='all'){
projections = projs;
}
grunt.file.write('./projs.js',[
- "var projs = [",
- " require('./lib/projections/"+projections.join("'),\n\trequire('./lib/projections/")+"')",
- "];",
- "module.exports = function(proj4){",
- " projs.forEach(function(proj){",
- " proj4.Proj.projections.add(proj);",
- " });",
+ projections.map(function(proj) {
+ return "import " + proj + " from './lib/projections/" + proj + "';";
+ }).join("\n"),
+ "export default function(proj4){",
+ projections.map(function(proj) {
+ return " proj4.Proj.projections.add(" + proj + ");"
+ }).join("\n"),
"}"
].join("\n"));
});
diff --git a/bower.json b/bower.json
index c9c8eb6..49cce2f 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "proj4",
- "version": "2.3.17-alpha",
+ "version": "2.3.18-alpha",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",
"homepage": "https://github.com/proj4js/proj4js",
"main": "dist/proj4.js",
diff --git a/component.json b/component.json
index 9bcf9d8..c8809f1 100644
--- a/component.json
+++ b/component.json
@@ -1,6 +1,6 @@
{
"name": "proj4",
- "version": "2.3.17-alpha",
+ "version": "2.3.18-alpha",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",
"repo": "proj4js/proj4js",
"keywords": [
diff --git a/dist/proj4-src.js b/dist/proj4-src.js
index 1c24eee..24726fb 100644
--- a/dist/proj4-src.js
+++ b/dist/proj4-src.js
@@ -1,5456 +1,5920 @@
-(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.proj4 = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)r [...]
-var projs = [
- require('./lib/projections/tmerc'),
- require('./lib/projections/utm'),
- require('./lib/projections/sterea'),
- require('./lib/projections/stere'),
- require('./lib/projections/somerc'),
- require('./lib/projections/omerc'),
- require('./lib/projections/lcc'),
- require('./lib/projections/krovak'),
- require('./lib/projections/cass'),
- require('./lib/projections/laea'),
- require('./lib/projections/aea'),
- require('./lib/projections/gnom'),
- require('./lib/projections/cea'),
- require('./lib/projections/eqc'),
- require('./lib/projections/poly'),
- require('./lib/projections/nzmg'),
- require('./lib/projections/mill'),
- require('./lib/projections/sinu'),
- require('./lib/projections/moll'),
- require('./lib/projections/eqdc'),
- require('./lib/projections/vandg'),
- require('./lib/projections/aeqd'),
- require('./lib/projections/ortho')
-];
-module.exports = function(proj4){
- projs.forEach(function(proj){
- proj4.Proj.projections.add(proj);
- });
-}
-},{"./lib/projections/aea":42,"./lib/projections/aeqd":43,"./lib/projections/cass":44,"./lib/projections/cea":45,"./lib/projections/eqc":46,"./lib/projections/eqdc":47,"./lib/projections/gnom":49,"./lib/projections/krovak":50,"./lib/projections/laea":51,"./lib/projections/lcc":52,"./lib/projections/mill":55,"./lib/projections/moll":56,"./lib/projections/nzmg":57,"./lib/projections/omerc":58,"./lib/projections/ortho":59,"./lib/projections/poly":60,"./lib/projections/sinu":61,"./lib/projec [...]
-module.exports = '2.3.17';
-
-},{}],1:[function(require,module,exports){
-var mgrs = require('mgrs');
-
-function Point(x, y, z) {
- if (!(this instanceof Point)) {
- return new Point(x, y, z);
- }
- if (Array.isArray(x)) {
- this.x = x[0];
- this.y = x[1];
- this.z = x[2] || 0.0;
- } else if(typeof x === 'object') {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z || 0.0;
- } else if (typeof x === 'string' && typeof y === 'undefined') {
- var coords = x.split(',');
- this.x = parseFloat(coords[0], 10);
- this.y = parseFloat(coords[1], 10);
- this.z = parseFloat(coords[2], 10) || 0.0;
- } else {
- this.x = x;
- this.y = y;
- this.z = z || 0.0;
- }
- console.warn('proj4.Point will be removed in version 3, use proj4.toPoint');
-}
-
-Point.fromMGRS = function(mgrsStr) {
- return new Point(mgrs.toPoint(mgrsStr));
-};
-Point.prototype.toMGRS = function(accuracy) {
- return mgrs.forward([this.x, this.y], accuracy);
-};
-module.exports = Point;
-
-},{"mgrs":70}],2:[function(require,module,exports){
-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) {
- if (!(this instanceof Projection)) {
- return new Projection(srsCode);
- }
- callback = callback || function(error){
- if(error){
- throw error;
- }
- };
- var json = parseCode(srsCode);
- if(typeof json !== 'object'){
- callback(srsCode);
- return;
- }
- 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);
-
-}
-Projection.projections = projections;
-Projection.projections.start();
-module.exports = Projection;
-
-},{"./constants/Datum":26,"./datum":31,"./deriveConstants":35,"./extend":36,"./parseCode":39,"./projections":41}],3:[function(require,module,exports){
-module.exports = function(crs, denorm, point) {
- var xin = point.x,
- yin = point.y,
- zin = point.z || 0.0;
- var v, t, i;
- var out = {};
- for (i = 0; i < 3; i++) {
- if (denorm && i === 2 && point.z === undefined) {
- continue;
- }
- if (i === 0) {
- v = xin;
- t = 'x';
- }
- else if (i === 1) {
- v = yin;
- t = 'y';
- }
- else {
- v = zin;
- t = 'z';
- }
- switch (crs.axis[i]) {
- case 'e':
- out[t] = v;
- break;
- case 'w':
- out[t] = -v;
- break;
- case 'n':
- out[t] = v;
- break;
- case 's':
- out[t] = -v;
- break;
- case 'u':
- if (point[t] !== undefined) {
- out.z = v;
- }
- break;
- case 'd':
- if (point[t] !== undefined) {
- out.z = -v;
- }
- break;
- default:
- //console.log("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
- return null;
- }
- }
- return out;
-};
-
-},{}],4:[function(require,module,exports){
-var HALF_PI = Math.PI/2;
-var sign = require('./sign');
-
-module.exports = function(x) {
- return (Math.abs(x) < HALF_PI) ? x : (x - (sign(x) * Math.PI));
-};
-},{"./sign":22}],5:[function(require,module,exports){
-var TWO_PI = Math.PI * 2;
-// SPI is slightly greater than Math.PI, so values that exceed the -180..180
-// degree range by a tiny amount don't get wrapped. This prevents points that
-// have drifted from their original location along the 180th meridian (due to
-// floating point error) from changing their sign.
-var SPI = 3.14159265359;
-var sign = require('./sign');
-
-module.exports = function(x) {
- return (Math.abs(x) <= SPI) ? x : (x - (sign(x) * TWO_PI));
-};
-},{"./sign":22}],6:[function(require,module,exports){
-var adjust_lon = require('./adjust_lon');
-
-module.exports = function(zone, lon) {
- if (zone === undefined) {
- zone = Math.floor((adjust_lon(lon) + Math.PI) * 30 / Math.PI);
-
- if (zone < 0) {
- return 0;
- } else if (zone >= 60) {
- return 59;
- }
- return zone;
- } else {
- if (zone > 0 && zone <= 60) {
- return zone - 1;
- }
- }
-};
-
-},{"./adjust_lon":5}],7:[function(require,module,exports){
-module.exports = function(x) {
- if (Math.abs(x) > 1) {
- x = (x > 1) ? 1 : -1;
- }
- return Math.asin(x);
-};
-},{}],8:[function(require,module,exports){
-module.exports = function(x) {
- return (1 - 0.25 * x * (1 + x / 16 * (3 + 1.25 * x)));
-};
-},{}],9:[function(require,module,exports){
-module.exports = function(x) {
- return (0.375 * x * (1 + 0.25 * x * (1 + 0.46875 * x)));
-};
-},{}],10:[function(require,module,exports){
-module.exports = function(x) {
- return (0.05859375 * x * x * (1 + 0.75 * x));
-};
-},{}],11:[function(require,module,exports){
-module.exports = function(x) {
- return (x * x * x * (35 / 3072));
-};
-},{}],12:[function(require,module,exports){
-module.exports = function(a, e, sinphi) {
- var temp = e * sinphi;
- return a / Math.sqrt(1 - temp * temp);
-};
-},{}],13:[function(require,module,exports){
-module.exports = 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 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi))) / (e0 - 2 * e1 * Math.cos(2 * phi) + 4 * e2 * Math.cos(4 * phi) - 6 * e3 * Math.cos(6 * phi));
- phi += dphi;
- if (Math.abs(dphi) <= 0.0000000001) {
- return phi;
- }
- }
-
- //..reportError("IMLFN-CONV:Latitude failed to converge after 15 iterations");
- return NaN;
-};
-},{}],14:[function(require,module,exports){
-var HALF_PI = Math.PI/2;
-
-module.exports = function(eccent, q) {
- var temp = 1 - (1 - eccent * eccent) / (2 * eccent) * Math.log((1 - eccent) / (1 + eccent));
- if (Math.abs(Math.abs(q) - temp) < 1.0E-6) {
- if (q < 0) {
- return (-1 * HALF_PI);
- }
- else {
- return 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 - con * con, 2) / (2 * cos_phi) * (q / (1 - eccent * eccent) - sin_phi / (1 - con * con) + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
- phi += dphi;
- if (Math.abs(dphi) <= 0.0000000001) {
- return phi;
- }
- }
-
- //console.log("IQSFN-CONV:Latitude failed to converge after 30 iterations");
- return NaN;
-};
-},{}],15:[function(require,module,exports){
-module.exports = function(e0, e1, e2, e3, phi) {
- return (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi));
-};
-},{}],16:[function(require,module,exports){
-module.exports = function(eccent, sinphi, cosphi) {
- var con = eccent * sinphi;
- return cosphi / (Math.sqrt(1 - con * con));
-};
-},{}],17:[function(require,module,exports){
-var HALF_PI = Math.PI/2;
-module.exports = function(eccent, ts) {
- var eccnth = 0.5 * eccent;
- var con, dphi;
- var phi = HALF_PI - 2 * Math.atan(ts);
- for (var i = 0; i <= 15; i++) {
- con = eccent * Math.sin(phi);
- dphi = HALF_PI - 2 * Math.atan(ts * (Math.pow(((1 - con) / (1 + con)), eccnth))) - phi;
- phi += dphi;
- if (Math.abs(dphi) <= 0.0000000001) {
- return phi;
- }
- }
- //console.log("phi2z has NoConvergence");
- return -9999;
-};
-},{}],18:[function(require,module,exports){
-var C00 = 1;
-var C02 = 0.25;
-var C04 = 0.046875;
-var C06 = 0.01953125;
-var C08 = 0.01068115234375;
-var C22 = 0.75;
-var C44 = 0.46875;
-var C46 = 0.01302083333333333333;
-var C48 = 0.00712076822916666666;
-var C66 = 0.36458333333333333333;
-var C68 = 0.00569661458333333333;
-var C88 = 0.3076171875;
-
-module.exports = function(es) {
- var en = [];
- en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
- en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
- var t = es * es;
- en[2] = t * (C44 - es * (C46 + es * C48));
- t *= es;
- en[3] = t * (C66 - es * C68);
- en[4] = t * es * C88;
- return en;
-};
-},{}],19:[function(require,module,exports){
-var pj_mlfn = require("./pj_mlfn");
-var EPSLN = 1.0e-10;
-var MAX_ITER = 20;
-module.exports = function(arg, es, en) {
- var k = 1 / (1 - es);
- var phi = arg;
- for (var i = MAX_ITER; i; --i) { /* rarely goes over 2 iterations */
- var s = Math.sin(phi);
- var t = 1 - es * s * s;
- //t = this.pj_mlfn(phi, s, Math.cos(phi), en) - arg;
- //phi -= t * (t * Math.sqrt(t)) * k;
- t = (pj_mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
- phi -= t;
- if (Math.abs(t) < EPSLN) {
- return phi;
- }
- }
- //..reportError("cass:pj_inv_mlfn: Convergence error");
- return phi;
-};
-},{"./pj_mlfn":20}],20:[function(require,module,exports){
-module.exports = function(phi, sphi, cphi, en) {
- cphi *= sphi;
- sphi *= sphi;
- return (en[0] * phi - cphi * (en[1] + sphi * (en[2] + sphi * (en[3] + sphi * en[4]))));
-};
-},{}],21:[function(require,module,exports){
-module.exports = function(eccent, sinphi) {
- var con;
- if (eccent > 1.0e-7) {
- con = eccent * sinphi;
- return ((1 - eccent * eccent) * (sinphi / (1 - con * con) - (0.5 / eccent) * Math.log((1 - con) / (1 + con))));
- }
- else {
- return (2 * sinphi);
- }
-};
-},{}],22:[function(require,module,exports){
-module.exports = function(x) {
- return x<0 ? -1 : 1;
-};
-},{}],23:[function(require,module,exports){
-module.exports = function(esinp, exp) {
- return (Math.pow((1 - esinp) / (1 + esinp), exp));
-};
-},{}],24:[function(require,module,exports){
-module.exports = function (array){
- var out = {
- x: array[0],
- y: array[1]
- };
- if (array.length>2) {
- out.z = array[2];
- }
- if (array.length>3) {
- out.m = array[3];
- }
- return out;
-};
-},{}],25:[function(require,module,exports){
-var HALF_PI = Math.PI/2;
-
-module.exports = function(eccent, phi, sinphi) {
- var con = eccent * sinphi;
- var com = 0.5 * eccent;
- con = Math.pow(((1 - con) / (1 + con)), com);
- return (Math.tan(0.5 * (HALF_PI - phi)) / con);
-};
-},{}],26:[function(require,module,exports){
-exports.wgs84 = {
- towgs84: "0,0,0",
- ellipse: "WGS84",
- datumName: "WGS84"
-};
-exports.ch1903 = {
- towgs84: "674.374,15.056,405.346",
- ellipse: "bessel",
- datumName: "swiss"
-};
-exports.ggrs87 = {
- towgs84: "-199.87,74.79,246.62",
- ellipse: "GRS80",
- datumName: "Greek_Geodetic_Reference_System_1987"
-};
-exports.nad83 = {
- towgs84: "0,0,0",
- ellipse: "GRS80",
- datumName: "North_American_Datum_1983"
-};
-exports.nad27 = {
- nadgrids: "@conus, at alaska, at ntv2_0.gsb, at ntv1_can.dat",
- ellipse: "clrk66",
- datumName: "North_American_Datum_1927"
-};
-exports.potsdam = {
- towgs84: "606.0,23.0,413.0",
- ellipse: "bessel",
- datumName: "Potsdam Rauenberg 1950 DHDN"
-};
-exports.carthage = {
- towgs84: "-263.0,6.0,431.0",
- ellipse: "clark80",
- datumName: "Carthage 1934 Tunisia"
-};
-exports.hermannskogel = {
- towgs84: "653.0,-212.0,449.0",
- ellipse: "bessel",
- datumName: "Hermannskogel"
-};
-exports.ire65 = {
- towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",
- ellipse: "mod_airy",
- datumName: "Ireland 1965"
-};
-exports.rassadiran = {
- towgs84: "-133.63,-157.5,-158.62",
- ellipse: "intl",
- datumName: "Rassadiran"
-};
-exports.nzgd49 = {
- towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",
- ellipse: "intl",
- datumName: "New Zealand Geodetic Datum 1949"
-};
-exports.osgb36 = {
- towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",
- ellipse: "airy",
- datumName: "Airy 1830"
-};
-exports.s_jtsk = {
- towgs84: "589,76,480",
- ellipse: 'bessel',
- datumName: 'S-JTSK (Ferro)'
-};
-exports.beduaram = {
- towgs84: '-106,-87,188',
- ellipse: 'clrk80',
- datumName: 'Beduaram'
-};
-exports.gunung_segara = {
- towgs84: '-403,684,41',
- ellipse: 'bessel',
- datumName: 'Gunung Segara Jakarta'
-};
-exports.rnb72 = {
- towgs84: "106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",
- ellipse: "intl",
- datumName: "Reseau National Belge 1972"
-};
-},{}],27:[function(require,module,exports){
-exports.MERIT = {
- a: 6378137.0,
- rf: 298.257,
- ellipseName: "MERIT 1983"
-};
-exports.SGS85 = {
- a: 6378136.0,
- rf: 298.257,
- ellipseName: "Soviet Geodetic System 85"
-};
-exports.GRS80 = {
- a: 6378137.0,
- rf: 298.257222101,
- ellipseName: "GRS 1980(IUGG, 1980)"
-};
-exports.IAU76 = {
- a: 6378140.0,
- rf: 298.257,
- ellipseName: "IAU 1976"
-};
-exports.airy = {
- a: 6377563.396,
- b: 6356256.910,
- ellipseName: "Airy 1830"
-};
-exports.APL4 = {
- a: 6378137,
- rf: 298.25,
- ellipseName: "Appl. Physics. 1965"
-};
-exports.NWL9D = {
- a: 6378145.0,
- rf: 298.25,
- ellipseName: "Naval Weapons Lab., 1965"
-};
-exports.mod_airy = {
- a: 6377340.189,
- b: 6356034.446,
- ellipseName: "Modified Airy"
-};
-exports.andrae = {
- a: 6377104.43,
- rf: 300.0,
- ellipseName: "Andrae 1876 (Den., Iclnd.)"
-};
-exports.aust_SA = {
- a: 6378160.0,
- rf: 298.25,
- ellipseName: "Australian Natl & S. Amer. 1969"
-};
-exports.GRS67 = {
- a: 6378160.0,
- rf: 298.2471674270,
- ellipseName: "GRS 67(IUGG 1967)"
-};
-exports.bessel = {
- a: 6377397.155,
- rf: 299.1528128,
- ellipseName: "Bessel 1841"
-};
-exports.bess_nam = {
- a: 6377483.865,
- rf: 299.1528128,
- ellipseName: "Bessel 1841 (Namibia)"
-};
-exports.clrk66 = {
- a: 6378206.4,
- b: 6356583.8,
- ellipseName: "Clarke 1866"
-};
-exports.clrk80 = {
- a: 6378249.145,
- rf: 293.4663,
- ellipseName: "Clarke 1880 mod."
-};
-exports.clrk58 = {
- a: 6378293.645208759,
- rf: 294.2606763692654,
- ellipseName: "Clarke 1858"
-};
-exports.CPM = {
- a: 6375738.7,
- rf: 334.29,
- ellipseName: "Comm. des Poids et Mesures 1799"
-};
-exports.delmbr = {
- a: 6376428.0,
- rf: 311.5,
- ellipseName: "Delambre 1810 (Belgium)"
-};
-exports.engelis = {
- a: 6378136.05,
- rf: 298.2566,
- ellipseName: "Engelis 1985"
-};
-exports.evrst30 = {
- a: 6377276.345,
- rf: 300.8017,
- ellipseName: "Everest 1830"
-};
-exports.evrst48 = {
- a: 6377304.063,
- rf: 300.8017,
- ellipseName: "Everest 1948"
-};
-exports.evrst56 = {
- a: 6377301.243,
- rf: 300.8017,
- ellipseName: "Everest 1956"
-};
-exports.evrst69 = {
- a: 6377295.664,
- rf: 300.8017,
- ellipseName: "Everest 1969"
-};
-exports.evrstSS = {
- a: 6377298.556,
- rf: 300.8017,
- ellipseName: "Everest (Sabah & Sarawak)"
-};
-exports.fschr60 = {
- a: 6378166.0,
- rf: 298.3,
- ellipseName: "Fischer (Mercury Datum) 1960"
-};
-exports.fschr60m = {
- a: 6378155.0,
- rf: 298.3,
- ellipseName: "Fischer 1960"
-};
-exports.fschr68 = {
- a: 6378150.0,
- rf: 298.3,
- ellipseName: "Fischer 1968"
-};
-exports.helmert = {
- a: 6378200.0,
- rf: 298.3,
- ellipseName: "Helmert 1906"
-};
-exports.hough = {
- a: 6378270.0,
- rf: 297.0,
- ellipseName: "Hough"
-};
-exports.intl = {
- a: 6378388.0,
- rf: 297.0,
- ellipseName: "International 1909 (Hayford)"
-};
-exports.kaula = {
- a: 6378163.0,
- rf: 298.24,
- ellipseName: "Kaula 1961"
-};
-exports.lerch = {
- a: 6378139.0,
- rf: 298.257,
- ellipseName: "Lerch 1979"
-};
-exports.mprts = {
- a: 6397300.0,
- rf: 191.0,
- ellipseName: "Maupertius 1738"
-};
-exports.new_intl = {
- a: 6378157.5,
- b: 6356772.2,
- ellipseName: "New International 1967"
-};
-exports.plessis = {
- a: 6376523.0,
- rf: 6355863.0,
- ellipseName: "Plessis 1817 (France)"
-};
-exports.krass = {
- a: 6378245.0,
- rf: 298.3,
- ellipseName: "Krassovsky, 1942"
-};
-exports.SEasia = {
- a: 6378155.0,
- b: 6356773.3205,
- ellipseName: "Southeast Asia"
-};
-exports.walbeck = {
- a: 6376896.0,
- b: 6355834.8467,
- ellipseName: "Walbeck"
-};
-exports.WGS60 = {
- a: 6378165.0,
- rf: 298.3,
- ellipseName: "WGS 60"
-};
-exports.WGS66 = {
- a: 6378145.0,
- rf: 298.25,
- ellipseName: "WGS 66"
-};
-exports.WGS7 = {
- a: 6378135.0,
- rf: 298.26,
- ellipseName: "WGS 72"
-};
-exports.WGS84 = {
- a: 6378137.0,
- rf: 298.257223563,
- ellipseName: "WGS 84"
-};
-exports.sphere = {
- a: 6370997.0,
- b: 6370997.0,
- ellipseName: "Normal Sphere (r=6370997)"
-};
-},{}],28:[function(require,module,exports){
-exports.greenwich = 0.0; //"0dE",
-exports.lisbon = -9.131906111111; //"9d07'54.862\"W",
-exports.paris = 2.337229166667; //"2d20'14.025\"E",
-exports.bogota = -74.080916666667; //"74d04'51.3\"W",
-exports.madrid = -3.687938888889; //"3d41'16.58\"W",
-exports.rome = 12.452333333333; //"12d27'8.4\"E",
-exports.bern = 7.439583333333; //"7d26'22.5\"E",
-exports.jakarta = 106.807719444444; //"106d48'27.79\"E",
-exports.ferro = -17.666666666667; //"17d40'W",
-exports.brussels = 4.367975; //"4d22'4.71\"E",
-exports.stockholm = 18.058277777778; //"18d3'29.8\"E",
-exports.athens = 23.7163375; //"23d42'58.815\"E",
-exports.oslo = 10.722916666667; //"10d43'22.5\"E"
-},{}],29:[function(require,module,exports){
-exports.ft = {to_meter: 0.3048};
-exports['us-ft'] = {to_meter: 1200 / 3937};
-
-},{}],30:[function(require,module,exports){
-var proj = require('./Proj');
-var transform = require('./transform');
-var wgs84 = proj('WGS84');
-
-function transformer(from, to, coords) {
- var transformedArray;
- if (Array.isArray(coords)) {
- transformedArray = transform(from, to, coords);
- if (coords.length === 3) {
- return [transformedArray.x, transformedArray.y, transformedArray.z];
- }
- else {
- return [transformedArray.x, transformedArray.y];
- }
- }
- else {
- return transform(from, to, coords);
- }
-}
-
-function checkProj(item) {
- if (item instanceof proj) {
- return item;
- }
- if (item.oProj) {
- return item.oProj;
- }
- return proj(item);
-}
-function proj4(fromProj, toProj, coord) {
- fromProj = checkProj(fromProj);
- var single = false;
- var obj;
- if (typeof toProj === 'undefined') {
- toProj = fromProj;
- fromProj = wgs84;
- single = true;
- }
- else if (typeof toProj.x !== 'undefined' || Array.isArray(toProj)) {
- coord = toProj;
- toProj = fromProj;
- fromProj = wgs84;
- single = true;
- }
- toProj = checkProj(toProj);
- if (coord) {
- return transformer(fromProj, toProj, coord);
- }
- else {
- obj = {
- forward: function(coords) {
- return transformer(fromProj, toProj, coords);
- },
- inverse: function(coords) {
- return transformer(toProj, fromProj, coords);
- }
- };
- if (single) {
- obj.oProj = toProj;
- }
- return obj;
- }
-}
-module.exports = proj4;
-},{"./Proj":2,"./transform":68}],31:[function(require,module,exports){
-var PJD_3PARAM = 1;
-var PJD_7PARAM = 2;
-var PJD_WGS84 = 4; // WGS84 or equivalent
-var PJD_NODATUM = 5; // WGS84 or equivalent
-var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
-
-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;
- }
-
- 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 (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;
- }
- }
- }
-
-
- out.a = a; //datum object also uses these values
- out.b = b;
- out.es = es;
- out.ep2 = ep2;
- return out;
-}
-
-module.exports = datum;
-
-},{}],32:[function(require,module,exports){
-'use strict';
-var PJD_3PARAM = 1;
-var PJD_7PARAM = 2;
-var HALF_PI = Math.PI/2;
-
-exports.compareDatums = function(source, dest) {
- if (source.datum_type !== dest.datum_type) {
- return false; // false, datums are not equal
- } else if (source.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 (source.datum_type === PJD_3PARAM) {
- return (this.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2]);
- } else if (source.datum_type === PJD_7PARAM) {
- return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2] && source.datum_params[3] === dest.datum_params[3] && source.datum_params[4] === dest.datum_params[4] && source.datum_params[5] === dest.datum_params[5] && source.datum_params[6] === dest.datum_params[6]);
- } 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)
- *
- */
-exports.geodeticToGeocentric = function(p, es, a) {
- var Longitude = p.x;
- var Latitude = p.y;
- var Height = p.z ? p.z : 0; //Z value not always supplied
-
- 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 = a / (Math.sqrt(1.0e0 - es * Sin2_Lat));
- return {
- x: (Rn + Height) * Cos_Lat * Math.cos(Longitude),
- y: (Rn + Height) * Cos_Lat * Math.sin(Longitude),
- z: ((Rn * (1 - es)) + Height) * Sin_Lat
- };
-}; // cs_geodetic_to_geocentric()
-
-
-exports.geocentricToGeodetic = function(p, es, a, b) {
- /* 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 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;
-
- P = Math.sqrt(X * X + Y * Y);
- RR = Math.sqrt(X * X + Y * Y + Z * Z);
-
- /* special cases for latitude and longitude */
- if (P / a < genau) {
-
- /* special case, if P=0. (X=0., Y=0.) */
- 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 / a < genau) {
- Latitude = HALF_PI;
- Height = -b;
- return {
- x: p.x,
- y: p.y,
- z: p.z
- };
- }
- } 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 - es * (2.0 - es) * ST * ST);
- CPHI0 = ST * (1.0 - 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 = a / Math.sqrt(1.0 - es * SPHI0 * SPHI0);
-
- /* ellipsoidal (geodetic) height */
- Height = P * CPHI0 + Z * SPHI0 - RN * (1.0 - es * SPHI0 * SPHI0);
-
- RK = 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));
- return {
- x: Longitude,
- y: Latitude,
- z: Height
- };
-}; // cs_geocentric_to_geodetic()
-
-
-/****************************************************************/
-// pj_geocentic_to_wgs84( p )
-// p = point to transform in geocentric coordinates (x,y,z)
-
-
-/** 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.
-*/
-exports.geocentricToWgs84 = function(p, datum_type, datum_params) {
-
- if (datum_type === PJD_3PARAM) {
- // if( x[io] === HUGE_VAL )
- // continue;
- return {
- x: p.x + datum_params[0],
- y: p.y + datum_params[1],
- z: p.z + datum_params[2],
- };
- } else if (datum_type === PJD_7PARAM) {
- var Dx_BF = datum_params[0];
- var Dy_BF = datum_params[1];
- var Dz_BF = datum_params[2];
- var Rx_BF = datum_params[3];
- var Ry_BF = datum_params[4];
- var Rz_BF = datum_params[5];
- var M_BF = datum_params[6];
- // if( x[io] === HUGE_VAL )
- // continue;
- return {
- x: M_BF * (p.x - Rz_BF * p.y + Ry_BF * p.z) + Dx_BF,
- y: M_BF * (Rz_BF * p.x + p.y - Rx_BF * p.z) + Dy_BF,
- z: M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF
- };
- }
-}; // cs_geocentric_to_wgs84
-
-/****************************************************************/
-// pj_geocentic_from_wgs84()
-// coordinate system definition,
-// point to transform in geocentric coordinates (x,y,z)
-exports.geocentricFromWgs84 = function(p, datum_type, datum_params) {
-
- if (datum_type === PJD_3PARAM) {
- //if( x[io] === HUGE_VAL )
- // continue;
- return {
- x: p.x - datum_params[0],
- y: p.y - datum_params[1],
- z: p.z - datum_params[2],
- };
-
- } else if (datum_type === PJD_7PARAM) {
- var Dx_BF = datum_params[0];
- var Dy_BF = datum_params[1];
- var Dz_BF = datum_params[2];
- var Rx_BF = datum_params[3];
- var Ry_BF = datum_params[4];
- var Rz_BF = datum_params[5];
- var M_BF = 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;
-
- return {
- x: x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp,
- y: -Rz_BF * x_tmp + y_tmp + Rx_BF * z_tmp,
- z: Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp
- };
- } //cs_geocentric_from_wgs84()
-};
-
-},{}],33:[function(require,module,exports){
-var PJD_3PARAM = 1;
-var PJD_7PARAM = 2;
-var PJD_NODATUM = 5; // WGS84 or equivalent
-var datum = require('./datumUtils');
-function checkParams(type) {
- return (type === PJD_3PARAM || type === PJD_7PARAM);
-}
-module.exports = function(source, dest, point) {
- // Short cut if the datums are identical.
- if (datum.compareDatums(source, dest)) {
- return point; // in this case, zero is sucess,
- // whereas cs_compare_datums returns 1 to indicate TRUE
- // confusing, should fix this
- }
-
- // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
- if (source.datum_type === PJD_NODATUM || dest.datum_type === PJD_NODATUM) {
- return point;
- }
-
- // If this datum requires grid shifts, then apply it to geodetic coordinates.
-
- // 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;
- }
-
- // 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 (checkParams(dest.datum_type)) {
- point = datum.geocentricFromWgs84(point, dest.datum_type, dest.datum_params);
- }
- return datum.geocentricToGeodetic(point, dest.es, dest.a, dest.b);
-
-};
-
-},{"./datumUtils":32}],34:[function(require,module,exports){
-var globals = require('./global');
-var parseProj = require('./projString');
-var wkt = require('./wkt');
-
-function defs(name) {
- /*global console*/
- var that = this;
- if (arguments.length === 2) {
- var def = arguments[1];
- if (typeof def === 'string') {
- if (def.charAt(0) === '+') {
- defs[name] = parseProj(arguments[1]);
- }
- else {
- defs[name] = wkt(arguments[1]);
- }
- } else {
- defs[name] = def;
- }
- }
- else if (arguments.length === 1) {
- if (Array.isArray(name)) {
- return name.map(function(v) {
- if (Array.isArray(v)) {
- defs.apply(that, v);
- }
- else {
- defs(v);
- }
- });
- }
- else if (typeof name === 'string') {
- if (name in defs) {
- return defs[name];
- }
- }
- else if ('EPSG' in name) {
- defs['EPSG:' + name.EPSG] = name;
- }
- else if ('ESRI' in name) {
- defs['ESRI:' + name.ESRI] = name;
- }
- else if ('IAU2000' in name) {
- defs['IAU2000:' + name.IAU2000] = name;
- }
- else {
- console.log(name);
- }
- return;
- }
-
-
-}
-globals(defs);
-module.exports = defs;
-
-},{"./global":37,"./projString":40,"./wkt":69}],35:[function(require,module,exports){
-// ellipoid pj_set_ell.c
-var SIXTH = 0.1666666666666666667;
-/* 1/6 */
-var RA4 = 0.04722222222222222222;
-/* 17/360 */
-var RA6 = 0.02215608465608465608;
-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 (rf && !b) {
- b = (1.0 - 1.0 / rf) * a;
- }
- if (rf === 0 || Math.abs(a - b) < EPSLN) {
- sphere = true;
- b = a;
- }
- return {
- a: a,
- b: b,
- rf: rf,
- sphere: sphere
- };
-};
-
-},{"./constants/Ellipsoid":27}],36:[function(require,module,exports){
-module.exports = function(destination, source) {
- destination = destination || {};
- var value, property;
- if (!source) {
- return destination;
- }
- for (property in source) {
- value = source[property];
- if (value !== undefined) {
- destination[property] = value;
- }
- }
- return destination;
-};
-
-},{}],37:[function(require,module,exports){
-module.exports = function(defs) {
- defs('EPSG:4326', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
- defs('EPSG:4269', "+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees");
- defs('EPSG:3857', "+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs");
-
- defs.WGS84 = defs['EPSG:4326'];
- defs['EPSG:3785'] = defs['EPSG:3857']; // maintain backward compat, official code is 3857
- defs.GOOGLE = defs['EPSG:3857'];
- defs['EPSG:900913'] = defs['EPSG:3857'];
- defs['EPSG:102113'] = defs['EPSG:3857'];
-};
-
-},{}],38:[function(require,module,exports){
-var proj4 = require('./core');
-proj4.defaultDatum = 'WGS84'; //default datum
-proj4.Proj = require('./Proj');
-proj4.WGS84 = new proj4.Proj('WGS84');
-proj4.Point = require('./Point');
-proj4.toPoint = require('./common/toPoint');
-proj4.defs = require('./defs');
-proj4.transform = require('./transform');
-proj4.mgrs = require('mgrs');
-proj4.version = require('./version');
-require('./includedProjections')(proj4);
-module.exports = proj4;
-
-},{"./Point":1,"./Proj":2,"./common/toPoint":24,"./core":30,"./defs":34,"./includedProjections":"./includedProjections","./transform":68,"./version":"./lib/version","mgrs":70}],39:[function(require,module,exports){
-var defs = require('./defs');
-var wkt = require('./wkt');
-var projStr = require('./projString');
-function testObj(code){
- return typeof code === 'string';
-}
-function testDef(code){
- return code in defs;
-}
-var codeWords = ['GEOGCS','GEOCCS','PROJCS','LOCAL_CS'];
-
-function testWKT(code){
- return codeWords.some(function (word) {
- return code.indexOf(word) > -1;
- });
-}
-function testProj(code){
- return code[0] === '+';
-}
-function parse(code){
- if (testObj(code)) {
- //check to see if this is a WKT string
- if (testDef(code)) {
- return defs[code];
- }
- if (testWKT(code)) {
- return wkt(code);
- }
- if (testProj(code)) {
- return projStr(code);
- }
- }else{
- return code;
- }
-}
-
-module.exports = parse;
-
-},{"./defs":34,"./projString":40,"./wkt":69}],40:[function(require,module,exports){
-var D2R = 0.01745329251994329577;
-var PrimeMeridian = require('./constants/PrimeMeridian');
-var units = require('./constants/units');
-
-module.exports = function(defData) {
- var self = {};
- var paramObj = defData.split('+').map(function(v) {
- return v.trim();
- }).filter(function(a) {
- return a;
- }).reduce(function(p, a) {
- var split = a.split('=');
- split.push(true);
- p[split[0].toLowerCase()] = split[1];
- return p;
- }, {});
- var paramName, paramVal, paramOutname;
- var params = {
- proj: 'projName',
- datum: 'datumCode',
- rf: function(v) {
- self.rf = parseFloat(v);
- },
- lat_0: function(v) {
- self.lat0 = v * D2R;
- },
- lat_1: function(v) {
- self.lat1 = v * D2R;
- },
- lat_2: function(v) {
- self.lat2 = v * D2R;
- },
- lat_ts: function(v) {
- self.lat_ts = v * D2R;
- },
- lon_0: function(v) {
- self.long0 = v * D2R;
- },
- lon_1: function(v) {
- self.long1 = v * D2R;
- },
- lon_2: function(v) {
- self.long2 = v * D2R;
- },
- alpha: function(v) {
- self.alpha = parseFloat(v) * D2R;
- },
- lonc: function(v) {
- self.longc = v * D2R;
- },
- x_0: function(v) {
- self.x0 = parseFloat(v);
- },
- y_0: function(v) {
- self.y0 = parseFloat(v);
- },
- k_0: function(v) {
- self.k0 = parseFloat(v);
- },
- k: function(v) {
- self.k0 = parseFloat(v);
- },
- a: function(v) {
- self.a = parseFloat(v);
- },
- b: function(v) {
- self.b = parseFloat(v);
- },
- r_a: function() {
- self.R_A = true;
- },
- zone: function(v) {
- self.zone = parseInt(v, 10);
- },
- south: function() {
- self.utmSouth = true;
- },
- towgs84: function(v) {
- self.datum_params = v.split(",").map(function(a) {
- return parseFloat(a);
- });
- },
- to_meter: function(v) {
- self.to_meter = parseFloat(v);
- },
- units: function(v) {
- self.units = v;
- if (units[v]) {
- self.to_meter = units[v].to_meter;
- }
- },
- from_greenwich: function(v) {
- self.from_greenwich = v * D2R;
- },
- pm: function(v) {
- self.from_greenwich = (PrimeMeridian[v] ? PrimeMeridian[v] : parseFloat(v)) * D2R;
- },
- nadgrids: function(v) {
- if (v === '@null') {
- self.datumCode = 'none';
- }
- else {
- self.nadgrids = v;
- }
- },
- axis: function(v) {
- var legalAxis = "ewnsud";
- if (v.length === 3 && legalAxis.indexOf(v.substr(0, 1)) !== -1 && legalAxis.indexOf(v.substr(1, 1)) !== -1 && legalAxis.indexOf(v.substr(2, 1)) !== -1) {
- self.axis = v;
- }
- }
- };
- for (paramName in paramObj) {
- paramVal = paramObj[paramName];
- if (paramName in params) {
- paramOutname = params[paramName];
- if (typeof paramOutname === 'function') {
- paramOutname(paramVal);
- }
- else {
- self[paramOutname] = paramVal;
- }
- }
- else {
- self[paramName] = paramVal;
- }
- }
- if(typeof self.datumCode === 'string' && self.datumCode !== "WGS84"){
- self.datumCode = self.datumCode.toLowerCase();
- }
- return self;
-};
-
-},{"./constants/PrimeMeridian":28,"./constants/units":29}],41:[function(require,module,exports){
-var projs = [
- require('./projections/merc'),
- require('./projections/longlat')
-];
-var names = {};
-var projStore = [];
-
-function add(proj, i) {
- var len = projStore.length;
- if (!proj.names) {
- console.log(i);
- return true;
- }
- projStore[len] = proj;
- proj.names.forEach(function(n) {
- names[n.toLowerCase()] = len;
- });
- return this;
-}
-
-exports.add = add;
-
-exports.get = function(name) {
- if (!name) {
- return false;
- }
- var n = name.toLowerCase();
- if (typeof names[n] !== 'undefined' && projStore[names[n]]) {
- return projStore[names[n]];
- }
-};
-exports.start = function() {
- projs.forEach(add);
-};
-
-},{"./projections/longlat":53,"./projections/merc":54}],42:[function(require,module,exports){
-var EPSLN = 1.0e-10;
-var msfnz = require('../common/msfnz');
-var qsfnz = require('../common/qsfnz');
-var adjust_lon = require('../common/adjust_lon');
-var asinz = require('../common/asinz');
-exports.init = function() {
-
- if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
- return;
- }
- this.temp = this.b / this.a;
- this.es = 1 - Math.pow(this.temp, 2);
- this.e3 = Math.sqrt(this.es);
-
- this.sin_po = Math.sin(this.lat1);
- this.cos_po = Math.cos(this.lat1);
- this.t1 = this.sin_po;
- this.con = this.sin_po;
- this.ms1 = msfnz(this.e3, this.sin_po, this.cos_po);
- this.qs1 = qsfnz(this.e3, this.sin_po, this.cos_po);
-
- this.sin_po = Math.sin(this.lat2);
- this.cos_po = Math.cos(this.lat2);
- this.t2 = this.sin_po;
- this.ms2 = msfnz(this.e3, this.sin_po, this.cos_po);
- this.qs2 = qsfnz(this.e3, this.sin_po, this.cos_po);
-
- this.sin_po = Math.sin(this.lat0);
- this.cos_po = Math.cos(this.lat0);
- this.t3 = this.sin_po;
- this.qs0 = qsfnz(this.e3, this.sin_po, this.cos_po);
-
- if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
- this.ns0 = (this.ms1 * this.ms1 - this.ms2 * this.ms2) / (this.qs2 - this.qs1);
- }
- else {
- this.ns0 = this.con;
- }
- this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
- this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0) / this.ns0;
-};
-
-/* Albers Conical Equal Area forward equations--mapping lat,long to x,y
- -------------------------------------------------------------------*/
-exports.forward = function(p) {
-
- var lon = p.x;
- var lat = p.y;
-
- this.sin_phi = Math.sin(lat);
- this.cos_phi = Math.cos(lat);
-
- var qs = qsfnz(this.e3, this.sin_phi, this.cos_phi);
- var rh1 = this.a * Math.sqrt(this.c - this.ns0 * qs) / this.ns0;
- var theta = this.ns0 * adjust_lon(lon - this.long0);
- var x = rh1 * Math.sin(theta) + this.x0;
- var y = this.rh - rh1 * Math.cos(theta) + this.y0;
-
- p.x = x;
- p.y = y;
- return p;
-};
-
-
-exports.inverse = function(p) {
- var rh1, qs, con, theta, lon, lat;
-
- p.x -= this.x0;
- p.y = this.rh - p.y + this.y0;
- if (this.ns0 >= 0) {
- rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
- con = 1;
- }
- else {
- rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
- con = -1;
- }
- theta = 0;
- if (rh1 !== 0) {
- theta = Math.atan2(con * p.x, con * p.y);
- }
- con = rh1 * this.ns0 / this.a;
- if (this.sphere) {
- lat = Math.asin((this.c - con * con) / (2 * this.ns0));
- }
- else {
- qs = (this.c - con * con) / this.ns0;
- lat = this.phi1z(this.e3, qs);
- }
-
- lon = adjust_lon(theta / this.ns0 + this.long0);
- p.x = lon;
- p.y = lat;
- return p;
-};
-
-/* Function to compute phi1, the latitude for the inverse of the
- Albers Conical Equal-Area projection.
--------------------------------------------*/
-exports.phi1z = function(eccent, qs) {
- var sinphi, cosphi, con, com, dphi;
- var phi = asinz(0.5 * qs);
- if (eccent < EPSLN) {
- return phi;
- }
-
- var eccnts = eccent * eccent;
- for (var i = 1; i <= 25; i++) {
- sinphi = Math.sin(phi);
- cosphi = Math.cos(phi);
- con = eccent * sinphi;
- com = 1 - con * con;
- dphi = 0.5 * com * com / cosphi * (qs / (1 - eccnts) - sinphi / com + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
- phi = phi + dphi;
- if (Math.abs(dphi) <= 1e-7) {
- return phi;
- }
- }
- return null;
-};
-exports.names = ["Albers_Conic_Equal_Area", "Albers", "aea"];
-
-},{"../common/adjust_lon":5,"../common/asinz":7,"../common/msfnz":16,"../common/qsfnz":21}],43:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var mlfn = require('../common/mlfn');
-var e0fn = require('../common/e0fn');
-var e1fn = require('../common/e1fn');
-var e2fn = require('../common/e2fn');
-var e3fn = require('../common/e3fn');
-var gN = require('../common/gN');
-var asinz = require('../common/asinz');
-var imlfn = require('../common/imlfn');
-exports.init = function() {
- this.sin_p12 = Math.sin(this.lat0);
- this.cos_p12 = Math.cos(this.lat0);
-};
-
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
- var sinphi = Math.sin(p.y);
- var cosphi = Math.cos(p.y);
- var dlon = adjust_lon(lon - this.long0);
- var e0, e1, e2, e3, Mlp, Ml, tanphi, Nl1, Nl, psi, Az, G, H, GH, Hs, c, kp, cos_c, s, s2, s3, s4, s5;
- if (this.sphere) {
- if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
- //North Pole case
- p.x = this.x0 + this.a * (HALF_PI - lat) * Math.sin(dlon);
- p.y = this.y0 - this.a * (HALF_PI - lat) * Math.cos(dlon);
- return p;
- }
- else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
- //South Pole case
- p.x = this.x0 + this.a * (HALF_PI + lat) * Math.sin(dlon);
- p.y = this.y0 + this.a * (HALF_PI + lat) * Math.cos(dlon);
- return p;
- }
- else {
- //default case
- cos_c = this.sin_p12 * sinphi + this.cos_p12 * cosphi * Math.cos(dlon);
- c = Math.acos(cos_c);
- kp = c / Math.sin(c);
- p.x = this.x0 + this.a * kp * cosphi * Math.sin(dlon);
- p.y = this.y0 + this.a * kp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * Math.cos(dlon));
- return p;
- }
- }
- else {
- e0 = e0fn(this.es);
- e1 = e1fn(this.es);
- e2 = e2fn(this.es);
- e3 = e3fn(this.es);
- if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
- //North Pole case
- Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
- Ml = this.a * mlfn(e0, e1, e2, e3, lat);
- p.x = this.x0 + (Mlp - Ml) * Math.sin(dlon);
- p.y = this.y0 - (Mlp - Ml) * Math.cos(dlon);
- return p;
- }
- else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
- //South Pole case
- Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
- Ml = this.a * mlfn(e0, e1, e2, e3, lat);
- p.x = this.x0 + (Mlp + Ml) * Math.sin(dlon);
- p.y = this.y0 + (Mlp + Ml) * Math.cos(dlon);
- return p;
- }
- else {
- //Default case
- tanphi = sinphi / cosphi;
- Nl1 = gN(this.a, this.e, this.sin_p12);
- Nl = gN(this.a, this.e, sinphi);
- psi = Math.atan((1 - this.es) * tanphi + this.es * Nl1 * this.sin_p12 / (Nl * cosphi));
- Az = Math.atan2(Math.sin(dlon), this.cos_p12 * Math.tan(psi) - this.sin_p12 * Math.cos(dlon));
- if (Az === 0) {
- s = Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
- }
- else if (Math.abs(Math.abs(Az) - Math.PI) <= EPSLN) {
- s = -Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
- }
- else {
- s = Math.asin(Math.sin(dlon) * Math.cos(psi) / Math.sin(Az));
- }
- G = this.e * this.sin_p12 / Math.sqrt(1 - this.es);
- H = this.e * this.cos_p12 * Math.cos(Az) / Math.sqrt(1 - this.es);
- GH = G * H;
- Hs = H * H;
- s2 = s * s;
- s3 = s2 * s;
- s4 = s3 * s;
- s5 = s4 * s;
- c = Nl1 * s * (1 - s2 * Hs * (1 - Hs) / 6 + s3 / 8 * GH * (1 - 2 * Hs) + s4 / 120 * (Hs * (4 - 7 * Hs) - 3 * G * G * (1 - 7 * Hs)) - s5 / 48 * GH);
- p.x = this.x0 + c * Math.sin(Az);
- p.y = this.y0 + c * Math.cos(Az);
- return p;
- }
- }
-
-
-};
-
-exports.inverse = function(p) {
- p.x -= this.x0;
- p.y -= this.y0;
- var rh, z, sinz, cosz, lon, lat, con, e0, e1, e2, e3, Mlp, M, N1, psi, Az, cosAz, tmp, A, B, D, Ee, F;
- if (this.sphere) {
- rh = Math.sqrt(p.x * p.x + p.y * p.y);
- if (rh > (2 * HALF_PI * this.a)) {
- return;
- }
- z = rh / this.a;
-
- sinz = Math.sin(z);
- cosz = Math.cos(z);
-
- lon = this.long0;
- if (Math.abs(rh) <= EPSLN) {
- lat = this.lat0;
- }
- else {
- lat = asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
- con = Math.abs(this.lat0) - HALF_PI;
- if (Math.abs(con) <= EPSLN) {
- if (this.lat0 >= 0) {
- lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
- }
- else {
- lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
- }
- }
- else {
- /*con = cosz - this.sin_p12 * Math.sin(lat);
- if ((Math.abs(con) < EPSLN) && (Math.abs(p.x) < EPSLN)) {
- //no-op, just keep the lon value as is
- } else {
- var temp = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
- lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
- }*/
- lon = adjust_lon(this.long0 + Math.atan2(p.x * sinz, rh * this.cos_p12 * cosz - p.y * this.sin_p12 * sinz));
- }
- }
-
- p.x = lon;
- p.y = lat;
- return p;
- }
- else {
- e0 = e0fn(this.es);
- e1 = e1fn(this.es);
- e2 = e2fn(this.es);
- e3 = e3fn(this.es);
- if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
- //North pole case
- Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
- rh = Math.sqrt(p.x * p.x + p.y * p.y);
- M = Mlp - rh;
- lat = imlfn(M / this.a, e0, e1, e2, e3);
- lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
- p.x = lon;
- p.y = lat;
- return p;
- }
- else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
- //South pole case
- Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
- rh = Math.sqrt(p.x * p.x + p.y * p.y);
- M = rh - Mlp;
-
- lat = imlfn(M / this.a, e0, e1, e2, e3);
- lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
- p.x = lon;
- p.y = lat;
- return p;
- }
- else {
- //default case
- rh = Math.sqrt(p.x * p.x + p.y * p.y);
- Az = Math.atan2(p.x, p.y);
- N1 = gN(this.a, this.e, this.sin_p12);
- cosAz = Math.cos(Az);
- tmp = this.e * this.cos_p12 * cosAz;
- A = -tmp * tmp / (1 - this.es);
- B = 3 * this.es * (1 - A) * this.sin_p12 * this.cos_p12 * cosAz / (1 - this.es);
- D = rh / N1;
- Ee = D - A * (1 + A) * Math.pow(D, 3) / 6 - B * (1 + 3 * A) * Math.pow(D, 4) / 24;
- F = 1 - A * Ee * Ee / 2 - D * Ee * Ee * Ee / 6;
- psi = Math.asin(this.sin_p12 * Math.cos(Ee) + this.cos_p12 * Math.sin(Ee) * cosAz);
- lon = adjust_lon(this.long0 + Math.asin(Math.sin(Az) * Math.sin(Ee) / Math.cos(psi)));
- lat = Math.atan((1 - this.es * F * this.sin_p12 / Math.sin(psi)) * Math.tan(psi) / (1 - this.es));
- p.x = lon;
- p.y = lat;
- return p;
- }
- }
-
-};
-exports.names = ["Azimuthal_Equidistant", "aeqd"];
-
-},{"../common/adjust_lon":5,"../common/asinz":7,"../common/e0fn":8,"../common/e1fn":9,"../common/e2fn":10,"../common/e3fn":11,"../common/gN":12,"../common/imlfn":13,"../common/mlfn":15}],44:[function(require,module,exports){
-var mlfn = require('../common/mlfn');
-var e0fn = require('../common/e0fn');
-var e1fn = require('../common/e1fn');
-var e2fn = require('../common/e2fn');
-var e3fn = require('../common/e3fn');
-var gN = require('../common/gN');
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-var imlfn = require('../common/imlfn');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-exports.init = function() {
- if (!this.sphere) {
- 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);
- }
-};
-
-
-
-/* Cassini forward equations--mapping lat,long to x,y
- -----------------------------------------------------------------------*/
-exports.forward = function(p) {
-
- /* Forward equations
- -----------------*/
- var x, y;
- var lam = p.x;
- var phi = p.y;
- lam = adjust_lon(lam - this.long0);
-
- if (this.sphere) {
- x = this.a * Math.asin(Math.cos(phi) * Math.sin(lam));
- y = this.a * (Math.atan2(Math.tan(phi), Math.cos(lam)) - this.lat0);
- }
- else {
- //ellipsoid
- var sinphi = Math.sin(phi);
- var cosphi = Math.cos(phi);
- var nl = gN(this.a, this.e, sinphi);
- var tl = Math.tan(phi) * Math.tan(phi);
- var al = lam * Math.cos(phi);
- var asq = al * al;
- var cl = this.es * cosphi * cosphi / (1 - this.es);
- var ml = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
-
- x = nl * al * (1 - asq * tl * (1 / 6 - (8 - tl + 8 * cl) * asq / 120));
- y = ml - this.ml0 + nl * sinphi / cosphi * asq * (0.5 + (5 - tl + 6 * cl) * asq / 24);
-
-
- }
-
- p.x = x + this.x0;
- p.y = y + this.y0;
- return p;
-};
-
-/* Inverse equations
- -----------------*/
-exports.inverse = function(p) {
- p.x -= this.x0;
- p.y -= this.y0;
- var x = p.x / this.a;
- var y = p.y / this.a;
- var phi, lam;
-
- if (this.sphere) {
- var dd = y + this.lat0;
- phi = Math.asin(Math.sin(dd) * Math.cos(x));
- lam = Math.atan2(Math.tan(x), Math.cos(dd));
- }
- else {
- /* ellipsoid */
- var ml1 = this.ml0 / this.a + y;
- var phi1 = imlfn(ml1, this.e0, this.e1, this.e2, this.e3);
- if (Math.abs(Math.abs(phi1) - HALF_PI) <= EPSLN) {
- p.x = this.long0;
- p.y = HALF_PI;
- if (y < 0) {
- p.y *= -1;
- }
- return p;
- }
- var nl1 = gN(this.a, this.e, Math.sin(phi1));
-
- var rl1 = nl1 * nl1 * nl1 / this.a / this.a * (1 - this.es);
- var tl1 = Math.pow(Math.tan(phi1), 2);
- var dl = x * this.a / nl1;
- var dsq = dl * dl;
- phi = phi1 - nl1 * Math.tan(phi1) / rl1 * dl * dl * (0.5 - (1 + 3 * tl1) * dl * dl / 24);
- lam = dl * (1 - dsq * (tl1 / 3 + (1 + 3 * tl1) * tl1 * dsq / 15)) / Math.cos(phi1);
-
- }
-
- p.x = adjust_lon(lam + this.long0);
- p.y = adjust_lat(phi);
- return p;
-
-};
-exports.names = ["Cassini", "Cassini_Soldner", "cass"];
-},{"../common/adjust_lat":4,"../common/adjust_lon":5,"../common/e0fn":8,"../common/e1fn":9,"../common/e2fn":10,"../common/e3fn":11,"../common/gN":12,"../common/imlfn":13,"../common/mlfn":15}],45:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-var qsfnz = require('../common/qsfnz');
-var msfnz = require('../common/msfnz');
-var iqsfnz = require('../common/iqsfnz');
-/*
- reference:
- "Cartographic Projection Procedures for the UNIX Environment-
- A User's Manual" by Gerald I. Evenden,
- USGS Open File Report 90-284and Release 4 Interim Reports (2003)
-*/
-exports.init = function() {
- //no-op
- if (!this.sphere) {
- this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
- }
-};
-
-
-/* Cylindrical Equal Area forward equations--mapping lat,long to x,y
- ------------------------------------------------------------*/
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
- var x, y;
- /* Forward equations
- -----------------*/
- var dlon = adjust_lon(lon - this.long0);
- if (this.sphere) {
- x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
- y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
- }
- else {
- var qs = qsfnz(this.e, Math.sin(lat));
- x = this.x0 + this.a * this.k0 * dlon;
- y = this.y0 + this.a * qs * 0.5 / this.k0;
- }
-
- p.x = x;
- p.y = y;
- return p;
-};
-
-/* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
- ------------------------------------------------------------*/
-exports.inverse = function(p) {
- p.x -= this.x0;
- p.y -= this.y0;
- var lon, lat;
-
- if (this.sphere) {
- lon = adjust_lon(this.long0 + (p.x / this.a) / Math.cos(this.lat_ts));
- lat = Math.asin((p.y / this.a) * Math.cos(this.lat_ts));
- }
- else {
- lat = iqsfnz(this.e, 2 * p.y * this.k0 / this.a);
- lon = adjust_lon(this.long0 + p.x / (this.a * this.k0));
- }
-
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["cea"];
-
-},{"../common/adjust_lon":5,"../common/iqsfnz":14,"../common/msfnz":16,"../common/qsfnz":21}],46:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-exports.init = function() {
-
- this.x0 = this.x0 || 0;
- this.y0 = this.y0 || 0;
- this.lat0 = this.lat0 || 0;
- this.long0 = this.long0 || 0;
- this.lat_ts = this.lat_ts || 0;
- this.title = this.title || "Equidistant Cylindrical (Plate Carre)";
-
- this.rc = Math.cos(this.lat_ts);
-};
-
-
-// forward equations--mapping lat,long to x,y
-// -----------------------------------------------------------------
-exports.forward = function(p) {
-
- var lon = p.x;
- var lat = p.y;
-
- var dlon = adjust_lon(lon - this.long0);
- var dlat = adjust_lat(lat - this.lat0);
- p.x = this.x0 + (this.a * dlon * this.rc);
- p.y = this.y0 + (this.a * dlat);
- return p;
-};
-
-// inverse equations--mapping x,y to lat/long
-// -----------------------------------------------------------------
-exports.inverse = function(p) {
-
- var x = p.x;
- var y = p.y;
-
- p.x = adjust_lon(this.long0 + ((x - this.x0) / (this.a * this.rc)));
- p.y = adjust_lat(this.lat0 + ((y - this.y0) / (this.a)));
- return p;
-};
-exports.names = ["Equirectangular", "Equidistant_Cylindrical", "eqc"];
-
-},{"../common/adjust_lat":4,"../common/adjust_lon":5}],47:[function(require,module,exports){
-var e0fn = require('../common/e0fn');
-var e1fn = require('../common/e1fn');
-var e2fn = require('../common/e2fn');
-var e3fn = require('../common/e3fn');
-var msfnz = require('../common/msfnz');
-var mlfn = require('../common/mlfn');
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-var imlfn = require('../common/imlfn');
-var EPSLN = 1.0e-10;
-exports.init = function() {
-
- /* Place parameters in static storage for common use
- -------------------------------------------------*/
- // Standard Parallels cannot be equal and on opposite sides of the equator
- if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
- return;
- }
- this.lat2 = this.lat2 || this.lat1;
- this.temp = this.b / this.a;
- this.es = 1 - Math.pow(this.temp, 2);
- this.e = Math.sqrt(this.es);
- this.e0 = e0fn(this.es);
- this.e1 = e1fn(this.es);
- this.e2 = e2fn(this.es);
- this.e3 = e3fn(this.es);
-
- this.sinphi = Math.sin(this.lat1);
- this.cosphi = Math.cos(this.lat1);
-
- this.ms1 = msfnz(this.e, this.sinphi, this.cosphi);
- this.ml1 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat1);
-
- if (Math.abs(this.lat1 - this.lat2) < EPSLN) {
- this.ns = this.sinphi;
- }
- else {
- this.sinphi = Math.sin(this.lat2);
- this.cosphi = Math.cos(this.lat2);
- this.ms2 = msfnz(this.e, this.sinphi, this.cosphi);
- this.ml2 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
- this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
- }
- this.g = this.ml1 + this.ms1 / this.ns;
- this.ml0 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
- this.rh = this.a * (this.g - this.ml0);
-};
-
-
-/* Equidistant Conic forward equations--mapping lat,long to x,y
- -----------------------------------------------------------*/
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
- var rh1;
-
- /* Forward equations
- -----------------*/
- if (this.sphere) {
- rh1 = this.a * (this.g - lat);
- }
- else {
- var ml = mlfn(this.e0, this.e1, this.e2, this.e3, lat);
- rh1 = this.a * (this.g - ml);
- }
- var theta = this.ns * adjust_lon(lon - this.long0);
- var x = this.x0 + rh1 * Math.sin(theta);
- var y = this.y0 + this.rh - rh1 * Math.cos(theta);
- p.x = x;
- p.y = y;
- return p;
-};
-
-/* Inverse equations
- -----------------*/
-exports.inverse = function(p) {
- p.x -= this.x0;
- p.y = this.rh - p.y + this.y0;
- var con, rh1, lat, lon;
- if (this.ns >= 0) {
- rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
- con = 1;
- }
- else {
- rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
- con = -1;
- }
- var theta = 0;
- if (rh1 !== 0) {
- theta = Math.atan2(con * p.x, con * p.y);
- }
-
- if (this.sphere) {
- lon = adjust_lon(this.long0 + theta / this.ns);
- lat = adjust_lat(this.g - rh1 / this.a);
- p.x = lon;
- p.y = lat;
- return p;
- }
- else {
- var ml = this.g - rh1 / this.a;
- lat = imlfn(ml, this.e0, this.e1, this.e2, this.e3);
- lon = adjust_lon(this.long0 + theta / this.ns);
- p.x = lon;
- p.y = lat;
- return p;
- }
-
-};
-exports.names = ["Equidistant_Conic", "eqdc"];
-
-},{"../common/adjust_lat":4,"../common/adjust_lon":5,"../common/e0fn":8,"../common/e1fn":9,"../common/e2fn":10,"../common/e3fn":11,"../common/imlfn":13,"../common/mlfn":15,"../common/msfnz":16}],48:[function(require,module,exports){
-var FORTPI = Math.PI/4;
-var srat = require('../common/srat');
-var HALF_PI = Math.PI/2;
-var MAX_ITER = 20;
-exports.init = function() {
- var sphi = Math.sin(this.lat0);
- var cphi = Math.cos(this.lat0);
- cphi *= cphi;
- this.rc = Math.sqrt(1 - this.es) / (1 - this.es * sphi * sphi);
- this.C = Math.sqrt(1 + this.es * cphi * cphi / (1 - this.es));
- this.phic0 = Math.asin(sphi / this.C);
- this.ratexp = 0.5 * this.C * this.e;
- this.K = Math.tan(0.5 * this.phic0 + FORTPI) / (Math.pow(Math.tan(0.5 * this.lat0 + FORTPI), this.C) * srat(this.e * sphi, this.ratexp));
-};
-
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
-
- p.y = 2 * Math.atan(this.K * Math.pow(Math.tan(0.5 * lat + FORTPI), this.C) * srat(this.e * Math.sin(lat), this.ratexp)) - HALF_PI;
- p.x = this.C * lon;
- return p;
-};
-
-exports.inverse = function(p) {
- var DEL_TOL = 1e-14;
- var lon = p.x / this.C;
- var lat = p.y;
- var num = Math.pow(Math.tan(0.5 * lat + FORTPI) / this.K, 1 / this.C);
- for (var i = MAX_ITER; i > 0; --i) {
- lat = 2 * Math.atan(num * srat(this.e * Math.sin(p.y), - 0.5 * this.e)) - HALF_PI;
- if (Math.abs(lat - p.y) < DEL_TOL) {
- break;
- }
- p.y = lat;
- }
- /* convergence failed */
- if (!i) {
- return null;
- }
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["gauss"];
-
-},{"../common/srat":23}],49:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-var EPSLN = 1.0e-10;
-var asinz = require('../common/asinz');
-
-/*
- reference:
- Wolfram Mathworld "Gnomonic Projection"
- http://mathworld.wolfram.com/GnomonicProjection.html
- Accessed: 12th November 2009
- */
-exports.init = function() {
-
- /* Place parameters in static storage for common use
- -------------------------------------------------*/
- this.sin_p14 = Math.sin(this.lat0);
- this.cos_p14 = Math.cos(this.lat0);
- // Approximation for projecting points to the horizon (infinity)
- this.infinity_dist = 1000 * this.a;
- this.rc = 1;
-};
-
-
-/* Gnomonic forward equations--mapping lat,long to x,y
- ---------------------------------------------------*/
-exports.forward = function(p) {
- var sinphi, cosphi; /* sin and cos value */
- var dlon; /* delta longitude value */
- var coslon; /* cos of longitude */
- var ksp; /* scale factor */
- var g;
- var x, y;
- var lon = p.x;
- var lat = p.y;
- /* Forward equations
- -----------------*/
- dlon = adjust_lon(lon - this.long0);
-
- sinphi = Math.sin(lat);
- cosphi = Math.cos(lat);
-
- coslon = Math.cos(dlon);
- g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
- ksp = 1;
- if ((g > 0) || (Math.abs(g) <= EPSLN)) {
- x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon) / g;
- y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon) / g;
- }
- else {
-
- // Point is in the opposing hemisphere and is unprojectable
- // We still need to return a reasonable point, so we project
- // to infinity, on a bearing
- // equivalent to the northern hemisphere equivalent
- // This is a reasonable approximation for short shapes and lines that
- // straddle the horizon.
-
- x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon);
- y = this.y0 + this.infinity_dist * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
-
- }
- p.x = x;
- p.y = y;
- return p;
-};
-
-
-exports.inverse = function(p) {
- var rh; /* Rho */
- var sinc, cosc;
- var c;
- var lon, lat;
-
- /* Inverse equations
- -----------------*/
- p.x = (p.x - this.x0) / this.a;
- p.y = (p.y - this.y0) / this.a;
-
- p.x /= this.k0;
- p.y /= this.k0;
-
- if ((rh = Math.sqrt(p.x * p.x + p.y * p.y))) {
- c = Math.atan2(rh, this.rc);
- sinc = Math.sin(c);
- cosc = Math.cos(c);
-
- lat = asinz(cosc * this.sin_p14 + (p.y * sinc * this.cos_p14) / rh);
- lon = Math.atan2(p.x * sinc, rh * this.cos_p14 * cosc - p.y * this.sin_p14 * sinc);
- lon = adjust_lon(this.long0 + lon);
- }
- else {
- lat = this.phic0;
- lon = 0;
- }
-
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["gnom"];
-
-},{"../common/adjust_lon":5,"../common/asinz":7}],50:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-exports.init = function() {
- this.a = 6377397.155;
- this.es = 0.006674372230614;
- this.e = Math.sqrt(this.es);
- if (!this.lat0) {
- this.lat0 = 0.863937979737193;
- }
- if (!this.long0) {
- this.long0 = 0.7417649320975901 - 0.308341501185665;
- }
- /* if scale not set default to 0.9999 */
- if (!this.k0) {
- this.k0 = 0.9999;
- }
- this.s45 = 0.785398163397448; /* 45 */
- this.s90 = 2 * this.s45;
- this.fi0 = this.lat0;
- this.e2 = this.es;
- this.e = Math.sqrt(this.e2);
- this.alfa = Math.sqrt(1 + (this.e2 * Math.pow(Math.cos(this.fi0), 4)) / (1 - this.e2));
- this.uq = 1.04216856380474;
- this.u0 = Math.asin(Math.sin(this.fi0) / this.alfa);
- this.g = Math.pow((1 + this.e * Math.sin(this.fi0)) / (1 - this.e * Math.sin(this.fi0)), this.alfa * this.e / 2);
- this.k = Math.tan(this.u0 / 2 + this.s45) / Math.pow(Math.tan(this.fi0 / 2 + this.s45), this.alfa) * this.g;
- this.k1 = this.k0;
- this.n0 = this.a * Math.sqrt(1 - this.e2) / (1 - this.e2 * Math.pow(Math.sin(this.fi0), 2));
- this.s0 = 1.37008346281555;
- this.n = Math.sin(this.s0);
- this.ro0 = this.k1 * this.n0 / Math.tan(this.s0);
- this.ad = this.s90 - this.uq;
-};
-
-/* ellipsoid */
-/* calculate xy from lat/lon */
-/* Constants, identical to inverse transform function */
-exports.forward = function(p) {
- var gfi, u, deltav, s, d, eps, ro;
- var lon = p.x;
- var lat = p.y;
- var delta_lon = adjust_lon(lon - this.long0);
- /* Transformation */
- gfi = Math.pow(((1 + this.e * Math.sin(lat)) / (1 - this.e * Math.sin(lat))), (this.alfa * this.e / 2));
- u = 2 * (Math.atan(this.k * Math.pow(Math.tan(lat / 2 + this.s45), this.alfa) / gfi) - this.s45);
- deltav = -delta_lon * this.alfa;
- s = Math.asin(Math.cos(this.ad) * Math.sin(u) + Math.sin(this.ad) * Math.cos(u) * Math.cos(deltav));
- d = Math.asin(Math.cos(u) * Math.sin(deltav) / Math.cos(s));
- eps = this.n * d;
- ro = this.ro0 * Math.pow(Math.tan(this.s0 / 2 + this.s45), this.n) / Math.pow(Math.tan(s / 2 + this.s45), this.n);
- p.y = ro * Math.cos(eps) / 1;
- p.x = ro * Math.sin(eps) / 1;
-
- if (!this.czech) {
- p.y *= -1;
- p.x *= -1;
- }
- return (p);
-};
-
-/* calculate lat/lon from xy */
-exports.inverse = function(p) {
- var u, deltav, s, d, eps, ro, fi1;
- var ok;
-
- /* Transformation */
- /* revert y, x*/
- var tmp = p.x;
- p.x = p.y;
- p.y = tmp;
- if (!this.czech) {
- p.y *= -1;
- p.x *= -1;
- }
- ro = Math.sqrt(p.x * p.x + p.y * p.y);
- eps = Math.atan2(p.y, p.x);
- d = eps / Math.sin(this.s0);
- s = 2 * (Math.atan(Math.pow(this.ro0 / ro, 1 / this.n) * Math.tan(this.s0 / 2 + this.s45)) - this.s45);
- u = Math.asin(Math.cos(this.ad) * Math.sin(s) - Math.sin(this.ad) * Math.cos(s) * Math.cos(d));
- deltav = Math.asin(Math.cos(s) * Math.sin(d) / Math.cos(u));
- p.x = this.long0 - deltav / this.alfa;
- fi1 = u;
- ok = 0;
- var iter = 0;
- do {
- p.y = 2 * (Math.atan(Math.pow(this.k, - 1 / this.alfa) * Math.pow(Math.tan(u / 2 + this.s45), 1 / this.alfa) * Math.pow((1 + this.e * Math.sin(fi1)) / (1 - this.e * Math.sin(fi1)), this.e / 2)) - this.s45);
- if (Math.abs(fi1 - p.y) < 0.0000000001) {
- ok = 1;
- }
- fi1 = p.y;
- iter += 1;
- } while (ok === 0 && iter < 15);
- if (iter >= 15) {
- return null;
- }
-
- return (p);
-};
-exports.names = ["Krovak", "krovak"];
-
-},{"../common/adjust_lon":5}],51:[function(require,module,exports){
-var HALF_PI = Math.PI/2;
-var FORTPI = Math.PI/4;
-var EPSLN = 1.0e-10;
-var qsfnz = require('../common/qsfnz');
-var adjust_lon = require('../common/adjust_lon');
-/*
- reference
- "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
- The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
- */
-
-exports.S_POLE = 1;
-exports.N_POLE = 2;
-exports.EQUIT = 3;
-exports.OBLIQ = 4;
-
-
-/* Initialize the Lambert Azimuthal Equal Area projection
- ------------------------------------------------------*/
-exports.init = function() {
- var t = Math.abs(this.lat0);
- if (Math.abs(t - HALF_PI) < EPSLN) {
- this.mode = this.lat0 < 0 ? this.S_POLE : this.N_POLE;
- }
- else if (Math.abs(t) < EPSLN) {
- this.mode = this.EQUIT;
- }
- else {
- this.mode = this.OBLIQ;
- }
- if (this.es > 0) {
- var sinphi;
-
- this.qp = qsfnz(this.e, 1);
- this.mmf = 0.5 / (1 - this.es);
- this.apa = this.authset(this.es);
- switch (this.mode) {
- case this.N_POLE:
- this.dd = 1;
- break;
- case this.S_POLE:
- this.dd = 1;
- break;
- case this.EQUIT:
- this.rq = Math.sqrt(0.5 * this.qp);
- this.dd = 1 / this.rq;
- this.xmf = 1;
- this.ymf = 0.5 * this.qp;
- break;
- case this.OBLIQ:
- this.rq = Math.sqrt(0.5 * this.qp);
- sinphi = Math.sin(this.lat0);
- this.sinb1 = qsfnz(this.e, sinphi) / this.qp;
- this.cosb1 = Math.sqrt(1 - this.sinb1 * this.sinb1);
- this.dd = Math.cos(this.lat0) / (Math.sqrt(1 - this.es * sinphi * sinphi) * this.rq * this.cosb1);
- this.ymf = (this.xmf = this.rq) / this.dd;
- this.xmf *= this.dd;
- break;
- }
- }
- else {
- if (this.mode === this.OBLIQ) {
- this.sinph0 = Math.sin(this.lat0);
- this.cosph0 = Math.cos(this.lat0);
- }
- }
-};
-
-/* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
- -----------------------------------------------------------------------*/
-exports.forward = function(p) {
-
- /* Forward equations
- -----------------*/
- var x, y, coslam, sinlam, sinphi, q, sinb, cosb, b, cosphi;
- var lam = p.x;
- var phi = p.y;
-
- lam = adjust_lon(lam - this.long0);
-
- if (this.sphere) {
- sinphi = Math.sin(phi);
- cosphi = Math.cos(phi);
- coslam = Math.cos(lam);
- if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
- y = (this.mode === this.EQUIT) ? 1 + cosphi * coslam : 1 + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
- if (y <= EPSLN) {
- return null;
- }
- y = Math.sqrt(2 / y);
- x = y * cosphi * Math.sin(lam);
- y *= (this.mode === this.EQUIT) ? sinphi : this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
- }
- else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
- if (this.mode === this.N_POLE) {
- coslam = -coslam;
- }
- if (Math.abs(phi + this.phi0) < EPSLN) {
- return null;
- }
- y = FORTPI - phi * 0.5;
- y = 2 * ((this.mode === this.S_POLE) ? Math.cos(y) : Math.sin(y));
- x = y * Math.sin(lam);
- y *= coslam;
- }
- }
- else {
- sinb = 0;
- cosb = 0;
- b = 0;
- coslam = Math.cos(lam);
- sinlam = Math.sin(lam);
- sinphi = Math.sin(phi);
- q = qsfnz(this.e, sinphi);
- if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
- sinb = q / this.qp;
- cosb = Math.sqrt(1 - sinb * sinb);
- }
- switch (this.mode) {
- case this.OBLIQ:
- b = 1 + this.sinb1 * sinb + this.cosb1 * cosb * coslam;
- break;
- case this.EQUIT:
- b = 1 + cosb * coslam;
- break;
- case this.N_POLE:
- b = HALF_PI + phi;
- q = this.qp - q;
- break;
- case this.S_POLE:
- b = phi - HALF_PI;
- q = this.qp + q;
- break;
- }
- if (Math.abs(b) < EPSLN) {
- return null;
- }
- switch (this.mode) {
- case this.OBLIQ:
- case this.EQUIT:
- b = Math.sqrt(2 / b);
- if (this.mode === this.OBLIQ) {
- y = this.ymf * b * (this.cosb1 * sinb - this.sinb1 * cosb * coslam);
- }
- else {
- y = (b = Math.sqrt(2 / (1 + cosb * coslam))) * sinb * this.ymf;
- }
- x = this.xmf * b * cosb * sinlam;
- break;
- case this.N_POLE:
- case this.S_POLE:
- if (q >= 0) {
- x = (b = Math.sqrt(q)) * sinlam;
- y = coslam * ((this.mode === this.S_POLE) ? b : -b);
- }
- else {
- x = y = 0;
- }
- break;
- }
- }
-
- p.x = this.a * x + this.x0;
- p.y = this.a * y + this.y0;
- return p;
-};
-
-/* Inverse equations
- -----------------*/
-exports.inverse = function(p) {
- p.x -= this.x0;
- p.y -= this.y0;
- var x = p.x / this.a;
- var y = p.y / this.a;
- var lam, phi, cCe, sCe, q, rho, ab;
-
- if (this.sphere) {
- var cosz = 0,
- rh, sinz = 0;
-
- rh = Math.sqrt(x * x + y * y);
- phi = rh * 0.5;
- if (phi > 1) {
- return null;
- }
- phi = 2 * Math.asin(phi);
- if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
- sinz = Math.sin(phi);
- cosz = Math.cos(phi);
- }
- switch (this.mode) {
- case this.EQUIT:
- phi = (Math.abs(rh) <= EPSLN) ? 0 : Math.asin(y * sinz / rh);
- x *= sinz;
- y = cosz * rh;
- break;
- case this.OBLIQ:
- phi = (Math.abs(rh) <= EPSLN) ? this.phi0 : Math.asin(cosz * this.sinph0 + y * sinz * this.cosph0 / rh);
- x *= sinz * this.cosph0;
- y = (cosz - Math.sin(phi) * this.sinph0) * rh;
- break;
- case this.N_POLE:
- y = -y;
- phi = HALF_PI - phi;
- break;
- case this.S_POLE:
- phi -= HALF_PI;
- break;
- }
- lam = (y === 0 && (this.mode === this.EQUIT || this.mode === this.OBLIQ)) ? 0 : Math.atan2(x, y);
- }
- else {
- ab = 0;
- if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
- x /= this.dd;
- y *= this.dd;
- rho = Math.sqrt(x * x + y * y);
- if (rho < EPSLN) {
- p.x = 0;
- p.y = this.phi0;
- return p;
- }
- sCe = 2 * Math.asin(0.5 * rho / this.rq);
- cCe = Math.cos(sCe);
- x *= (sCe = Math.sin(sCe));
- if (this.mode === this.OBLIQ) {
- ab = cCe * this.sinb1 + y * sCe * this.cosb1 / rho;
- q = this.qp * ab;
- y = rho * this.cosb1 * cCe - y * this.sinb1 * sCe;
- }
- else {
- ab = y * sCe / rho;
- q = this.qp * ab;
- y = rho * cCe;
- }
- }
- else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
- if (this.mode === this.N_POLE) {
- y = -y;
- }
- q = (x * x + y * y);
- if (!q) {
- p.x = 0;
- p.y = this.phi0;
- return p;
- }
- ab = 1 - q / this.qp;
- if (this.mode === this.S_POLE) {
- ab = -ab;
- }
- }
- lam = Math.atan2(x, y);
- phi = this.authlat(Math.asin(ab), this.apa);
- }
-
-
- p.x = adjust_lon(this.long0 + lam);
- p.y = phi;
- return p;
-};
-
-/* determine latitude from authalic latitude */
-exports.P00 = 0.33333333333333333333;
-exports.P01 = 0.17222222222222222222;
-exports.P02 = 0.10257936507936507936;
-exports.P10 = 0.06388888888888888888;
-exports.P11 = 0.06640211640211640211;
-exports.P20 = 0.01641501294219154443;
-
-exports.authset = function(es) {
- var t;
- var APA = [];
- APA[0] = es * this.P00;
- t = es * es;
- APA[0] += t * this.P01;
- APA[1] = t * this.P10;
- t *= es;
- APA[0] += t * this.P02;
- APA[1] += t * this.P11;
- APA[2] = t * this.P20;
- return APA;
-};
-
-exports.authlat = function(beta, APA) {
- var t = beta + beta;
- return (beta + APA[0] * Math.sin(t) + APA[1] * Math.sin(t + t) + APA[2] * Math.sin(t + t + t));
-};
-exports.names = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"];
-
-},{"../common/adjust_lon":5,"../common/qsfnz":21}],52:[function(require,module,exports){
-var EPSLN = 1.0e-10;
-var msfnz = require('../common/msfnz');
-var tsfnz = require('../common/tsfnz');
-var HALF_PI = Math.PI/2;
-var sign = require('../common/sign');
-var adjust_lon = require('../common/adjust_lon');
-var phi2z = require('../common/phi2z');
-exports.init = function() {
-
- // array of: r_maj,r_min,lat1,lat2,c_lon,c_lat,false_east,false_north
- //double c_lat; /* center latitude */
- //double c_lon; /* center longitude */
- //double lat1; /* first standard parallel */
- //double lat2; /* second standard parallel */
- //double r_maj; /* major axis */
- //double r_min; /* minor axis */
- //double false_east; /* x offset in meters */
- //double false_north; /* y offset in meters */
-
- if (!this.lat2) {
- this.lat2 = this.lat1;
- } //if lat2 is not defined
- if (!this.k0) {
- this.k0 = 1;
- }
- this.x0 = this.x0 || 0;
- this.y0 = this.y0 || 0;
- // Standard Parallels cannot be equal and on opposite sides of the equator
- if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
- return;
- }
-
- var temp = this.b / this.a;
- this.e = Math.sqrt(1 - temp * temp);
-
- var sin1 = Math.sin(this.lat1);
- var cos1 = Math.cos(this.lat1);
- var ms1 = msfnz(this.e, sin1, cos1);
- var ts1 = tsfnz(this.e, this.lat1, sin1);
-
- var sin2 = Math.sin(this.lat2);
- var cos2 = Math.cos(this.lat2);
- var ms2 = msfnz(this.e, sin2, cos2);
- var ts2 = tsfnz(this.e, this.lat2, sin2);
-
- var ts0 = tsfnz(this.e, this.lat0, Math.sin(this.lat0));
-
- if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
- this.ns = Math.log(ms1 / ms2) / Math.log(ts1 / ts2);
- }
- else {
- this.ns = sin1;
- }
- if (isNaN(this.ns)) {
- this.ns = sin1;
- }
- this.f0 = ms1 / (this.ns * Math.pow(ts1, this.ns));
- this.rh = this.a * this.f0 * Math.pow(ts0, this.ns);
- if (!this.title) {
- this.title = "Lambert Conformal Conic";
- }
-};
-
-
-// Lambert Conformal conic forward equations--mapping lat,long to x,y
-// -----------------------------------------------------------------
-exports.forward = function(p) {
-
- var lon = p.x;
- var lat = p.y;
-
- // singular cases :
- if (Math.abs(2 * Math.abs(lat) - Math.PI) <= EPSLN) {
- lat = sign(lat) * (HALF_PI - 2 * EPSLN);
- }
-
- var con = Math.abs(Math.abs(lat) - HALF_PI);
- var ts, rh1;
- if (con > EPSLN) {
- ts = tsfnz(this.e, lat, Math.sin(lat));
- rh1 = this.a * this.f0 * Math.pow(ts, this.ns);
- }
- else {
- con = lat * this.ns;
- if (con <= 0) {
- return null;
- }
- rh1 = 0;
- }
- var theta = this.ns * adjust_lon(lon - this.long0);
- p.x = this.k0 * (rh1 * Math.sin(theta)) + this.x0;
- p.y = this.k0 * (this.rh - rh1 * Math.cos(theta)) + this.y0;
-
- return p;
-};
-
-// Lambert Conformal Conic inverse equations--mapping x,y to lat/long
-// -----------------------------------------------------------------
-exports.inverse = function(p) {
-
- var rh1, con, ts;
- var lat, lon;
- var x = (p.x - this.x0) / this.k0;
- var y = (this.rh - (p.y - this.y0) / this.k0);
- if (this.ns > 0) {
- rh1 = Math.sqrt(x * x + y * y);
- con = 1;
- }
- else {
- rh1 = -Math.sqrt(x * x + y * y);
- con = -1;
- }
- var theta = 0;
- if (rh1 !== 0) {
- theta = Math.atan2((con * x), (con * y));
- }
- if ((rh1 !== 0) || (this.ns > 0)) {
- con = 1 / this.ns;
- ts = Math.pow((rh1 / (this.a * this.f0)), con);
- lat = phi2z(this.e, ts);
- if (lat === -9999) {
- return null;
- }
- }
- else {
- lat = -HALF_PI;
- }
- lon = adjust_lon(theta / this.ns + this.long0);
-
- p.x = lon;
- p.y = lat;
- return p;
-};
-
-exports.names = ["Lambert Tangential Conformal Conic Projection", "Lambert_Conformal_Conic", "Lambert_Conformal_Conic_2SP", "lcc"];
-
-},{"../common/adjust_lon":5,"../common/msfnz":16,"../common/phi2z":17,"../common/sign":22,"../common/tsfnz":25}],53:[function(require,module,exports){
-exports.init = function() {
- //no-op for longlat
-};
-
-function identity(pt) {
- return pt;
-}
-exports.forward = identity;
-exports.inverse = identity;
-exports.names = ["longlat", "identity"];
-
-},{}],54:[function(require,module,exports){
-var msfnz = require('../common/msfnz');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var R2D = 57.29577951308232088;
-var adjust_lon = require('../common/adjust_lon');
-var FORTPI = Math.PI/4;
-var tsfnz = require('../common/tsfnz');
-var phi2z = require('../common/phi2z');
-exports.init = function() {
- var con = this.b / this.a;
- this.es = 1 - con * con;
- if(!('x0' in this)){
- this.x0 = 0;
- }
- if(!('y0' in this)){
- this.y0 = 0;
- }
- this.e = Math.sqrt(this.es);
- if (this.lat_ts) {
- if (this.sphere) {
- this.k0 = Math.cos(this.lat_ts);
- }
- else {
- this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
- }
- }
- else {
- if (!this.k0) {
- if (this.k) {
- this.k0 = this.k;
- }
- else {
- this.k0 = 1;
- }
- }
- }
-};
-
-/* Mercator forward equations--mapping lat,long to x,y
- --------------------------------------------------*/
-
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
- // convert to radians
- if (lat * R2D > 90 && lat * R2D < -90 && lon * R2D > 180 && lon * R2D < -180) {
- return null;
- }
-
- var x, y;
- if (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN) {
- return null;
- }
- else {
- if (this.sphere) {
- x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
- y = this.y0 + this.a * this.k0 * Math.log(Math.tan(FORTPI + 0.5 * lat));
- }
- else {
- var sinphi = Math.sin(lat);
- var ts = tsfnz(this.e, lat, sinphi);
- x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
- y = this.y0 - this.a * this.k0 * Math.log(ts);
- }
- p.x = x;
- p.y = y;
- return p;
- }
-};
-
-
-/* Mercator inverse equations--mapping x,y to lat/long
- --------------------------------------------------*/
-exports.inverse = function(p) {
-
- var x = p.x - this.x0;
- var y = p.y - this.y0;
- var lon, lat;
-
- if (this.sphere) {
- lat = HALF_PI - 2 * Math.atan(Math.exp(-y / (this.a * this.k0)));
- }
- else {
- var ts = Math.exp(-y / (this.a * this.k0));
- lat = phi2z(this.e, ts);
- if (lat === -9999) {
- return null;
- }
- }
- lon = adjust_lon(this.long0 + x / (this.a * this.k0));
-
- p.x = lon;
- p.y = lat;
- return p;
-};
-
-exports.names = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"];
-
-},{"../common/adjust_lon":5,"../common/msfnz":16,"../common/phi2z":17,"../common/tsfnz":25}],55:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-/*
- reference
- "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
- The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
- */
-
-
-/* Initialize the Miller Cylindrical projection
- -------------------------------------------*/
-exports.init = function() {
- //no-op
-};
-
-
-/* Miller Cylindrical forward equations--mapping lat,long to x,y
- ------------------------------------------------------------*/
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
- /* Forward equations
- -----------------*/
- var dlon = adjust_lon(lon - this.long0);
- var x = this.x0 + this.a * dlon;
- var y = this.y0 + this.a * Math.log(Math.tan((Math.PI / 4) + (lat / 2.5))) * 1.25;
-
- p.x = x;
- p.y = y;
- return p;
-};
-
-/* Miller Cylindrical inverse equations--mapping x,y to lat/long
- ------------------------------------------------------------*/
-exports.inverse = function(p) {
- p.x -= this.x0;
- p.y -= this.y0;
-
- var lon = adjust_lon(this.long0 + p.x / this.a);
- var lat = 2.5 * (Math.atan(Math.exp(0.8 * p.y / this.a)) - Math.PI / 4);
-
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["Miller_Cylindrical", "mill"];
-
-},{"../common/adjust_lon":5}],56:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-var EPSLN = 1.0e-10;
-exports.init = function() {};
-
-/* Mollweide forward equations--mapping lat,long to x,y
- ----------------------------------------------------*/
-exports.forward = function(p) {
-
- /* Forward equations
- -----------------*/
- var lon = p.x;
- var lat = p.y;
-
- var delta_lon = adjust_lon(lon - this.long0);
- var theta = lat;
- var con = Math.PI * Math.sin(lat);
-
- /* Iterate using the Newton-Raphson method to find theta
- -----------------------------------------------------*/
- for (var i = 0; true; i++) {
- var delta_theta = -(theta + Math.sin(theta) - con) / (1 + Math.cos(theta));
- theta += delta_theta;
- if (Math.abs(delta_theta) < EPSLN) {
- break;
- }
- }
- theta /= 2;
-
- /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
- this is done here because of precision problems with "cos(theta)"
- --------------------------------------------------------------------------*/
- if (Math.PI / 2 - Math.abs(lat) < EPSLN) {
- delta_lon = 0;
- }
- var x = 0.900316316158 * this.a * delta_lon * Math.cos(theta) + this.x0;
- var y = 1.4142135623731 * this.a * Math.sin(theta) + this.y0;
-
- p.x = x;
- p.y = y;
- return p;
-};
-
-exports.inverse = function(p) {
- var theta;
- var arg;
-
- /* Inverse equations
- -----------------*/
- p.x -= this.x0;
- p.y -= this.y0;
- arg = p.y / (1.4142135623731 * this.a);
-
- /* Because of division by zero problems, 'arg' can not be 1. Therefore
- a number very close to one is used instead.
- -------------------------------------------------------------------*/
- if (Math.abs(arg) > 0.999999999999) {
- arg = 0.999999999999;
- }
- theta = Math.asin(arg);
- var lon = adjust_lon(this.long0 + (p.x / (0.900316316158 * this.a * Math.cos(theta))));
- if (lon < (-Math.PI)) {
- lon = -Math.PI;
- }
- if (lon > Math.PI) {
- lon = Math.PI;
- }
- arg = (2 * theta + Math.sin(2 * theta)) / Math.PI;
- if (Math.abs(arg) > 1) {
- arg = 1;
- }
- var lat = Math.asin(arg);
-
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["Mollweide", "moll"];
-
-},{"../common/adjust_lon":5}],57:[function(require,module,exports){
-var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
-/*
- reference
- Department of Land and Survey Technical Circular 1973/32
- http://www.linz.govt.nz/docs/miscellaneous/nz-map-definition.pdf
- OSG Technical Report 4.1
- http://www.linz.govt.nz/docs/miscellaneous/nzmg.pdf
- */
-
-/**
- * iterations: Number of iterations to refine inverse transform.
- * 0 -> km accuracy
- * 1 -> m accuracy -- suitable for most mapping applications
- * 2 -> mm accuracy
- */
-exports.iterations = 1;
-
-exports.init = function() {
- this.A = [];
- this.A[1] = 0.6399175073;
- this.A[2] = -0.1358797613;
- this.A[3] = 0.063294409;
- this.A[4] = -0.02526853;
- this.A[5] = 0.0117879;
- this.A[6] = -0.0055161;
- this.A[7] = 0.0026906;
- this.A[8] = -0.001333;
- this.A[9] = 0.00067;
- this.A[10] = -0.00034;
-
- this.B_re = [];
- this.B_im = [];
- this.B_re[1] = 0.7557853228;
- this.B_im[1] = 0;
- this.B_re[2] = 0.249204646;
- this.B_im[2] = 0.003371507;
- this.B_re[3] = -0.001541739;
- this.B_im[3] = 0.041058560;
- this.B_re[4] = -0.10162907;
- this.B_im[4] = 0.01727609;
- this.B_re[5] = -0.26623489;
- this.B_im[5] = -0.36249218;
- this.B_re[6] = -0.6870983;
- this.B_im[6] = -1.1651967;
-
- this.C_re = [];
- this.C_im = [];
- this.C_re[1] = 1.3231270439;
- this.C_im[1] = 0;
- this.C_re[2] = -0.577245789;
- this.C_im[2] = -0.007809598;
- this.C_re[3] = 0.508307513;
- this.C_im[3] = -0.112208952;
- this.C_re[4] = -0.15094762;
- this.C_im[4] = 0.18200602;
- this.C_re[5] = 1.01418179;
- this.C_im[5] = 1.64497696;
- this.C_re[6] = 1.9660549;
- this.C_im[6] = 2.5127645;
-
- this.D = [];
- this.D[1] = 1.5627014243;
- this.D[2] = 0.5185406398;
- this.D[3] = -0.03333098;
- this.D[4] = -0.1052906;
- this.D[5] = -0.0368594;
- this.D[6] = 0.007317;
- this.D[7] = 0.01220;
- this.D[8] = 0.00394;
- this.D[9] = -0.0013;
-};
-
-/**
- New Zealand Map Grid Forward - long/lat to x/y
- long/lat in radians
- */
-exports.forward = function(p) {
- var n;
- var lon = p.x;
- var lat = p.y;
-
- var delta_lat = lat - this.lat0;
- var delta_lon = lon - this.long0;
-
- // 1. Calculate d_phi and d_psi ... // and d_lambda
- // For this algorithm, delta_latitude is in seconds of arc x 10-5, so we need to scale to those units. Longitude is radians.
- var d_phi = delta_lat / SEC_TO_RAD * 1E-5;
- var d_lambda = delta_lon;
- var d_phi_n = 1; // d_phi^0
-
- var d_psi = 0;
- for (n = 1; n <= 10; n++) {
- d_phi_n = d_phi_n * d_phi;
- d_psi = d_psi + this.A[n] * d_phi_n;
- }
-
- // 2. Calculate theta
- var th_re = d_psi;
- var th_im = d_lambda;
-
- // 3. Calculate z
- var th_n_re = 1;
- var th_n_im = 0; // theta^0
- var th_n_re1;
- var th_n_im1;
-
- var z_re = 0;
- var z_im = 0;
- for (n = 1; n <= 6; n++) {
- th_n_re1 = th_n_re * th_re - th_n_im * th_im;
- th_n_im1 = th_n_im * th_re + th_n_re * th_im;
- th_n_re = th_n_re1;
- th_n_im = th_n_im1;
- z_re = z_re + this.B_re[n] * th_n_re - this.B_im[n] * th_n_im;
- z_im = z_im + this.B_im[n] * th_n_re + this.B_re[n] * th_n_im;
- }
-
- // 4. Calculate easting and northing
- p.x = (z_im * this.a) + this.x0;
- p.y = (z_re * this.a) + this.y0;
-
- return p;
-};
-
-
-/**
- New Zealand Map Grid Inverse - x/y to long/lat
- */
-exports.inverse = function(p) {
- var n;
- var x = p.x;
- var y = p.y;
-
- var delta_x = x - this.x0;
- var delta_y = y - this.y0;
-
- // 1. Calculate z
- var z_re = delta_y / this.a;
- var z_im = delta_x / this.a;
-
- // 2a. Calculate theta - first approximation gives km accuracy
- var z_n_re = 1;
- var z_n_im = 0; // z^0
- var z_n_re1;
- var z_n_im1;
-
- var th_re = 0;
- var th_im = 0;
- for (n = 1; n <= 6; n++) {
- z_n_re1 = z_n_re * z_re - z_n_im * z_im;
- z_n_im1 = z_n_im * z_re + z_n_re * z_im;
- z_n_re = z_n_re1;
- z_n_im = z_n_im1;
- th_re = th_re + this.C_re[n] * z_n_re - this.C_im[n] * z_n_im;
- th_im = th_im + this.C_im[n] * z_n_re + this.C_re[n] * z_n_im;
- }
-
- // 2b. Iterate to refine the accuracy of the calculation
- // 0 iterations gives km accuracy
- // 1 iteration gives m accuracy -- good enough for most mapping applications
- // 2 iterations bives mm accuracy
- for (var i = 0; i < this.iterations; i++) {
- var th_n_re = th_re;
- var th_n_im = th_im;
- var th_n_re1;
- var th_n_im1;
-
- var num_re = z_re;
- var num_im = z_im;
- for (n = 2; n <= 6; n++) {
- th_n_re1 = th_n_re * th_re - th_n_im * th_im;
- th_n_im1 = th_n_im * th_re + th_n_re * th_im;
- th_n_re = th_n_re1;
- th_n_im = th_n_im1;
- num_re = num_re + (n - 1) * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
- num_im = num_im + (n - 1) * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
- }
-
- th_n_re = 1;
- th_n_im = 0;
- var den_re = this.B_re[1];
- var den_im = this.B_im[1];
- for (n = 2; n <= 6; n++) {
- th_n_re1 = th_n_re * th_re - th_n_im * th_im;
- th_n_im1 = th_n_im * th_re + th_n_re * th_im;
- th_n_re = th_n_re1;
- th_n_im = th_n_im1;
- den_re = den_re + n * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
- den_im = den_im + n * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
- }
-
- // Complex division
- var den2 = den_re * den_re + den_im * den_im;
- th_re = (num_re * den_re + num_im * den_im) / den2;
- th_im = (num_im * den_re - num_re * den_im) / den2;
- }
-
- // 3. Calculate d_phi ... // and d_lambda
- var d_psi = th_re;
- var d_lambda = th_im;
- var d_psi_n = 1; // d_psi^0
-
- var d_phi = 0;
- for (n = 1; n <= 9; n++) {
- d_psi_n = d_psi_n * d_psi;
- d_phi = d_phi + this.D[n] * d_psi_n;
- }
-
- // 4. Calculate latitude and longitude
- // d_phi is calcuated in second of arc * 10^-5, so we need to scale back to radians. d_lambda is in radians.
- var lat = this.lat0 + (d_phi * SEC_TO_RAD * 1E5);
- var lon = this.long0 + d_lambda;
-
- p.x = lon;
- p.y = lat;
-
- return p;
-};
-exports.names = ["New_Zealand_Map_Grid", "nzmg"];
-},{}],58:[function(require,module,exports){
-var tsfnz = require('../common/tsfnz');
-var adjust_lon = require('../common/adjust_lon');
-var phi2z = require('../common/phi2z');
-var HALF_PI = Math.PI/2;
-var FORTPI = Math.PI/4;
-var EPSLN = 1.0e-10;
-
-/* Initialize the Oblique Mercator projection
- ------------------------------------------*/
-exports.init = function() {
- this.no_off = this.no_off || false;
- this.no_rot = this.no_rot || false;
-
- if (isNaN(this.k0)) {
- this.k0 = 1;
- }
- var sinlat = Math.sin(this.lat0);
- var coslat = Math.cos(this.lat0);
- var con = this.e * sinlat;
-
- this.bl = Math.sqrt(1 + this.es / (1 - this.es) * Math.pow(coslat, 4));
- this.al = this.a * this.bl * this.k0 * Math.sqrt(1 - this.es) / (1 - con * con);
- var t0 = tsfnz(this.e, this.lat0, sinlat);
- var dl = this.bl / coslat * Math.sqrt((1 - this.es) / (1 - con * con));
- if (dl * dl < 1) {
- dl = 1;
- }
- var fl;
- var gl;
- if (!isNaN(this.longc)) {
- //Central point and azimuth method
-
- if (this.lat0 >= 0) {
- fl = dl + Math.sqrt(dl * dl - 1);
- }
- else {
- fl = dl - Math.sqrt(dl * dl - 1);
- }
- this.el = fl * Math.pow(t0, this.bl);
- gl = 0.5 * (fl - 1 / fl);
- this.gamma0 = Math.asin(Math.sin(this.alpha) / dl);
- this.long0 = this.longc - Math.asin(gl * Math.tan(this.gamma0)) / this.bl;
-
- }
- else {
- //2 points method
- var t1 = tsfnz(this.e, this.lat1, Math.sin(this.lat1));
- var t2 = tsfnz(this.e, this.lat2, Math.sin(this.lat2));
- if (this.lat0 >= 0) {
- this.el = (dl + Math.sqrt(dl * dl - 1)) * Math.pow(t0, this.bl);
- }
- else {
- this.el = (dl - Math.sqrt(dl * dl - 1)) * Math.pow(t0, this.bl);
- }
- var hl = Math.pow(t1, this.bl);
- var ll = Math.pow(t2, this.bl);
- fl = this.el / hl;
- gl = 0.5 * (fl - 1 / fl);
- var jl = (this.el * this.el - ll * hl) / (this.el * this.el + ll * hl);
- var pl = (ll - hl) / (ll + hl);
- var dlon12 = adjust_lon(this.long1 - this.long2);
- this.long0 = 0.5 * (this.long1 + this.long2) - Math.atan(jl * Math.tan(0.5 * this.bl * (dlon12)) / pl) / this.bl;
- this.long0 = adjust_lon(this.long0);
- var dlon10 = adjust_lon(this.long1 - this.long0);
- this.gamma0 = Math.atan(Math.sin(this.bl * (dlon10)) / gl);
- this.alpha = Math.asin(dl * Math.sin(this.gamma0));
- }
-
- if (this.no_off) {
- this.uc = 0;
- }
- else {
- if (this.lat0 >= 0) {
- this.uc = this.al / this.bl * Math.atan2(Math.sqrt(dl * dl - 1), Math.cos(this.alpha));
- }
- else {
- this.uc = -1 * this.al / this.bl * Math.atan2(Math.sqrt(dl * dl - 1), Math.cos(this.alpha));
- }
- }
-
-};
-
-
-/* Oblique Mercator forward equations--mapping lat,long to x,y
- ----------------------------------------------------------*/
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
- var dlon = adjust_lon(lon - this.long0);
- var us, vs;
- var con;
- if (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN) {
- if (lat > 0) {
- con = -1;
- }
- else {
- con = 1;
- }
- vs = this.al / this.bl * Math.log(Math.tan(FORTPI + con * this.gamma0 * 0.5));
- us = -1 * con * HALF_PI * this.al / this.bl;
- }
- else {
- var t = tsfnz(this.e, lat, Math.sin(lat));
- var ql = this.el / Math.pow(t, this.bl);
- var sl = 0.5 * (ql - 1 / ql);
- var tl = 0.5 * (ql + 1 / ql);
- var vl = Math.sin(this.bl * (dlon));
- var ul = (sl * Math.sin(this.gamma0) - vl * Math.cos(this.gamma0)) / tl;
- if (Math.abs(Math.abs(ul) - 1) <= EPSLN) {
- vs = Number.POSITIVE_INFINITY;
- }
- else {
- vs = 0.5 * this.al * Math.log((1 - ul) / (1 + ul)) / this.bl;
- }
- if (Math.abs(Math.cos(this.bl * (dlon))) <= EPSLN) {
- us = this.al * this.bl * (dlon);
- }
- else {
- us = this.al * Math.atan2(sl * Math.cos(this.gamma0) + vl * Math.sin(this.gamma0), Math.cos(this.bl * dlon)) / this.bl;
- }
- }
-
- if (this.no_rot) {
- p.x = this.x0 + us;
- p.y = this.y0 + vs;
- }
- else {
-
- us -= this.uc;
- p.x = this.x0 + vs * Math.cos(this.alpha) + us * Math.sin(this.alpha);
- p.y = this.y0 + us * Math.cos(this.alpha) - vs * Math.sin(this.alpha);
- }
- return p;
-};
-
-exports.inverse = function(p) {
- var us, vs;
- if (this.no_rot) {
- vs = p.y - this.y0;
- us = p.x - this.x0;
- }
- else {
- vs = (p.x - this.x0) * Math.cos(this.alpha) - (p.y - this.y0) * Math.sin(this.alpha);
- us = (p.y - this.y0) * Math.cos(this.alpha) + (p.x - this.x0) * Math.sin(this.alpha);
- us += this.uc;
- }
- var qp = Math.exp(-1 * this.bl * vs / this.al);
- var sp = 0.5 * (qp - 1 / qp);
- var tp = 0.5 * (qp + 1 / qp);
- var vp = Math.sin(this.bl * us / this.al);
- var up = (vp * Math.cos(this.gamma0) + sp * Math.sin(this.gamma0)) / tp;
- var ts = Math.pow(this.el / Math.sqrt((1 + up) / (1 - up)), 1 / this.bl);
- if (Math.abs(up - 1) < EPSLN) {
- p.x = this.long0;
- p.y = HALF_PI;
- }
- else if (Math.abs(up + 1) < EPSLN) {
- p.x = this.long0;
- p.y = -1 * HALF_PI;
- }
- else {
- p.y = phi2z(this.e, ts);
- p.x = adjust_lon(this.long0 - Math.atan2(sp * Math.cos(this.gamma0) - vp * Math.sin(this.gamma0), Math.cos(this.bl * us / this.al)) / this.bl);
- }
- return p;
-};
-
-exports.names = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "omerc"];
-},{"../common/adjust_lon":5,"../common/phi2z":17,"../common/tsfnz":25}],59:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-var EPSLN = 1.0e-10;
-var asinz = require('../common/asinz');
-var HALF_PI = Math.PI/2;
-exports.init = function() {
- //double temp; /* temporary variable */
-
- /* Place parameters in static storage for common use
- -------------------------------------------------*/
- this.sin_p14 = Math.sin(this.lat0);
- this.cos_p14 = Math.cos(this.lat0);
-};
-
-
-/* Orthographic forward equations--mapping lat,long to x,y
- ---------------------------------------------------*/
-exports.forward = function(p) {
- var sinphi, cosphi; /* sin and cos value */
- var dlon; /* delta longitude value */
- var coslon; /* cos of longitude */
- var ksp; /* scale factor */
- var g, x, y;
- var lon = p.x;
- var lat = p.y;
- /* Forward equations
- -----------------*/
- dlon = adjust_lon(lon - this.long0);
-
- sinphi = Math.sin(lat);
- cosphi = Math.cos(lat);
-
- coslon = Math.cos(dlon);
- g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
- ksp = 1;
- if ((g > 0) || (Math.abs(g) <= EPSLN)) {
- x = this.a * ksp * cosphi * Math.sin(dlon);
- y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
- }
- p.x = x;
- p.y = y;
- return p;
-};
-
-
-exports.inverse = function(p) {
- var rh; /* height above ellipsoid */
- var z; /* angle */
- var sinz, cosz; /* sin of z and cos of z */
- var con;
- var lon, lat;
- /* Inverse equations
- -----------------*/
- p.x -= this.x0;
- p.y -= this.y0;
- rh = Math.sqrt(p.x * p.x + p.y * p.y);
- z = asinz(rh / this.a);
-
- sinz = Math.sin(z);
- cosz = Math.cos(z);
-
- lon = this.long0;
- if (Math.abs(rh) <= EPSLN) {
- lat = this.lat0;
- p.x = lon;
- p.y = lat;
- return p;
- }
- lat = asinz(cosz * this.sin_p14 + (p.y * sinz * this.cos_p14) / rh);
- con = Math.abs(this.lat0) - HALF_PI;
- if (Math.abs(con) <= EPSLN) {
- if (this.lat0 >= 0) {
- lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
- }
- else {
- lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
- }
- p.x = lon;
- p.y = lat;
- return p;
- }
- lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz), rh * this.cos_p14 * cosz - p.y * this.sin_p14 * sinz));
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["ortho"];
-
-},{"../common/adjust_lon":5,"../common/asinz":7}],60:[function(require,module,exports){
-var e0fn = require('../common/e0fn');
-var e1fn = require('../common/e1fn');
-var e2fn = require('../common/e2fn');
-var e3fn = require('../common/e3fn');
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-var mlfn = require('../common/mlfn');
-var EPSLN = 1.0e-10;
-var gN = require('../common/gN');
-var MAX_ITER = 20;
-exports.init = function() {
- /* Place parameters in static storage for common use
- -------------------------------------------------*/
- this.temp = this.b / this.a;
- this.es = 1 - Math.pow(this.temp, 2); // devait etre dans tmerc.js mais n y est pas donc je commente sinon retour de valeurs nulles
- this.e = Math.sqrt(this.es);
- 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); //si que des zeros le calcul ne se fait pas
-};
-
-
-/* Polyconic forward equations--mapping lat,long to x,y
- ---------------------------------------------------*/
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
- var x, y, el;
- var dlon = adjust_lon(lon - this.long0);
- el = dlon * Math.sin(lat);
- if (this.sphere) {
- if (Math.abs(lat) <= EPSLN) {
- x = this.a * dlon;
- y = -1 * this.a * this.lat0;
- }
- else {
- x = this.a * Math.sin(el) / Math.tan(lat);
- y = this.a * (adjust_lat(lat - this.lat0) + (1 - Math.cos(el)) / Math.tan(lat));
- }
- }
- else {
- if (Math.abs(lat) <= EPSLN) {
- x = this.a * dlon;
- y = -1 * this.ml0;
- }
- else {
- var nl = gN(this.a, this.e, Math.sin(lat)) / Math.tan(lat);
- x = nl * Math.sin(el);
- y = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, lat) - this.ml0 + nl * (1 - Math.cos(el));
- }
-
- }
- p.x = x + this.x0;
- p.y = y + this.y0;
- return p;
-};
-
-
-/* Inverse equations
- -----------------*/
-exports.inverse = function(p) {
- var lon, lat, x, y, i;
- var al, bl;
- var phi, dphi;
- x = p.x - this.x0;
- y = p.y - this.y0;
-
- if (this.sphere) {
- if (Math.abs(y + this.a * this.lat0) <= EPSLN) {
- lon = adjust_lon(x / this.a + this.long0);
- lat = 0;
- }
- else {
- al = this.lat0 + y / this.a;
- bl = x * x / this.a / this.a + al * al;
- phi = al;
- var tanphi;
- for (i = MAX_ITER; i; --i) {
- tanphi = Math.tan(phi);
- dphi = -1 * (al * (phi * tanphi + 1) - phi - 0.5 * (phi * phi + bl) * tanphi) / ((phi - al) / tanphi - 1);
- phi += dphi;
- if (Math.abs(dphi) <= EPSLN) {
- lat = phi;
- break;
- }
- }
- lon = adjust_lon(this.long0 + (Math.asin(x * Math.tan(phi) / this.a)) / Math.sin(lat));
- }
- }
- else {
- if (Math.abs(y + this.ml0) <= EPSLN) {
- lat = 0;
- lon = adjust_lon(this.long0 + x / this.a);
- }
- else {
-
- al = (this.ml0 + y) / this.a;
- bl = x * x / this.a / this.a + al * al;
- phi = al;
- var cl, mln, mlnp, ma;
- var con;
- for (i = MAX_ITER; i; --i) {
- con = this.e * Math.sin(phi);
- cl = Math.sqrt(1 - con * con) * Math.tan(phi);
- mln = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
- mlnp = this.e0 - 2 * this.e1 * Math.cos(2 * phi) + 4 * this.e2 * Math.cos(4 * phi) - 6 * this.e3 * Math.cos(6 * phi);
- ma = mln / this.a;
- dphi = (al * (cl * ma + 1) - ma - 0.5 * cl * (ma * ma + bl)) / (this.es * Math.sin(2 * phi) * (ma * ma + bl - 2 * al * ma) / (4 * cl) + (al - ma) * (cl * mlnp - 2 / Math.sin(2 * phi)) - mlnp);
- phi -= dphi;
- if (Math.abs(dphi) <= EPSLN) {
- lat = phi;
- break;
- }
- }
-
- //lat=phi4z(this.e,this.e0,this.e1,this.e2,this.e3,al,bl,0,0);
- cl = Math.sqrt(1 - this.es * Math.pow(Math.sin(lat), 2)) * Math.tan(lat);
- lon = adjust_lon(this.long0 + Math.asin(x * cl / this.a) / Math.sin(lat));
- }
- }
-
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["Polyconic", "poly"];
-},{"../common/adjust_lat":4,"../common/adjust_lon":5,"../common/e0fn":8,"../common/e1fn":9,"../common/e2fn":10,"../common/e3fn":11,"../common/gN":12,"../common/mlfn":15}],61:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-var pj_enfn = require('../common/pj_enfn');
-var MAX_ITER = 20;
-var pj_mlfn = require('../common/pj_mlfn');
-var pj_inv_mlfn = require('../common/pj_inv_mlfn');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var asinz = require('../common/asinz');
-exports.init = function() {
- /* Place parameters in static storage for common use
- -------------------------------------------------*/
-
-
- if (!this.sphere) {
- this.en = pj_enfn(this.es);
- }
- else {
- this.n = 1;
- this.m = 0;
- this.es = 0;
- this.C_y = Math.sqrt((this.m + 1) / this.n);
- this.C_x = this.C_y / (this.m + 1);
- }
-
-};
-
-/* Sinusoidal forward equations--mapping lat,long to x,y
- -----------------------------------------------------*/
-exports.forward = function(p) {
- var x, y;
- var lon = p.x;
- var lat = p.y;
- /* Forward equations
- -----------------*/
- lon = adjust_lon(lon - this.long0);
-
- if (this.sphere) {
- if (!this.m) {
- lat = this.n !== 1 ? Math.asin(this.n * Math.sin(lat)) : lat;
- }
- else {
- var k = this.n * Math.sin(lat);
- for (var i = MAX_ITER; i; --i) {
- var V = (this.m * lat + Math.sin(lat) - k) / (this.m + Math.cos(lat));
- lat -= V;
- if (Math.abs(V) < EPSLN) {
- break;
- }
- }
- }
- x = this.a * this.C_x * lon * (this.m + Math.cos(lat));
- y = this.a * this.C_y * lat;
-
- }
- else {
-
- var s = Math.sin(lat);
- var c = Math.cos(lat);
- y = this.a * pj_mlfn(lat, s, c, this.en);
- x = this.a * lon * c / Math.sqrt(1 - this.es * s * s);
- }
-
- p.x = x;
- p.y = y;
- return p;
-};
-
-exports.inverse = function(p) {
- var lat, temp, lon, s;
-
- p.x -= this.x0;
- lon = p.x / this.a;
- p.y -= this.y0;
- lat = p.y / this.a;
-
- if (this.sphere) {
- lat /= this.C_y;
- lon = lon / (this.C_x * (this.m + Math.cos(lat)));
- if (this.m) {
- lat = asinz((this.m * lat + Math.sin(lat)) / this.n);
- }
- else if (this.n !== 1) {
- lat = asinz(Math.sin(lat) / this.n);
- }
- lon = adjust_lon(lon + this.long0);
- lat = adjust_lat(lat);
- }
- else {
- lat = pj_inv_mlfn(p.y / this.a, this.es, this.en);
- s = Math.abs(lat);
- if (s < HALF_PI) {
- s = Math.sin(lat);
- temp = this.long0 + p.x * Math.sqrt(1 - this.es * s * s) / (this.a * Math.cos(lat));
- //temp = this.long0 + p.x / (this.a * Math.cos(lat));
- lon = adjust_lon(temp);
- }
- else if ((s - EPSLN) < HALF_PI) {
- lon = this.long0;
- }
- }
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["Sinusoidal", "sinu"];
-},{"../common/adjust_lat":4,"../common/adjust_lon":5,"../common/asinz":7,"../common/pj_enfn":18,"../common/pj_inv_mlfn":19,"../common/pj_mlfn":20}],62:[function(require,module,exports){
-/*
- references:
- Formules et constantes pour le Calcul pour la
- projection cylindrique conforme à axe oblique et pour la transformation entre
- des systèmes de référence.
- http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf
- */
-exports.init = function() {
- var phy0 = this.lat0;
- this.lambda0 = this.long0;
- var sinPhy0 = Math.sin(phy0);
- var semiMajorAxis = this.a;
- var invF = this.rf;
- var flattening = 1 / invF;
- var e2 = 2 * flattening - Math.pow(flattening, 2);
- var e = this.e = Math.sqrt(e2);
- this.R = this.k0 * semiMajorAxis * Math.sqrt(1 - e2) / (1 - e2 * Math.pow(sinPhy0, 2));
- this.alpha = Math.sqrt(1 + e2 / (1 - e2) * Math.pow(Math.cos(phy0), 4));
- this.b0 = Math.asin(sinPhy0 / this.alpha);
- var k1 = Math.log(Math.tan(Math.PI / 4 + this.b0 / 2));
- var k2 = Math.log(Math.tan(Math.PI / 4 + phy0 / 2));
- var k3 = Math.log((1 + e * sinPhy0) / (1 - e * sinPhy0));
- this.K = k1 - this.alpha * k2 + this.alpha * e / 2 * k3;
-};
-
-
-exports.forward = function(p) {
- var Sa1 = Math.log(Math.tan(Math.PI / 4 - p.y / 2));
- var Sa2 = this.e / 2 * Math.log((1 + this.e * Math.sin(p.y)) / (1 - this.e * Math.sin(p.y)));
- var S = -this.alpha * (Sa1 + Sa2) + this.K;
-
- // spheric latitude
- var b = 2 * (Math.atan(Math.exp(S)) - Math.PI / 4);
-
- // spheric longitude
- var I = this.alpha * (p.x - this.lambda0);
-
- // psoeudo equatorial rotation
- var rotI = Math.atan(Math.sin(I) / (Math.sin(this.b0) * Math.tan(b) + Math.cos(this.b0) * Math.cos(I)));
-
- var rotB = Math.asin(Math.cos(this.b0) * Math.sin(b) - Math.sin(this.b0) * Math.cos(b) * Math.cos(I));
-
- p.y = this.R / 2 * Math.log((1 + Math.sin(rotB)) / (1 - Math.sin(rotB))) + this.y0;
- p.x = this.R * rotI + this.x0;
- return p;
-};
-
-exports.inverse = function(p) {
- var Y = p.x - this.x0;
- var X = p.y - this.y0;
-
- var rotI = Y / this.R;
- var rotB = 2 * (Math.atan(Math.exp(X / this.R)) - Math.PI / 4);
-
- var b = Math.asin(Math.cos(this.b0) * Math.sin(rotB) + Math.sin(this.b0) * Math.cos(rotB) * Math.cos(rotI));
- var I = Math.atan(Math.sin(rotI) / (Math.cos(this.b0) * Math.cos(rotI) - Math.sin(this.b0) * Math.tan(rotB)));
-
- var lambda = this.lambda0 + I / this.alpha;
-
- var S = 0;
- var phy = b;
- var prevPhy = -1000;
- var iteration = 0;
- while (Math.abs(phy - prevPhy) > 0.0000001) {
- if (++iteration > 20) {
- //...reportError("omercFwdInfinity");
- return;
- }
- //S = Math.log(Math.tan(Math.PI / 4 + phy / 2));
- S = 1 / this.alpha * (Math.log(Math.tan(Math.PI / 4 + b / 2)) - this.K) + this.e * Math.log(Math.tan(Math.PI / 4 + Math.asin(this.e * Math.sin(phy)) / 2));
- prevPhy = phy;
- phy = 2 * Math.atan(Math.exp(S)) - Math.PI / 2;
- }
-
- p.x = lambda;
- p.y = phy;
- return p;
-};
-
-exports.names = ["somerc"];
-
-},{}],63:[function(require,module,exports){
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var sign = require('../common/sign');
-var msfnz = require('../common/msfnz');
-var tsfnz = require('../common/tsfnz');
-var phi2z = require('../common/phi2z');
-var adjust_lon = require('../common/adjust_lon');
-exports.ssfn_ = function(phit, sinphi, eccen) {
- sinphi *= eccen;
- return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen));
-};
-
-exports.init = function() {
- this.coslat0 = Math.cos(this.lat0);
- this.sinlat0 = Math.sin(this.lat0);
- if (this.sphere) {
- if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
- this.k0 = 0.5 * (1 + sign(this.lat0) * Math.sin(this.lat_ts));
- }
- }
- else {
- if (Math.abs(this.coslat0) <= EPSLN) {
- if (this.lat0 > 0) {
- //North pole
- //trace('stere:north pole');
- this.con = 1;
- }
- else {
- //South pole
- //trace('stere:south pole');
- this.con = -1;
- }
- }
- this.cons = Math.sqrt(Math.pow(1 + this.e, 1 + this.e) * Math.pow(1 - this.e, 1 - this.e));
- if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
- this.k0 = 0.5 * this.cons * msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts)) / tsfnz(this.e, this.con * this.lat_ts, this.con * Math.sin(this.lat_ts));
- }
- this.ms1 = msfnz(this.e, this.sinlat0, this.coslat0);
- this.X0 = 2 * Math.atan(this.ssfn_(this.lat0, this.sinlat0, this.e)) - HALF_PI;
- this.cosX0 = Math.cos(this.X0);
- this.sinX0 = Math.sin(this.X0);
- }
-};
-
-// Stereographic forward equations--mapping lat,long to x,y
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
- var sinlat = Math.sin(lat);
- var coslat = Math.cos(lat);
- var A, X, sinX, cosX, ts, rh;
- var dlon = adjust_lon(lon - this.long0);
-
- if (Math.abs(Math.abs(lon - this.long0) - Math.PI) <= EPSLN && Math.abs(lat + this.lat0) <= EPSLN) {
- //case of the origine point
- //trace('stere:this is the origin point');
- p.x = NaN;
- p.y = NaN;
- return p;
- }
- if (this.sphere) {
- //trace('stere:sphere case');
- A = 2 * this.k0 / (1 + 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 {
- X = 2 * Math.atan(this.ssfn_(lat, sinlat, this.e)) - HALF_PI;
- cosX = Math.cos(X);
- sinX = Math.sin(X);
- if (Math.abs(this.coslat0) <= EPSLN) {
- ts = tsfnz(this.e, lat * this.con, this.con * sinlat);
- rh = 2 * 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) < EPSLN) {
- //Eq
- //trace('stere:equateur');
- A = 2 * this.a * this.k0 / (1 + cosX * Math.cos(dlon));
- p.y = A * sinX;
- }
- else {
- //other case
- //trace('stere:normal case');
- A = 2 * this.a * this.k0 * this.ms1 / (this.cosX0 * (1 + 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;
-};
-
-
-//* Stereographic inverse equations--mapping x,y to lat/long
-exports.inverse = function(p) {
- p.x -= this.x0;
- p.y -= this.y0;
- 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));
- lon = this.long0;
- lat = this.lat0;
- if (rh <= EPSLN) {
- p.x = lon;
- p.y = lat;
- return p;
- }
- lat = Math.asin(Math.cos(c) * this.sinlat0 + p.y * Math.sin(c) * this.coslat0 / rh);
- if (Math.abs(this.coslat0) < EPSLN) {
- if (this.lat0 > 0) {
- lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
- }
- else {
- lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
- }
- }
- else {
- lon = 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 {
- if (Math.abs(this.coslat0) <= EPSLN) {
- if (rh <= 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;
- ts = rh * this.cons / (2 * this.a * this.k0);
- lat = this.con * phi2z(this.e, ts);
- lon = this.con * adjust_lon(this.con * this.long0 + Math.atan2(p.x, - 1 * p.y));
- }
- else {
- ce = 2 * Math.atan(rh * this.cosX0 / (2 * this.a * this.k0 * this.ms1));
- lon = this.long0;
- if (rh <= EPSLN) {
- Chi = this.X0;
- }
- else {
- Chi = Math.asin(Math.cos(ce) * this.sinX0 + p.y * Math.sin(ce) * this.cosX0 / rh);
- lon = 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 * phi2z(this.e, Math.tan(0.5 * (HALF_PI + Chi)));
- }
- }
- p.x = lon;
- p.y = lat;
-
- //trace(p.toString());
- return p;
-
-};
-exports.names = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)"];
-
-},{"../common/adjust_lon":5,"../common/msfnz":16,"../common/phi2z":17,"../common/sign":22,"../common/tsfnz":25}],64:[function(require,module,exports){
-var gauss = require('./gauss');
-var adjust_lon = require('../common/adjust_lon');
-exports.init = function() {
- gauss.init.apply(this);
- if (!this.rc) {
- return;
- }
- this.sinc0 = Math.sin(this.phic0);
- this.cosc0 = Math.cos(this.phic0);
- this.R2 = 2 * this.rc;
- if (!this.title) {
- this.title = "Oblique Stereographic Alternative";
- }
-};
-
-exports.forward = function(p) {
- var sinc, cosc, cosl, k;
- p.x = adjust_lon(p.x - this.long0);
- gauss.forward.apply(this, [p]);
- sinc = Math.sin(p.y);
- cosc = Math.cos(p.y);
- cosl = Math.cos(p.x);
- k = this.k0 * this.R2 / (1 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
- p.x = k * cosc * Math.sin(p.x);
- p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
- p.x = this.a * p.x + this.x0;
- p.y = this.a * p.y + this.y0;
- return p;
-};
-
-exports.inverse = function(p) {
- var sinc, cosc, lon, lat, rho;
- p.x = (p.x - this.x0) / this.a;
- p.y = (p.y - this.y0) / this.a;
-
- p.x /= this.k0;
- p.y /= this.k0;
- if ((rho = Math.sqrt(p.x * p.x + p.y * p.y))) {
- var c = 2 * Math.atan2(rho, this.R2);
- sinc = Math.sin(c);
- cosc = Math.cos(c);
- lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
- lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
- }
- else {
- lat = this.phic0;
- lon = 0;
- }
-
- p.x = lon;
- p.y = lat;
- gauss.inverse.apply(this, [p]);
- p.x = adjust_lon(p.x + this.long0);
- return p;
-};
-
-exports.names = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea","Oblique Stereographic Alternative"];
-
-},{"../common/adjust_lon":5,"./gauss":48}],65:[function(require,module,exports){
-// 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 EPSLN = 1.0e-10;
-var sign = require('../common/sign');
-
-exports.init = function() {
- 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);
- }
-};
-
-/**
- Transverse Mercator Forward - long/lat to x/y
- long/lat in radians
- */
-exports.forward = function(p) {
- var lon = p.x;
- var lat = p.y;
-
- var delta_lon = adjust_lon(lon - this.long0);
- var con;
- var x, y;
- var sin_phi = Math.sin(lat);
- var cos_phi = Math.cos(lat);
-
- if (!this.es) {
- var b = cos_phi * Math.sin(delta_lon);
-
- if ((Math.abs(Math.abs(b) - 1)) < EPSLN) {
- return (93);
- }
- else {
- 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) {
- y = -y;
- }
-
- y = this.a * this.k0 * (y - this.lat0) + this.y0;
- }
- }
- else {
- var al = cos_phi * delta_lon;
- var als = Math.pow(al, 2);
- var c = this.ep2 * Math.pow(cos_phi, 2);
- 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);
- al = al / Math.sqrt(con);
- var ml = pj_mlfn(lat, sin_phi, cos_phi, this.en);
-
- 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;
-};
-
-/**
- Transverse Mercator Inverse - x/y to long/lat
- */
-exports.inverse = function(p) {
- var con, phi;
- var lat, lon;
- var x = (p.x - this.x0) * (1 / this.a);
- var y = (p.y - this.y0) * (1 / this.a);
-
- if (!this.es) {
- var f = Math.exp(x / this.k0);
- var g = 0.5 * (f - 1 / f);
- var temp = this.lat0 + y / this.k0;
- var h = Math.cos(temp);
- 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 = 0;
- }
- else {
- lon = adjust_lon(Math.atan2(g, h) + this.long0);
- }
- }
- else { // ellipsoidal form
- con = this.ml0 + y / this.k0;
- phi = pj_inv_mlfn(con, this.es, this.en);
-
- if (Math.abs(phi) < HALF_PI) {
- var sin_phi = Math.sin(phi);
- var cos_phi = Math.cos(phi);
- var tan_phi = Math.abs(cos_phi) > EPSLN ? Math.tan(phi) : 0;
- var c = this.ep2 * Math.pow(cos_phi, 2);
- var cs = Math.pow(c, 2);
- var t = Math.pow(tan_phi, 2);
- var ts = Math.pow(t, 2);
- con = 1 - this.es * Math.pow(sin_phi, 2);
- var d = x * Math.sqrt(con) / this.k0;
- var ds = Math.pow(d, 2);
- 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 = 0;
- }
- }
-
- p.x = lon;
- p.y = lat;
-
- return p;
-};
-
-exports.names = ["Transverse_Mercator", "Transverse Mercator", "tmerc"];
-
-},{"../common/adjust_lon":5,"../common/pj_enfn":18,"../common/pj_inv_mlfn":19,"../common/pj_mlfn":20,"../common/sign":22}],66:[function(require,module,exports){
-var adjust_zone = require('../common/adjust_zone');
-var tmerc = require('./tmerc');
-
-exports.dependsOn = 'tmerc';
-
-exports.init = function() {
- var zone = adjust_zone(this.zone, this.long0);
- if (zone === undefined) {
- throw new Error('unknown utm zone');
- }
-
- this.lat0 = 0;
- this.long0 = (zone + 0.5) * Math.PI / 30 - Math.PI;
- this.x0 = 500000;
- this.y0 = this.utmSouth ? 10000000 : 0;
- this.k0 = 0.9996;
-
- tmerc.init.apply(this);
- this.forward = tmerc.forward;
- this.inverse = tmerc.inverse;
-};
-
-exports.names = ["Universal Transverse Mercator System", "utm"];
-
-},{"../common/adjust_zone":6,"./tmerc":65}],67:[function(require,module,exports){
-var adjust_lon = require('../common/adjust_lon');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var asinz = require('../common/asinz');
-/* Initialize the Van Der Grinten projection
- ----------------------------------------*/
-exports.init = function() {
- //this.R = 6370997; //Radius of earth
- this.R = this.a;
-};
-
-exports.forward = function(p) {
-
- var lon = p.x;
- var lat = p.y;
-
- /* Forward equations
- -----------------*/
- var dlon = adjust_lon(lon - this.long0);
- var x, y;
-
- if (Math.abs(lat) <= EPSLN) {
- x = this.x0 + this.R * dlon;
- y = this.y0;
- }
- var theta = asinz(2 * Math.abs(lat / Math.PI));
- if ((Math.abs(dlon) <= EPSLN) || (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN)) {
- x = this.x0;
- if (lat >= 0) {
- y = this.y0 + Math.PI * this.R * Math.tan(0.5 * theta);
- }
- else {
- y = this.y0 + Math.PI * this.R * -Math.tan(0.5 * theta);
- }
- // return(OK);
- }
- var al = 0.5 * Math.abs((Math.PI / dlon) - (dlon / Math.PI));
- var asq = al * al;
- var sinth = Math.sin(theta);
- var costh = Math.cos(theta);
-
- var g = costh / (sinth + costh - 1);
- var gsq = g * g;
- var m = g * (2 / sinth - 1);
- var msq = m * m;
- var con = Math.PI * this.R * (al * (g - msq) + Math.sqrt(asq * (g - msq) * (g - msq) - (msq + asq) * (gsq - msq))) / (msq + asq);
- if (dlon < 0) {
- con = -con;
- }
- x = this.x0 + con;
- //con = Math.abs(con / (Math.PI * this.R));
- var q = asq + g;
- con = Math.PI * this.R * (m * q - al * Math.sqrt((msq + asq) * (asq + 1) - q * q)) / (msq + asq);
- if (lat >= 0) {
- //y = this.y0 + Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
- y = this.y0 + con;
- }
- else {
- //y = this.y0 - Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
- y = this.y0 - con;
- }
- p.x = x;
- p.y = y;
- return p;
-};
-
-/* Van Der Grinten inverse equations--mapping x,y to lat/long
- ---------------------------------------------------------*/
-exports.inverse = function(p) {
- var lon, lat;
- var xx, yy, xys, c1, c2, c3;
- var a1;
- var m1;
- var con;
- var th1;
- var d;
-
- /* inverse equations
- -----------------*/
- p.x -= this.x0;
- p.y -= this.y0;
- con = Math.PI * this.R;
- xx = p.x / con;
- yy = p.y / con;
- xys = xx * xx + yy * yy;
- c1 = -Math.abs(yy) * (1 + xys);
- c2 = c1 - 2 * yy * yy + xx * xx;
- c3 = -2 * c1 + 1 + 2 * yy * yy + xys * xys;
- d = yy * yy / c3 + (2 * c2 * c2 * c2 / c3 / c3 / c3 - 9 * c1 * c2 / c3 / c3) / 27;
- a1 = (c1 - c2 * c2 / 3 / c3) / c3;
- m1 = 2 * Math.sqrt(-a1 / 3);
- con = ((3 * d) / a1) / m1;
- if (Math.abs(con) > 1) {
- if (con >= 0) {
- con = 1;
- }
- else {
- con = -1;
- }
- }
- th1 = Math.acos(con) / 3;
- if (p.y >= 0) {
- lat = (-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
- }
- else {
- lat = -(-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
- }
-
- if (Math.abs(xx) < EPSLN) {
- lon = this.long0;
- }
- else {
- lon = adjust_lon(this.long0 + Math.PI * (xys - 1 + Math.sqrt(1 + 2 * (xx * xx - yy * yy) + xys * xys)) / 2 / xx);
- }
-
- p.x = lon;
- p.y = lat;
- return p;
-};
-exports.names = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
-},{"../common/adjust_lon":5,"../common/asinz":7}],68:[function(require,module,exports){
-var D2R = 0.01745329251994329577;
-var R2D = 57.29577951308232088;
-var PJD_3PARAM = 1;
-var PJD_7PARAM = 2;
-var datum_transform = require('./datum_transform');
-var adjust_axis = require('./adjust_axis');
-var proj = require('./Proj');
-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) {
- var wgs84;
- if (Array.isArray(point)) {
- point = toPoint(point);
- }
-
- // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
- if (source.datum && dest.datum && checkNotWGS(source, dest)) {
- wgs84 = new proj('WGS84');
- point = transform(source, wgs84, point);
- source = wgs84;
- }
- // DGR, 2010/11/12
- 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: point.x * D2R,
- y: point.y * D2R
- };
- }
- else {
- if (source.to_meter) {
- point = {
- x: point.x * source.to_meter,
- y: point.y * source.to_meter
- };
- }
- point = source.inverse(point); // Convert Cartesian to longlat
- }
- // Adjust for the prime meridian if necessary
- if (source.from_greenwich) {
- point.x += source.from_greenwich;
- }
-
- // Convert datums if needed, and if possible.
- point = datum_transform(source.datum, dest.datum, point);
-
- // Adjust for the prime meridian if necessary
- if (dest.from_greenwich) {
- point = {
- x: point.x - dest.grom_greenwich,
- y: point.y
- };
- }
-
- if (dest.projName === 'longlat') {
- // convert radians to decimal degrees
- point = {
- x: point.x * R2D,
- y: point.y * R2D
- };
- } else { // else project
- point = dest.forward(point);
- if (dest.to_meter) {
- point = {
- x: point.x / dest.to_meter,
- y: point.y / dest.to_meter
- };
- }
- }
-
- // DGR, 2010/11/12
- if (dest.axis !== 'enu') {
- return adjust_axis(dest, true, point);
- }
-
- return point;
-};
-
-},{"./Proj":2,"./adjust_axis":3,"./common/toPoint":24,"./datum_transform":33}],69:[function(require,module,exports){
-var D2R = 0.01745329251994329577;
-var extend = require('./extend');
-
-function mapit(obj, key, v) {
- obj[key] = v.map(function(aa) {
- var o = {};
- sExpr(aa, o);
- return o;
- }).reduce(function(a, b) {
- return extend(a, b);
- }, {});
-}
-
-function sExpr(v, obj) {
- var key;
- if (!Array.isArray(v)) {
- obj[v] = true;
- return;
- }
- else {
- key = v.shift();
- if (key === 'PARAMETER') {
- key = v.shift();
- }
- if (v.length === 1) {
- if (Array.isArray(v[0])) {
- obj[key] = {};
- sExpr(v[0], obj[key]);
- }
- else {
- obj[key] = v[0];
- }
- }
- else if (!v.length) {
- obj[key] = true;
- }
- else if (key === 'TOWGS84') {
- obj[key] = v;
- }
- else {
- obj[key] = {};
- if (['UNIT', 'PRIMEM', 'VERT_DATUM'].indexOf(key) > -1) {
- obj[key] = {
- name: v[0].toLowerCase(),
- convert: v[1]
- };
- if (v.length === 3) {
- obj[key].auth = v[2];
- }
- }
- else if (key === 'SPHEROID') {
- obj[key] = {
- name: v[0],
- a: v[1],
- rf: v[2]
- };
- if (v.length === 4) {
- obj[key].auth = v[3];
- }
- }
- else if (['GEOGCS', 'GEOCCS', 'DATUM', 'VERT_CS', 'COMPD_CS', 'LOCAL_CS', 'FITTED_CS', 'LOCAL_DATUM'].indexOf(key) > -1) {
- v[0] = ['name', v[0]];
- mapit(obj, key, v);
- }
- else if (v.every(function(aa) {
- return Array.isArray(aa);
- })) {
- mapit(obj, key, v);
- }
- else {
- sExpr(v, obj[key]);
- }
- }
- }
-}
-
-function rename(obj, params) {
- var outName = params[0];
- var inName = params[1];
- if (!(outName in obj) && (inName in obj)) {
- obj[outName] = obj[inName];
- if (params.length === 3) {
- obj[outName] = params[2](obj[outName]);
- }
- }
-}
-
-function d2r(input) {
- return input * D2R;
-}
-
-function cleanWKT(wkt) {
- if (wkt.type === 'GEOGCS') {
- wkt.projName = 'longlat';
- }
- else if (wkt.type === 'LOCAL_CS') {
- wkt.projName = 'identity';
- wkt.local = true;
- }
- else {
- if (typeof wkt.PROJECTION === "object") {
- wkt.projName = Object.keys(wkt.PROJECTION)[0];
- }
- else {
- wkt.projName = wkt.PROJECTION;
- }
- }
- if (wkt.UNIT) {
- wkt.units = wkt.UNIT.name.toLowerCase();
- if (wkt.units === 'metre') {
- wkt.units = 'meter';
- }
- if (wkt.UNIT.convert) {
- if (wkt.type === 'GEOGCS') {
- if (wkt.DATUM && wkt.DATUM.SPHEROID) {
- wkt.to_meter = parseFloat(wkt.UNIT.convert, 10)*wkt.DATUM.SPHEROID.a;
- }
- } else {
- wkt.to_meter = parseFloat(wkt.UNIT.convert, 10);
- }
- }
- }
-
- if (wkt.GEOGCS) {
- //if(wkt.GEOGCS.PRIMEM&&wkt.GEOGCS.PRIMEM.convert){
- // wkt.from_greenwich=wkt.GEOGCS.PRIMEM.convert*D2R;
- //}
- if (wkt.GEOGCS.DATUM) {
- wkt.datumCode = wkt.GEOGCS.DATUM.name.toLowerCase();
- }
- else {
- wkt.datumCode = wkt.GEOGCS.name.toLowerCase();
- }
- if (wkt.datumCode.slice(0, 2) === 'd_') {
- wkt.datumCode = wkt.datumCode.slice(2);
- }
- if (wkt.datumCode === 'new_zealand_geodetic_datum_1949' || wkt.datumCode === 'new_zealand_1949') {
- wkt.datumCode = 'nzgd49';
- }
- if (wkt.datumCode === "wgs_1984") {
- if (wkt.PROJECTION === 'Mercator_Auxiliary_Sphere') {
- wkt.sphere = true;
- }
- wkt.datumCode = 'wgs84';
- }
- if (wkt.datumCode.slice(-6) === '_ferro') {
- wkt.datumCode = wkt.datumCode.slice(0, - 6);
- }
- if (wkt.datumCode.slice(-8) === '_jakarta') {
- wkt.datumCode = wkt.datumCode.slice(0, - 8);
- }
- if (~wkt.datumCode.indexOf('belge')) {
- wkt.datumCode = "rnb72";
- }
- if (wkt.GEOGCS.DATUM && wkt.GEOGCS.DATUM.SPHEROID) {
- wkt.ellps = wkt.GEOGCS.DATUM.SPHEROID.name.replace('_19', '').replace(/[Cc]larke\_18/, 'clrk');
- if (wkt.ellps.toLowerCase().slice(0, 13) === "international") {
- wkt.ellps = 'intl';
- }
-
- wkt.a = wkt.GEOGCS.DATUM.SPHEROID.a;
- wkt.rf = parseFloat(wkt.GEOGCS.DATUM.SPHEROID.rf, 10);
- }
- if (~wkt.datumCode.indexOf('osgb_1936')) {
- wkt.datumCode = "osgb36";
- }
- }
- if (wkt.b && !isFinite(wkt.b)) {
- wkt.b = wkt.a;
- }
-
- function toMeter(input) {
- var ratio = wkt.to_meter || 1;
- return parseFloat(input, 10) * ratio;
- }
- var renamer = function(a) {
- return rename(wkt, a);
- };
- var list = [
- ['standard_parallel_1', 'Standard_Parallel_1'],
- ['standard_parallel_2', 'Standard_Parallel_2'],
- ['false_easting', 'False_Easting'],
- ['false_northing', 'False_Northing'],
- ['central_meridian', 'Central_Meridian'],
- ['latitude_of_origin', 'Latitude_Of_Origin'],
- ['latitude_of_origin', 'Central_Parallel'],
- ['scale_factor', 'Scale_Factor'],
- ['k0', 'scale_factor'],
- ['latitude_of_center', 'Latitude_of_center'],
- ['lat0', 'latitude_of_center', d2r],
- ['longitude_of_center', 'Longitude_Of_Center'],
- ['longc', 'longitude_of_center', d2r],
- ['x0', 'false_easting', toMeter],
- ['y0', 'false_northing', toMeter],
- ['long0', 'central_meridian', d2r],
- ['lat0', 'latitude_of_origin', d2r],
- ['lat0', 'standard_parallel_1', d2r],
- ['lat1', 'standard_parallel_1', d2r],
- ['lat2', 'standard_parallel_2', d2r],
- ['alpha', 'azimuth', d2r],
- ['srsCode', 'name']
- ];
- list.forEach(renamer);
- if (!wkt.long0 && wkt.longc && (wkt.projName === 'Albers_Conic_Equal_Area' || wkt.projName === "Lambert_Azimuthal_Equal_Area")) {
- wkt.long0 = wkt.longc;
- }
- if (!wkt.lat_ts && wkt.lat1 && (wkt.projName === 'Stereographic_South_Pole' || wkt.projName === 'Polar Stereographic (variant B)')) {
- wkt.lat0 = d2r(wkt.lat1 > 0 ? 90 : -90);
- wkt.lat_ts = wkt.lat1;
- }
-}
-module.exports = function(wkt, self) {
- var lisp = JSON.parse(("," + wkt).replace(/\s*\,\s*([A-Z_0-9]+?)(\[)/g, ',["$1",').slice(1).replace(/\s*\,\s*([A-Z_0-9]+?)\]/g, ',"$1"]').replace(/,\["VERTCS".+/,''));
- var type = lisp.shift();
- var name = lisp.shift();
- lisp.unshift(['name', name]);
- lisp.unshift(['type', type]);
- lisp.unshift('output');
- var obj = {};
- sExpr(lisp, obj);
- cleanWKT(obj.output);
- return extend(self, obj.output);
-};
-
-},{"./extend":36}],70:[function(require,module,exports){
-
-
-
-/**
- * UTM zones are grouped, and assigned to one of a group of 6
- * sets.
- *
- * {int} @private
- */
-var NUM_100K_SETS = 6;
-
-/**
- * The column letters (for easting) of the lower left value, per
- * set.
- *
- * {string} @private
- */
-var SET_ORIGIN_COLUMN_LETTERS = 'AJSAJS';
-
-/**
- * The row letters (for northing) of the lower left value, per
- * set.
- *
- * {string} @private
- */
-var SET_ORIGIN_ROW_LETTERS = 'AFAFAF';
-
-var A = 65; // A
-var I = 73; // I
-var O = 79; // O
-var V = 86; // V
-var Z = 90; // Z
-
-/**
- * Conversion of lat/lon to MGRS.
- *
- * @param {object} ll Object literal with lat and lon properties on a
- * WGS84 ellipsoid.
- * @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for
- * 100 m, 2 for 1000 m or 1 for 10000 m). Optional, default is 5.
- * @return {string} the MGRS string for the given location and accuracy.
- */
-exports.forward = function(ll, accuracy) {
- accuracy = accuracy || 5; // default accuracy 1m
- return encode(LLtoUTM({
- lat: ll[1],
- lon: ll[0]
- }), accuracy);
-};
-
-/**
- * Conversion of MGRS to lat/lon.
- *
- * @param {string} mgrs MGRS string.
- * @return {array} An array with left (longitude), bottom (latitude), right
- * (longitude) and top (latitude) values in WGS84, representing the
- * bounding box for the provided MGRS reference.
- */
-exports.inverse = function(mgrs) {
- var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
- if (bbox.lat && bbox.lon) {
- return [bbox.lon, bbox.lat, bbox.lon, bbox.lat];
- }
- return [bbox.left, bbox.bottom, bbox.right, bbox.top];
-};
-
-exports.toPoint = function(mgrs) {
- var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
- if (bbox.lat && bbox.lon) {
- return [bbox.lon, bbox.lat];
- }
- return [(bbox.left + bbox.right) / 2, (bbox.top + bbox.bottom) / 2];
-};
-/**
- * Conversion from degrees to radians.
- *
- * @private
- * @param {number} deg the angle in degrees.
- * @return {number} the angle in radians.
- */
-function degToRad(deg) {
- return (deg * (Math.PI / 180.0));
-}
-
-/**
- * Conversion from radians to degrees.
- *
- * @private
- * @param {number} rad the angle in radians.
- * @return {number} the angle in degrees.
- */
-function radToDeg(rad) {
- return (180.0 * (rad / Math.PI));
-}
-
-/**
- * Converts a set of Longitude and Latitude co-ordinates to UTM
- * using the WGS84 ellipsoid.
- *
- * @private
- * @param {object} ll Object literal with lat and lon properties
- * representing the WGS84 coordinate to be converted.
- * @return {object} Object literal containing the UTM value with easting,
- * northing, zoneNumber and zoneLetter properties, and an optional
- * accuracy property in digits. Returns null if the conversion failed.
- */
-function LLtoUTM(ll) {
- var Lat = ll.lat;
- var Long = ll.lon;
- var a = 6378137.0; //ellip.radius;
- var eccSquared = 0.00669438; //ellip.eccsq;
- var k0 = 0.9996;
- var LongOrigin;
- var eccPrimeSquared;
- var N, T, C, A, M;
- var LatRad = degToRad(Lat);
- var LongRad = degToRad(Long);
- var LongOriginRad;
- var ZoneNumber;
- // (int)
- ZoneNumber = Math.floor((Long + 180) / 6) + 1;
-
- //Make sure the longitude 180.00 is in Zone 60
- if (Long === 180) {
- ZoneNumber = 60;
- }
-
- // Special zone for Norway
- if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) {
- ZoneNumber = 32;
- }
-
- // Special zones for Svalbard
- if (Lat >= 72.0 && Lat < 84.0) {
- if (Long >= 0.0 && Long < 9.0) {
- ZoneNumber = 31;
- }
- else if (Long >= 9.0 && Long < 21.0) {
- ZoneNumber = 33;
- }
- else if (Long >= 21.0 && Long < 33.0) {
- ZoneNumber = 35;
- }
- else if (Long >= 33.0 && Long < 42.0) {
- ZoneNumber = 37;
- }
- }
-
- LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin
- // in middle of
- // zone
- LongOriginRad = degToRad(LongOrigin);
-
- eccPrimeSquared = (eccSquared) / (1 - eccSquared);
-
- N = a / Math.sqrt(1 - eccSquared * Math.sin(LatRad) * Math.sin(LatRad));
- T = Math.tan(LatRad) * Math.tan(LatRad);
- C = eccPrimeSquared * Math.cos(LatRad) * Math.cos(LatRad);
- A = Math.cos(LatRad) * (LongRad - LongOriginRad);
-
- M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(2 * LatRad) + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(4 * LatRad) - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.sin(6 * LatRad));
-
- var UTMEasting = (k0 * N * (A + (1 - T + C) * A * A * A / 6.0 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120.0) + 500000.0);
-
- var UTMNorthing = (k0 * (M + N * Math.tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24.0 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720.0)));
- if (Lat < 0.0) {
- UTMNorthing += 10000000.0; //10000000 meter offset for
- // southern hemisphere
- }
-
- return {
- northing: Math.round(UTMNorthing),
- easting: Math.round(UTMEasting),
- zoneNumber: ZoneNumber,
- zoneLetter: getLetterDesignator(Lat)
- };
-}
-
-/**
- * Converts UTM coords to lat/long, using the WGS84 ellipsoid. This is a convenience
- * class where the Zone can be specified as a single string eg."60N" which
- * is then broken down into the ZoneNumber and ZoneLetter.
- *
- * @private
- * @param {object} utm An object literal with northing, easting, zoneNumber
- * and zoneLetter properties. If an optional accuracy property is
- * provided (in meters), a bounding box will be returned instead of
- * latitude and longitude.
- * @return {object} An object literal containing either lat and lon values
- * (if no accuracy was provided), or top, right, bottom and left values
- * for the bounding box calculated according to the provided accuracy.
- * Returns null if the conversion failed.
- */
-function UTMtoLL(utm) {
-
- var UTMNorthing = utm.northing;
- var UTMEasting = utm.easting;
- var zoneLetter = utm.zoneLetter;
- var zoneNumber = utm.zoneNumber;
- // check the ZoneNummber is valid
- if (zoneNumber < 0 || zoneNumber > 60) {
- return null;
- }
-
- var k0 = 0.9996;
- var a = 6378137.0; //ellip.radius;
- var eccSquared = 0.00669438; //ellip.eccsq;
- var eccPrimeSquared;
- var e1 = (1 - Math.sqrt(1 - eccSquared)) / (1 + Math.sqrt(1 - eccSquared));
- var N1, T1, C1, R1, D, M;
- var LongOrigin;
- var mu, phi1Rad;
-
- // remove 500,000 meter offset for longitude
- var x = UTMEasting - 500000.0;
- var y = UTMNorthing;
-
- // We must know somehow if we are in the Northern or Southern
- // hemisphere, this is the only time we use the letter So even
- // if the Zone letter isn't exactly correct it should indicate
- // the hemisphere correctly
- if (zoneLetter < 'N') {
- y -= 10000000.0; // remove 10,000,000 meter offset used
- // for southern hemisphere
- }
-
- // There are 60 zones with zone 1 being at West -180 to -174
- LongOrigin = (zoneNumber - 1) * 6 - 180 + 3; // +3 puts origin
- // in middle of
- // zone
-
- eccPrimeSquared = (eccSquared) / (1 - eccSquared);
-
- M = y / k0;
- mu = M / (a * (1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256));
-
- phi1Rad = mu + (3 * e1 / 2 - 27 * e1 * e1 * e1 / 32) * Math.sin(2 * mu) + (21 * e1 * e1 / 16 - 55 * e1 * e1 * e1 * e1 / 32) * Math.sin(4 * mu) + (151 * e1 * e1 * e1 / 96) * Math.sin(6 * mu);
- // double phi1 = ProjMath.radToDeg(phi1Rad);
-
- N1 = a / Math.sqrt(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad));
- T1 = Math.tan(phi1Rad) * Math.tan(phi1Rad);
- C1 = eccPrimeSquared * Math.cos(phi1Rad) * Math.cos(phi1Rad);
- R1 = a * (1 - eccSquared) / Math.pow(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad), 1.5);
- D = x / (N1 * k0);
-
- var lat = phi1Rad - (N1 * Math.tan(phi1Rad) / R1) * (D * D / 2 - (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * eccPrimeSquared) * D * D * D * D / 24 + (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1 - 252 * eccPrimeSquared - 3 * C1 * C1) * D * D * D * D * D * D / 720);
- lat = radToDeg(lat);
-
- var lon = (D - (1 + 2 * T1 + C1) * D * D * D / 6 + (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * eccPrimeSquared + 24 * T1 * T1) * D * D * D * D * D / 120) / Math.cos(phi1Rad);
- lon = LongOrigin + radToDeg(lon);
-
- var result;
- if (utm.accuracy) {
- var topRight = UTMtoLL({
- northing: utm.northing + utm.accuracy,
- easting: utm.easting + utm.accuracy,
- zoneLetter: utm.zoneLetter,
- zoneNumber: utm.zoneNumber
- });
- result = {
- top: topRight.lat,
- right: topRight.lon,
- bottom: lat,
- left: lon
- };
- }
- else {
- result = {
- lat: lat,
- lon: lon
- };
- }
- return result;
-}
-
-/**
- * Calculates the MGRS letter designator for the given latitude.
- *
- * @private
- * @param {number} lat The latitude in WGS84 to get the letter designator
- * for.
- * @return {char} The letter designator.
- */
-function getLetterDesignator(lat) {
- //This is here as an error flag to show that the Latitude is
- //outside MGRS limits
- var LetterDesignator = 'Z';
-
- if ((84 >= lat) && (lat >= 72)) {
- LetterDesignator = 'X';
- }
- else if ((72 > lat) && (lat >= 64)) {
- LetterDesignator = 'W';
- }
- else if ((64 > lat) && (lat >= 56)) {
- LetterDesignator = 'V';
- }
- else if ((56 > lat) && (lat >= 48)) {
- LetterDesignator = 'U';
- }
- else if ((48 > lat) && (lat >= 40)) {
- LetterDesignator = 'T';
- }
- else if ((40 > lat) && (lat >= 32)) {
- LetterDesignator = 'S';
- }
- else if ((32 > lat) && (lat >= 24)) {
- LetterDesignator = 'R';
- }
- else if ((24 > lat) && (lat >= 16)) {
- LetterDesignator = 'Q';
- }
- else if ((16 > lat) && (lat >= 8)) {
- LetterDesignator = 'P';
- }
- else if ((8 > lat) && (lat >= 0)) {
- LetterDesignator = 'N';
- }
- else if ((0 > lat) && (lat >= -8)) {
- LetterDesignator = 'M';
- }
- else if ((-8 > lat) && (lat >= -16)) {
- LetterDesignator = 'L';
- }
- else if ((-16 > lat) && (lat >= -24)) {
- LetterDesignator = 'K';
- }
- else if ((-24 > lat) && (lat >= -32)) {
- LetterDesignator = 'J';
- }
- else if ((-32 > lat) && (lat >= -40)) {
- LetterDesignator = 'H';
- }
- else if ((-40 > lat) && (lat >= -48)) {
- LetterDesignator = 'G';
- }
- else if ((-48 > lat) && (lat >= -56)) {
- LetterDesignator = 'F';
- }
- else if ((-56 > lat) && (lat >= -64)) {
- LetterDesignator = 'E';
- }
- else if ((-64 > lat) && (lat >= -72)) {
- LetterDesignator = 'D';
- }
- else if ((-72 > lat) && (lat >= -80)) {
- LetterDesignator = 'C';
- }
- return LetterDesignator;
-}
-
-/**
- * Encodes a UTM location as MGRS string.
- *
- * @private
- * @param {object} utm An object literal with easting, northing,
- * zoneLetter, zoneNumber
- * @param {number} accuracy Accuracy in digits (1-5).
- * @return {string} MGRS string for the given UTM location.
- */
-function encode(utm, accuracy) {
- // prepend with leading zeroes
- var seasting = "00000" + utm.easting,
- snorthing = "00000" + utm.northing;
-
- return utm.zoneNumber + utm.zoneLetter + get100kID(utm.easting, utm.northing, utm.zoneNumber) + seasting.substr(seasting.length - 5, accuracy) + snorthing.substr(snorthing.length - 5, accuracy);
-}
-
-/**
- * Get the two letter 100k designator for a given UTM easting,
- * northing and zone number value.
- *
- * @private
- * @param {number} easting
- * @param {number} northing
- * @param {number} zoneNumber
- * @return the two letter 100k designator for the given UTM location.
- */
-function get100kID(easting, northing, zoneNumber) {
- var setParm = get100kSetForZone(zoneNumber);
- var setColumn = Math.floor(easting / 100000);
- var setRow = Math.floor(northing / 100000) % 20;
- return getLetter100kID(setColumn, setRow, setParm);
-}
-
-/**
- * Given a UTM zone number, figure out the MGRS 100K set it is in.
- *
- * @private
- * @param {number} i An UTM zone number.
- * @return {number} the 100k set the UTM zone is in.
- */
-function get100kSetForZone(i) {
- var setParm = i % NUM_100K_SETS;
- if (setParm === 0) {
- setParm = NUM_100K_SETS;
- }
-
- return setParm;
-}
-
-/**
- * Get the two-letter MGRS 100k designator given information
- * translated from the UTM northing, easting and zone number.
- *
- * @private
- * @param {number} column the column index as it relates to the MGRS
- * 100k set spreadsheet, created from the UTM easting.
- * Values are 1-8.
- * @param {number} row the row index as it relates to the MGRS 100k set
- * spreadsheet, created from the UTM northing value. Values
- * are from 0-19.
- * @param {number} parm the set block, as it relates to the MGRS 100k set
- * spreadsheet, created from the UTM zone. Values are from
- * 1-60.
- * @return two letter MGRS 100k code.
- */
-function getLetter100kID(column, row, parm) {
- // colOrigin and rowOrigin are the letters at the origin of the set
- var index = parm - 1;
- var colOrigin = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(index);
- var rowOrigin = SET_ORIGIN_ROW_LETTERS.charCodeAt(index);
-
- // colInt and rowInt are the letters to build to return
- var colInt = colOrigin + column - 1;
- var rowInt = rowOrigin + row;
- var rollover = false;
-
- if (colInt > Z) {
- colInt = colInt - Z + A - 1;
- rollover = true;
- }
-
- if (colInt === I || (colOrigin < I && colInt > I) || ((colInt > I || colOrigin < I) && rollover)) {
- colInt++;
- }
-
- if (colInt === O || (colOrigin < O && colInt > O) || ((colInt > O || colOrigin < O) && rollover)) {
- colInt++;
-
- if (colInt === I) {
- colInt++;
- }
- }
-
- if (colInt > Z) {
- colInt = colInt - Z + A - 1;
- }
-
- if (rowInt > V) {
- rowInt = rowInt - V + A - 1;
- rollover = true;
- }
- else {
- rollover = false;
- }
-
- if (((rowInt === I) || ((rowOrigin < I) && (rowInt > I))) || (((rowInt > I) || (rowOrigin < I)) && rollover)) {
- rowInt++;
- }
-
- if (((rowInt === O) || ((rowOrigin < O) && (rowInt > O))) || (((rowInt > O) || (rowOrigin < O)) && rollover)) {
- rowInt++;
-
- if (rowInt === I) {
- rowInt++;
- }
- }
-
- if (rowInt > V) {
- rowInt = rowInt - V + A - 1;
- }
-
- var twoLetter = String.fromCharCode(colInt) + String.fromCharCode(rowInt);
- return twoLetter;
-}
-
-/**
- * Decode the UTM parameters from a MGRS string.
- *
- * @private
- * @param {string} mgrsString an UPPERCASE coordinate string is expected.
- * @return {object} An object literal with easting, northing, zoneLetter,
- * zoneNumber and accuracy (in meters) properties.
- */
-function decode(mgrsString) {
-
- if (mgrsString && mgrsString.length === 0) {
- throw ("MGRSPoint coverting from nothing");
- }
-
- var length = mgrsString.length;
-
- var hunK = null;
- var sb = "";
- var testChar;
- var i = 0;
-
- // get Zone number
- while (!(/[A-Z]/).test(testChar = mgrsString.charAt(i))) {
- if (i >= 2) {
- throw ("MGRSPoint bad conversion from: " + mgrsString);
- }
- sb += testChar;
- i++;
- }
-
- var zoneNumber = parseInt(sb, 10);
-
- if (i === 0 || i + 3 > length) {
- // A good MGRS string has to be 4-5 digits long,
- // ##AAA/#AAA at least.
- throw ("MGRSPoint bad conversion from: " + mgrsString);
- }
-
- var zoneLetter = mgrsString.charAt(i++);
-
- // Should we check the zone letter here? Why not.
- if (zoneLetter <= 'A' || zoneLetter === 'B' || zoneLetter === 'Y' || zoneLetter >= 'Z' || zoneLetter === 'I' || zoneLetter === 'O') {
- throw ("MGRSPoint zone letter " + zoneLetter + " not handled: " + mgrsString);
- }
-
- hunK = mgrsString.substring(i, i += 2);
-
- var set = get100kSetForZone(zoneNumber);
-
- var east100k = getEastingFromChar(hunK.charAt(0), set);
- var north100k = getNorthingFromChar(hunK.charAt(1), set);
-
- // We have a bug where the northing may be 2000000 too low.
- // How
- // do we know when to roll over?
-
- while (north100k < getMinNorthing(zoneLetter)) {
- north100k += 2000000;
- }
-
- // calculate the char index for easting/northing separator
- var remainder = length - i;
-
- if (remainder % 2 !== 0) {
- throw ("MGRSPoint has to have an even number \nof digits after the zone letter and two 100km letters - front \nhalf for easting meters, second half for \nnorthing meters" + mgrsString);
- }
-
- var sep = remainder / 2;
-
- var sepEasting = 0.0;
- var sepNorthing = 0.0;
- var accuracyBonus, sepEastingString, sepNorthingString, easting, northing;
- if (sep > 0) {
- accuracyBonus = 100000.0 / Math.pow(10, sep);
- sepEastingString = mgrsString.substring(i, i + sep);
- sepEasting = parseFloat(sepEastingString) * accuracyBonus;
- sepNorthingString = mgrsString.substring(i + sep);
- sepNorthing = parseFloat(sepNorthingString) * accuracyBonus;
- }
-
- easting = sepEasting + east100k;
- northing = sepNorthing + north100k;
-
- return {
- easting: easting,
- northing: northing,
- zoneLetter: zoneLetter,
- zoneNumber: zoneNumber,
- accuracy: accuracyBonus
- };
-}
-
-/**
- * Given the first letter from a two-letter MGRS 100k zone, and given the
- * MGRS table set for the zone number, figure out the easting value that
- * should be added to the other, secondary easting value.
- *
- * @private
- * @param {char} e The first letter from a two-letter MGRS 100´k zone.
- * @param {number} set The MGRS table set for the zone number.
- * @return {number} The easting value for the given letter and set.
- */
-function getEastingFromChar(e, set) {
- // colOrigin is the letter at the origin of the set for the
- // column
- var curCol = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(set - 1);
- var eastingValue = 100000.0;
- var rewindMarker = false;
-
- while (curCol !== e.charCodeAt(0)) {
- curCol++;
- if (curCol === I) {
- curCol++;
- }
- if (curCol === O) {
- curCol++;
- }
- if (curCol > Z) {
- if (rewindMarker) {
- throw ("Bad character: " + e);
- }
- curCol = A;
- rewindMarker = true;
- }
- eastingValue += 100000.0;
- }
-
- return eastingValue;
-}
-
-/**
- * Given the second letter from a two-letter MGRS 100k zone, and given the
- * MGRS table set for the zone number, figure out the northing value that
- * should be added to the other, secondary northing value. You have to
- * remember that Northings are determined from the equator, and the vertical
- * cycle of letters mean a 2000000 additional northing meters. This happens
- * approx. every 18 degrees of latitude. This method does *NOT* count any
- * additional northings. You have to figure out how many 2000000 meters need
- * to be added for the zone letter of the MGRS coordinate.
- *
- * @private
- * @param {char} n Second letter of the MGRS 100k zone
- * @param {number} set The MGRS table set number, which is dependent on the
- * UTM zone number.
- * @return {number} The northing value for the given letter and set.
- */
-function getNorthingFromChar(n, set) {
-
- if (n > 'V') {
- throw ("MGRSPoint given invalid Northing " + n);
- }
-
- // rowOrigin is the letter at the origin of the set for the
- // column
- var curRow = SET_ORIGIN_ROW_LETTERS.charCodeAt(set - 1);
- var northingValue = 0.0;
- var rewindMarker = false;
-
- while (curRow !== n.charCodeAt(0)) {
- curRow++;
- if (curRow === I) {
- curRow++;
- }
- if (curRow === O) {
- curRow++;
- }
- // fixing a bug making whole application hang in this loop
- // when 'n' is a wrong character
- if (curRow > V) {
- if (rewindMarker) { // making sure that this loop ends
- throw ("Bad character: " + n);
- }
- curRow = A;
- rewindMarker = true;
- }
- northingValue += 100000.0;
- }
-
- return northingValue;
-}
-
-/**
- * The function getMinNorthing returns the minimum northing value of a MGRS
- * zone.
- *
- * Ported from Geotrans' c Lattitude_Band_Value structure table.
- *
- * @private
- * @param {char} zoneLetter The MGRS zone to get the min northing for.
- * @return {number}
- */
-function getMinNorthing(zoneLetter) {
- var northing;
- switch (zoneLetter) {
- case 'C':
- northing = 1100000.0;
- break;
- case 'D':
- northing = 2000000.0;
- break;
- case 'E':
- northing = 2800000.0;
- break;
- case 'F':
- northing = 3700000.0;
- break;
- case 'G':
- northing = 4600000.0;
- break;
- case 'H':
- northing = 5500000.0;
- break;
- case 'J':
- northing = 6400000.0;
- break;
- case 'K':
- northing = 7300000.0;
- break;
- case 'L':
- northing = 8200000.0;
- break;
- case 'M':
- northing = 9100000.0;
- break;
- case 'N':
- northing = 0.0;
- break;
- case 'P':
- northing = 800000.0;
- break;
- case 'Q':
- northing = 1700000.0;
- break;
- case 'R':
- northing = 2600000.0;
- break;
- case 'S':
- northing = 3500000.0;
- break;
- case 'T':
- northing = 4400000.0;
- break;
- case 'U':
- northing = 5300000.0;
- break;
- case 'V':
- northing = 6200000.0;
- break;
- case 'W':
- northing = 7000000.0;
- break;
- case 'X':
- northing = 7900000.0;
- break;
- default:
- northing = -1.0;
- }
- if (northing >= 0.0) {
- return northing;
- }
- else {
- throw ("Invalid zone letter: " + zoneLetter);
- }
-
-}
-
-},{}]},{},[38])(38)
-});
\ No newline at end of file
+(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+ typeof define === 'function' && define.amd ? define(factory) :
+ (global.proj4 = factory());
+}(this, (function () { 'use strict';
+
+ var globals = function(defs) {
+ defs('EPSG:4326', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
+ defs('EPSG:4269', "+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees");
+ defs('EPSG:3857', "+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs");
+
+ defs.WGS84 = defs['EPSG:4326'];
+ defs['EPSG:3785'] = defs['EPSG:3857']; // maintain backward compat, official code is 3857
+ defs.GOOGLE = defs['EPSG:3857'];
+ defs['EPSG:900913'] = defs['EPSG:3857'];
+ defs['EPSG:102113'] = defs['EPSG:3857'];
+ };
+
+ var PJD_3PARAM = 1;
+ var PJD_7PARAM = 2;
+ var PJD_WGS84 = 4; // WGS84 or equivalent
+ var PJD_NODATUM = 5; // WGS84 or equivalent
+ var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
+ var HALF_PI = Math.PI/2;
+ // ellipoid pj_set_ell.c
+ var SIXTH = 0.1666666666666666667;
+ /* 1/6 */
+ var RA4 = 0.04722222222222222222;
+ /* 17/360 */
+ var RA6 = 0.02215608465608465608;
+ var EPSLN = (typeof Number.EPSILON === 'undefined') ? 1.0e-10 : Number.EPSILON;
+ var D2R = 0.01745329251994329577;
+ var R2D = 57.29577951308232088;
+ var FORTPI = Math.PI/4;
+ var TWO_PI = Math.PI * 2;
+ // SPI is slightly greater than Math.PI, so values that exceed the -180..180
+ // degree range by a tiny amount don't get wrapped. This prevents points that
+ // have drifted from their original location along the 180th meridian (due to
+ // floating point error) from changing their sign.
+ var SPI = 3.14159265359;
+
+ var exports$1 = {};
+ exports$1.greenwich = 0.0; //"0dE",
+ exports$1.lisbon = -9.131906111111; //"9d07'54.862\"W",
+ exports$1.paris = 2.337229166667; //"2d20'14.025\"E",
+ exports$1.bogota = -74.080916666667; //"74d04'51.3\"W",
+ exports$1.madrid = -3.687938888889; //"3d41'16.58\"W",
+ exports$1.rome = 12.452333333333; //"12d27'8.4\"E",
+ exports$1.bern = 7.439583333333; //"7d26'22.5\"E",
+ exports$1.jakarta = 106.807719444444; //"106d48'27.79\"E",
+ exports$1.ferro = -17.666666666667; //"17d40'W",
+ exports$1.brussels = 4.367975; //"4d22'4.71\"E",
+ exports$1.stockholm = 18.058277777778; //"18d3'29.8\"E",
+ exports$1.athens = 23.7163375; //"23d42'58.815\"E",
+ exports$1.oslo = 10.722916666667; //"10d43'22.5\"E"
+
+ var units = {
+ ft: {to_meter: 0.3048},
+ 'us-ft': {to_meter: 1200 / 3937}
+ };
+
+ var ignoredChar = /[\s_\-\/\(\)]/g;
+ function match(obj, key) {
+ if (obj[key]) {
+ return obj[key];
+ }
+ var keys = Object.keys(obj);
+ var lkey = key.toLowerCase().replace(ignoredChar, '');
+ var i = -1;
+ var testkey, processedKey;
+ while (++i < keys.length) {
+ testkey = keys[i];
+ processedKey = testkey.toLowerCase().replace(ignoredChar, '');
+ if (processedKey === lkey) {
+ return obj[testkey];
+ }
+ }
+ }
+
+ var parseProj = function(defData) {
+ var self = {};
+ var paramObj = defData.split('+').map(function(v) {
+ return v.trim();
+ }).filter(function(a) {
+ return a;
+ }).reduce(function(p, a) {
+ var split = a.split('=');
+ split.push(true);
+ p[split[0].toLowerCase()] = split[1];
+ return p;
+ }, {});
+ var paramName, paramVal, paramOutname;
+ var params = {
+ proj: 'projName',
+ datum: 'datumCode',
+ rf: function(v) {
+ self.rf = parseFloat(v);
+ },
+ lat_0: function(v) {
+ self.lat0 = v * D2R;
+ },
+ lat_1: function(v) {
+ self.lat1 = v * D2R;
+ },
+ lat_2: function(v) {
+ self.lat2 = v * D2R;
+ },
+ lat_ts: function(v) {
+ self.lat_ts = v * D2R;
+ },
+ lon_0: function(v) {
+ self.long0 = v * D2R;
+ },
+ lon_1: function(v) {
+ self.long1 = v * D2R;
+ },
+ lon_2: function(v) {
+ self.long2 = v * D2R;
+ },
+ alpha: function(v) {
+ self.alpha = parseFloat(v) * D2R;
+ },
+ lonc: function(v) {
+ self.longc = v * D2R;
+ },
+ x_0: function(v) {
+ self.x0 = parseFloat(v);
+ },
+ y_0: function(v) {
+ self.y0 = parseFloat(v);
+ },
+ k_0: function(v) {
+ self.k0 = parseFloat(v);
+ },
+ k: function(v) {
+ self.k0 = parseFloat(v);
+ },
+ a: function(v) {
+ self.a = parseFloat(v);
+ },
+ b: function(v) {
+ self.b = parseFloat(v);
+ },
+ r_a: function() {
+ self.R_A = true;
+ },
+ zone: function(v) {
+ self.zone = parseInt(v, 10);
+ },
+ south: function() {
+ self.utmSouth = true;
+ },
+ towgs84: function(v) {
+ self.datum_params = v.split(",").map(function(a) {
+ return parseFloat(a);
+ });
+ },
+ to_meter: function(v) {
+ self.to_meter = parseFloat(v);
+ },
+ units: function(v) {
+ self.units = v;
+ var unit = match(units, v);
+ if (unit) {
+ self.to_meter = unit.to_meter;
+ }
+ },
+ from_greenwich: function(v) {
+ self.from_greenwich = v * D2R;
+ },
+ pm: function(v) {
+ var pm = match(exports$1, v);
+ self.from_greenwich = (pm ? pm : parseFloat(v)) * D2R;
+ },
+ nadgrids: function(v) {
+ if (v === '@null') {
+ self.datumCode = 'none';
+ }
+ else {
+ self.nadgrids = v;
+ }
+ },
+ axis: function(v) {
+ var legalAxis = "ewnsud";
+ if (v.length === 3 && legalAxis.indexOf(v.substr(0, 1)) !== -1 && legalAxis.indexOf(v.substr(1, 1)) !== -1 && legalAxis.indexOf(v.substr(2, 1)) !== -1) {
+ self.axis = v;
+ }
+ }
+ };
+ for (paramName in paramObj) {
+ paramVal = paramObj[paramName];
+ if (paramName in params) {
+ paramOutname = params[paramName];
+ if (typeof paramOutname === 'function') {
+ paramOutname(paramVal);
+ }
+ else {
+ self[paramOutname] = paramVal;
+ }
+ }
+ else {
+ self[paramName] = paramVal;
+ }
+ }
+ if(typeof self.datumCode === 'string' && self.datumCode !== "WGS84"){
+ self.datumCode = self.datumCode.toLowerCase();
+ }
+ return self;
+ };
+
+ var NEUTRAL = 1;
+ var KEYWORD = 2;
+ var NUMBER = 3;
+ var QUOTED = 4;
+ var AFTERQUOTE = 5;
+ var ENDED = -1;
+ var whitespace = /\s/;
+ var latin = /[A-Za-z]/;
+ var keyword = /[A-Za-z84]/;
+ var endThings = /[,\]]/;
+ var digets = /[\d\.E\-\+]/;
+ // const ignoredChar = /[\s_\-\/\(\)]/g;
+ function Parser(text) {
+ if (typeof text !== 'string') {
+ throw new Error('not a string');
+ }
+ this.text = text.trim();
+ this.level = 0;
+ this.place = 0;
+ this.root = null;
+ this.stack = [];
+ this.currentObject = null;
+ this.state = NEUTRAL;
+ }
+ Parser.prototype.readCharicter = function() {
+ var char = this.text[this.place++];
+ if (this.state !== QUOTED) {
+ while (whitespace.test(char)) {
+ if (this.place >= this.text.length) {
+ return;
+ }
+ char = this.text[this.place++];
+ }
+ }
+ switch (this.state) {
+ case NEUTRAL:
+ return this.neutral(char);
+ case KEYWORD:
+ return this.keyword(char)
+ case QUOTED:
+ return this.quoted(char);
+ case AFTERQUOTE:
+ return this.afterquote(char);
+ case NUMBER:
+ return this.number(char);
+ case ENDED:
+ return;
+ }
+ };
+ Parser.prototype.afterquote = function(char) {
+ if (char === '"') {
+ this.word += '"';
+ this.state = QUOTED;
+ return;
+ }
+ if (endThings.test(char)) {
+ this.word = this.word.trim();
+ this.afterItem(char);
+ return;
+ }
+ throw new Error('havn\'t handled "' +char + '" in afterquote yet, index ' + this.place);
+ };
+ Parser.prototype.afterItem = function(char) {
+ if (char === ',') {
+ if (this.word !== null) {
+ this.currentObject.push(this.word);
+ }
+ this.word = null;
+ this.state = NEUTRAL;
+ return;
+ }
+ if (char === ']') {
+ this.level--;
+ if (this.word !== null) {
+ this.currentObject.push(this.word);
+ this.word = null;
+ }
+ this.state = NEUTRAL;
+ this.currentObject = this.stack.pop();
+ if (!this.currentObject) {
+ this.state = ENDED;
+ }
+
+ return;
+ }
+ };
+ Parser.prototype.number = function(char) {
+ if (digets.test(char)) {
+ this.word += char;
+ return;
+ }
+ if (endThings.test(char)) {
+ this.word = parseFloat(this.word);
+ this.afterItem(char);
+ return;
+ }
+ throw new Error('havn\'t handled "' +char + '" in number yet, index ' + this.place);
+ };
+ Parser.prototype.quoted = function(char) {
+ if (char === '"') {
+ this.state = AFTERQUOTE;
+ return;
+ }
+ this.word += char;
+ return;
+ };
+ Parser.prototype.keyword = function(char) {
+ if (keyword.test(char)) {
+ this.word += char;
+ return;
+ }
+ if (char === '[') {
+ var newObjects = [];
+ newObjects.push(this.word);
+ this.level++;
+ if (this.root === null) {
+ this.root = newObjects;
+ } else {
+ this.currentObject.push(newObjects);
+ }
+ this.stack.push(this.currentObject);
+ this.currentObject = newObjects;
+ this.state = NEUTRAL;
+ return;
+ }
+ if (endThings.test(char)) {
+ this.afterItem(char);
+ return;
+ }
+ throw new Error('havn\'t handled "' +char + '" in keyword yet, index ' + this.place);
+ };
+ Parser.prototype.neutral = function(char) {
+ if (latin.test(char)) {
+ this.word = char;
+ this.state = KEYWORD;
+ return;
+ }
+ if (char === '"') {
+ this.word = '';
+ this.state = QUOTED;
+ return;
+ }
+ if (digets.test(char)) {
+ this.word = char;
+ this.state = NUMBER;
+ return;
+ }
+ if (endThings.test(char)) {
+ this.afterItem(char);
+ return;
+ }
+ throw new Error('havn\'t handled "' +char + '" in neutral yet, index ' + this.place);
+ };
+ Parser.prototype.output = function() {
+ while (this.place < this.text.length) {
+ this.readCharicter();
+ }
+ if (this.state === ENDED) {
+ return this.root;
+ }
+ throw new Error('unable to parse string "' +this.text + '". State is ' + this.state);
+ };
+
+ function parseString(txt) {
+ var parser = new Parser(txt);
+ return parser.output();
+ }
+
+ function mapit(obj, key, value) {
+ if (Array.isArray(key)) {
+ value.unshift(key);
+ key = null;
+ }
+ var thing = key ? {} : obj;
+
+ var out = value.reduce(function(newObj, item) {
+ sExpr(item, newObj);
+ return newObj
+ }, thing);
+ if (key) {
+ obj[key] = out;
+ }
+ }
+
+ function sExpr(v, obj) {
+ if (!Array.isArray(v)) {
+ obj[v] = true;
+ return;
+ }
+ var key = v.shift();
+ if (key === 'PARAMETER') {
+ key = v.shift();
+ }
+ if (v.length === 1) {
+ if (Array.isArray(v[0])) {
+ obj[key] = {};
+ sExpr(v[0], obj[key]);
+ return;
+ }
+ obj[key] = v[0];
+ return;
+ }
+ if (!v.length) {
+ obj[key] = true;
+ return;
+ }
+ if (key === 'TOWGS84') {
+ obj[key] = v;
+ return;
+ }
+ obj[key] = {};
+ var i;
+ switch (key) {
+ case 'UNIT':
+ case 'PRIMEM':
+ case 'VERT_DATUM':
+ obj[key] = {
+ name: v[0].toLowerCase(),
+ convert: v[1]
+ };
+ if (v.length === 3) {
+ sExpr(v[2], obj[key]);
+ }
+ return;
+ case 'SPHEROID':
+ case 'ELLIPSOID':
+ obj[key] = {
+ name: v[0],
+ a: v[1],
+ rf: v[2]
+ };
+ if (v.length === 4) {
+ sExpr(v[3], obj[key]);
+ }
+ return;
+ case 'PROJECTEDCRS':
+ case 'PROJCRS':
+ case 'GEOGCS':
+ case 'GEOCCS':
+ case 'PROJCS':
+ case 'LOCAL_CS':
+ case 'GEODCRS':
+ case 'GEODETICCRS':
+ case 'GEODETICDATUM':
+ case 'EDATUM':
+ case 'ENGINEERINGDATUM':
+ case 'VERT_CS':
+ case 'VERTCRS':
+ case 'VERTICALCRS':
+ case 'COMPD_CS':
+ case 'COMPOUNDCRS':
+ case 'ENGINEERINGCRS':
+ case 'ENGCRS':
+ case 'FITTED_CS':
+ case 'LOCAL_DATUM':
+ case 'DATUM':
+ v[0] = ['name', v[0]];
+ mapit(obj, key, v);
+ return;
+ default:
+ i = -1;
+ while (++i < v.length) {
+ if (!Array.isArray(v[i])) {
+ return sExpr(v, obj[key]);
+ }
+ }
+ return mapit(obj, key, v);
+ }
+ }
+
+ var D2R$1 = 0.01745329251994329577;
+ function rename(obj, params) {
+ var outName = params[0];
+ var inName = params[1];
+ if (!(outName in obj) && (inName in obj)) {
+ obj[outName] = obj[inName];
+ if (params.length === 3) {
+ obj[outName] = params[2](obj[outName]);
+ }
+ }
+ }
+
+ function d2r(input) {
+ return input * D2R$1;
+ }
+
+ function cleanWKT(wkt) {
+ if (wkt.type === 'GEOGCS') {
+ wkt.projName = 'longlat';
+ } else if (wkt.type === 'LOCAL_CS') {
+ wkt.projName = 'identity';
+ wkt.local = true;
+ } else {
+ if (typeof wkt.PROJECTION === 'object') {
+ wkt.projName = Object.keys(wkt.PROJECTION)[0];
+ } else {
+ wkt.projName = wkt.PROJECTION;
+ }
+ }
+ if (wkt.UNIT) {
+ wkt.units = wkt.UNIT.name.toLowerCase();
+ if (wkt.units === 'metre') {
+ wkt.units = 'meter';
+ }
+ if (wkt.UNIT.convert) {
+ if (wkt.type === 'GEOGCS') {
+ if (wkt.DATUM && wkt.DATUM.SPHEROID) {
+ wkt.to_meter = wkt.UNIT.convert*wkt.DATUM.SPHEROID.a;
+ }
+ } else {
+ wkt.to_meter = wkt.UNIT.convert, 10;
+ }
+ }
+ }
+
+ if (wkt.GEOGCS) {
+ //if(wkt.GEOGCS.PRIMEM&&wkt.GEOGCS.PRIMEM.convert){
+ // wkt.from_greenwich=wkt.GEOGCS.PRIMEM.convert*D2R;
+ //}
+ if (wkt.GEOGCS.DATUM) {
+ wkt.datumCode = wkt.GEOGCS.DATUM.name.toLowerCase();
+ } else {
+ wkt.datumCode = wkt.GEOGCS.name.toLowerCase();
+ }
+ if (wkt.datumCode.slice(0, 2) === 'd_') {
+ wkt.datumCode = wkt.datumCode.slice(2);
+ }
+ if (wkt.datumCode === 'new_zealand_geodetic_datum_1949' || wkt.datumCode === 'new_zealand_1949') {
+ wkt.datumCode = 'nzgd49';
+ }
+ if (wkt.datumCode === 'wgs_1984') {
+ if (wkt.PROJECTION === 'Mercator_Auxiliary_Sphere') {
+ wkt.sphere = true;
+ }
+ wkt.datumCode = 'wgs84';
+ }
+ if (wkt.datumCode.slice(-6) === '_ferro') {
+ wkt.datumCode = wkt.datumCode.slice(0, - 6);
+ }
+ if (wkt.datumCode.slice(-8) === '_jakarta') {
+ wkt.datumCode = wkt.datumCode.slice(0, - 8);
+ }
+ if (~wkt.datumCode.indexOf('belge')) {
+ wkt.datumCode = 'rnb72';
+ }
+ if (wkt.GEOGCS.DATUM && wkt.GEOGCS.DATUM.SPHEROID) {
+ wkt.ellps = wkt.GEOGCS.DATUM.SPHEROID.name.replace('_19', '').replace(/[Cc]larke\_18/, 'clrk');
+ if (wkt.ellps.toLowerCase().slice(0, 13) === 'international') {
+ wkt.ellps = 'intl';
+ }
+
+ wkt.a = wkt.GEOGCS.DATUM.SPHEROID.a;
+ wkt.rf = parseFloat(wkt.GEOGCS.DATUM.SPHEROID.rf, 10);
+ }
+ if (~wkt.datumCode.indexOf('osgb_1936')) {
+ wkt.datumCode = 'osgb36';
+ }
+ }
+ if (wkt.b && !isFinite(wkt.b)) {
+ wkt.b = wkt.a;
+ }
+
+ function toMeter(input) {
+ var ratio = wkt.to_meter || 1;
+ return input * ratio;
+ }
+ var renamer = function(a) {
+ return rename(wkt, a);
+ };
+ var list = [
+ ['standard_parallel_1', 'Standard_Parallel_1'],
+ ['standard_parallel_2', 'Standard_Parallel_2'],
+ ['false_easting', 'False_Easting'],
+ ['false_northing', 'False_Northing'],
+ ['central_meridian', 'Central_Meridian'],
+ ['latitude_of_origin', 'Latitude_Of_Origin'],
+ ['latitude_of_origin', 'Central_Parallel'],
+ ['scale_factor', 'Scale_Factor'],
+ ['k0', 'scale_factor'],
+ ['latitude_of_center', 'Latitude_of_center'],
+ ['lat0', 'latitude_of_center', d2r],
+ ['longitude_of_center', 'Longitude_Of_Center'],
+ ['longc', 'longitude_of_center', d2r],
+ ['x0', 'false_easting', toMeter],
+ ['y0', 'false_northing', toMeter],
+ ['long0', 'central_meridian', d2r],
+ ['lat0', 'latitude_of_origin', d2r],
+ ['lat0', 'standard_parallel_1', d2r],
+ ['lat1', 'standard_parallel_1', d2r],
+ ['lat2', 'standard_parallel_2', d2r],
+ ['alpha', 'azimuth', d2r],
+ ['srsCode', 'name']
+ ];
+ list.forEach(renamer);
+ if (!wkt.long0 && wkt.longc && (wkt.projName === 'Albers_Conic_Equal_Area' || wkt.projName === 'Lambert_Azimuthal_Equal_Area')) {
+ wkt.long0 = wkt.longc;
+ }
+ if (!wkt.lat_ts && wkt.lat1 && (wkt.projName === 'Stereographic_South_Pole' || wkt.projName === 'Polar Stereographic (variant B)')) {
+ wkt.lat0 = d2r(wkt.lat1 > 0 ? 90 : -90);
+ wkt.lat_ts = wkt.lat1;
+ }
+ }
+ var wkt = function(wkt) {
+ var lisp = parseString(wkt);
+ var type = lisp.shift();
+ var name = lisp.shift();
+ lisp.unshift(['name', name]);
+ lisp.unshift(['type', type]);
+ var obj = {};
+ sExpr(lisp, obj);
+ cleanWKT(obj);
+ return obj;
+ };
+
+ function defs(name) {
+ /*global console*/
+ var that = this;
+ if (arguments.length === 2) {
+ var def = arguments[1];
+ if (typeof def === 'string') {
+ if (def.charAt(0) === '+') {
+ defs[name] = parseProj(arguments[1]);
+ }
+ else {
+ defs[name] = wkt(arguments[1]);
+ }
+ } else {
+ defs[name] = def;
+ }
+ }
+ else if (arguments.length === 1) {
+ if (Array.isArray(name)) {
+ return name.map(function(v) {
+ if (Array.isArray(v)) {
+ defs.apply(that, v);
+ }
+ else {
+ defs(v);
+ }
+ });
+ }
+ else if (typeof name === 'string') {
+ if (name in defs) {
+ return defs[name];
+ }
+ }
+ else if ('EPSG' in name) {
+ defs['EPSG:' + name.EPSG] = name;
+ }
+ else if ('ESRI' in name) {
+ defs['ESRI:' + name.ESRI] = name;
+ }
+ else if ('IAU2000' in name) {
+ defs['IAU2000:' + name.IAU2000] = name;
+ }
+ else {
+ console.log(name);
+ }
+ return;
+ }
+
+
+ }
+ globals(defs);
+
+ function testObj(code){
+ return typeof code === 'string';
+ }
+ function testDef(code){
+ return code in defs;
+ }
+ var codeWords = ['PROJECTEDCRS', 'PROJCRS', 'GEOGCS','GEOCCS','PROJCS','LOCAL_CS', 'GEODCRS', 'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS'];
+ function testWKT(code){
+ return codeWords.some(function (word) {
+ return code.indexOf(word) > -1;
+ });
+ }
+ function testProj(code){
+ return code[0] === '+';
+ }
+ function parse(code){
+ if (testObj(code)) {
+ //check to see if this is a WKT string
+ if (testDef(code)) {
+ return defs[code];
+ }
+ if (testWKT(code)) {
+ return wkt(code);
+ }
+ if (testProj(code)) {
+ return parseProj(code);
+ }
+ }else{
+ return code;
+ }
+ }
+
+ var extend = function(destination, source) {
+ destination = destination || {};
+ var value, property;
+ if (!source) {
+ return destination;
+ }
+ for (property in source) {
+ value = source[property];
+ if (value !== undefined) {
+ destination[property] = value;
+ }
+ }
+ return destination;
+ };
+
+ var msfnz = function(eccent, sinphi, cosphi) {
+ var con = eccent * sinphi;
+ return cosphi / (Math.sqrt(1 - con * con));
+ };
+
+ var sign = function(x) {
+ return x<0 ? -1 : 1;
+ };
+
+ var adjust_lon = function(x) {
+ return (Math.abs(x) <= SPI) ? x : (x - (sign(x) * TWO_PI));
+ };
+
+ var tsfnz = function(eccent, phi, sinphi) {
+ var con = eccent * sinphi;
+ var com = 0.5 * eccent;
+ con = Math.pow(((1 - con) / (1 + con)), com);
+ return (Math.tan(0.5 * (HALF_PI - phi)) / con);
+ };
+
+ var phi2z = function(eccent, ts) {
+ var eccnth = 0.5 * eccent;
+ var con, dphi;
+ var phi = HALF_PI - 2 * Math.atan(ts);
+ for (var i = 0; i <= 15; i++) {
+ con = eccent * Math.sin(phi);
+ dphi = HALF_PI - 2 * Math.atan(ts * (Math.pow(((1 - con) / (1 + con)), eccnth))) - phi;
+ phi += dphi;
+ if (Math.abs(dphi) <= 0.0000000001) {
+ return phi;
+ }
+ }
+ //console.log("phi2z has NoConvergence");
+ return -9999;
+ };
+
+ function init() {
+ var con = this.b / this.a;
+ this.es = 1 - con * con;
+ if(!('x0' in this)){
+ this.x0 = 0;
+ }
+ if(!('y0' in this)){
+ this.y0 = 0;
+ }
+ this.e = Math.sqrt(this.es);
+ if (this.lat_ts) {
+ if (this.sphere) {
+ this.k0 = Math.cos(this.lat_ts);
+ }
+ else {
+ this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
+ }
+ }
+ else {
+ if (!this.k0) {
+ if (this.k) {
+ this.k0 = this.k;
+ }
+ else {
+ this.k0 = 1;
+ }
+ }
+ }
+ }
+
+ /* Mercator forward equations--mapping lat,long to x,y
+ --------------------------------------------------*/
+
+ function forward(p) {
+ var lon = p.x;
+ var lat = p.y;
+ // convert to radians
+ if (lat * R2D > 90 && lat * R2D < -90 && lon * R2D > 180 && lon * R2D < -180) {
+ return null;
+ }
+
+ var x, y;
+ if (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN) {
+ return null;
+ }
+ else {
+ if (this.sphere) {
+ x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
+ y = this.y0 + this.a * this.k0 * Math.log(Math.tan(FORTPI + 0.5 * lat));
+ }
+ else {
+ var sinphi = Math.sin(lat);
+ var ts = tsfnz(this.e, lat, sinphi);
+ x = this.x0 + this.a * this.k0 * adjust_lon(lon - this.long0);
+ y = this.y0 - this.a * this.k0 * Math.log(ts);
+ }
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+ }
+
+ /* Mercator inverse equations--mapping x,y to lat/long
+ --------------------------------------------------*/
+ function inverse(p) {
+
+ var x = p.x - this.x0;
+ var y = p.y - this.y0;
+ var lon, lat;
+
+ if (this.sphere) {
+ lat = HALF_PI - 2 * Math.atan(Math.exp(-y / (this.a * this.k0)));
+ }
+ else {
+ var ts = Math.exp(-y / (this.a * this.k0));
+ lat = phi2z(this.e, ts);
+ if (lat === -9999) {
+ return null;
+ }
+ }
+ lon = adjust_lon(this.long0 + x / (this.a * this.k0));
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$1 = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"];
+ var merc = {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names$1
+ };
+
+ function init$1() {
+ //no-op for longlat
+ }
+
+ function identity(pt) {
+ return pt;
+ }
+ var names$2 = ["longlat", "identity"];
+ var longlat = {
+ init: init$1,
+ forward: identity,
+ inverse: identity,
+ names: names$2
+ };
+
+ var projs = [merc, longlat];
+ var names$$1 = {};
+ var projStore = [];
+
+ function add(proj, i) {
+ var len = projStore.length;
+ if (!proj.names) {
+ console.log(i);
+ return true;
+ }
+ projStore[len] = proj;
+ proj.names.forEach(function(n) {
+ names$$1[n.toLowerCase()] = len;
+ });
+ return this;
+ }
+
+ function get(name) {
+ if (!name) {
+ return false;
+ }
+ var n = name.toLowerCase();
+ if (typeof names$$1[n] !== 'undefined' && projStore[names$$1[n]]) {
+ return projStore[names$$1[n]];
+ }
+ }
+
+ function start() {
+ projs.forEach(add);
+ }
+ var projections = {
+ start: start,
+ add: add,
+ get: get
+ };
+
+ var exports$2 = {};
+ exports$2.MERIT = {
+ a: 6378137.0,
+ rf: 298.257,
+ ellipseName: "MERIT 1983"
+ };
+
+ exports$2.SGS85 = {
+ a: 6378136.0,
+ rf: 298.257,
+ ellipseName: "Soviet Geodetic System 85"
+ };
+
+ exports$2.GRS80 = {
+ a: 6378137.0,
+ rf: 298.257222101,
+ ellipseName: "GRS 1980(IUGG, 1980)"
+ };
+
+ exports$2.IAU76 = {
+ a: 6378140.0,
+ rf: 298.257,
+ ellipseName: "IAU 1976"
+ };
+
+ exports$2.airy = {
+ a: 6377563.396,
+ b: 6356256.910,
+ ellipseName: "Airy 1830"
+ };
+
+ exports$2.APL4 = {
+ a: 6378137,
+ rf: 298.25,
+ ellipseName: "Appl. Physics. 1965"
+ };
+
+ exports$2.NWL9D = {
+ a: 6378145.0,
+ rf: 298.25,
+ ellipseName: "Naval Weapons Lab., 1965"
+ };
+
+ exports$2.mod_airy = {
+ a: 6377340.189,
+ b: 6356034.446,
+ ellipseName: "Modified Airy"
+ };
+
+ exports$2.andrae = {
+ a: 6377104.43,
+ rf: 300.0,
+ ellipseName: "Andrae 1876 (Den., Iclnd.)"
+ };
+
+ exports$2.aust_SA = {
+ a: 6378160.0,
+ rf: 298.25,
+ ellipseName: "Australian Natl & S. Amer. 1969"
+ };
+
+ exports$2.GRS67 = {
+ a: 6378160.0,
+ rf: 298.2471674270,
+ ellipseName: "GRS 67(IUGG 1967)"
+ };
+
+ exports$2.bessel = {
+ a: 6377397.155,
+ rf: 299.1528128,
+ ellipseName: "Bessel 1841"
+ };
+
+ exports$2.bess_nam = {
+ a: 6377483.865,
+ rf: 299.1528128,
+ ellipseName: "Bessel 1841 (Namibia)"
+ };
+
+ exports$2.clrk66 = {
+ a: 6378206.4,
+ b: 6356583.8,
+ ellipseName: "Clarke 1866"
+ };
+
+ exports$2.clrk80 = {
+ a: 6378249.145,
+ rf: 293.4663,
+ ellipseName: "Clarke 1880 mod."
+ };
+
+ exports$2.clrk58 = {
+ a: 6378293.645208759,
+ rf: 294.2606763692654,
+ ellipseName: "Clarke 1858"
+ };
+
+ exports$2.CPM = {
+ a: 6375738.7,
+ rf: 334.29,
+ ellipseName: "Comm. des Poids et Mesures 1799"
+ };
+
+ exports$2.delmbr = {
+ a: 6376428.0,
+ rf: 311.5,
+ ellipseName: "Delambre 1810 (Belgium)"
+ };
+
+ exports$2.engelis = {
+ a: 6378136.05,
+ rf: 298.2566,
+ ellipseName: "Engelis 1985"
+ };
+
+ exports$2.evrst30 = {
+ a: 6377276.345,
+ rf: 300.8017,
+ ellipseName: "Everest 1830"
+ };
+
+ exports$2.evrst48 = {
+ a: 6377304.063,
+ rf: 300.8017,
+ ellipseName: "Everest 1948"
+ };
+
+ exports$2.evrst56 = {
+ a: 6377301.243,
+ rf: 300.8017,
+ ellipseName: "Everest 1956"
+ };
+
+ exports$2.evrst69 = {
+ a: 6377295.664,
+ rf: 300.8017,
+ ellipseName: "Everest 1969"
+ };
+
+ exports$2.evrstSS = {
+ a: 6377298.556,
+ rf: 300.8017,
+ ellipseName: "Everest (Sabah & Sarawak)"
+ };
+
+ exports$2.fschr60 = {
+ a: 6378166.0,
+ rf: 298.3,
+ ellipseName: "Fischer (Mercury Datum) 1960"
+ };
+
+ exports$2.fschr60m = {
+ a: 6378155.0,
+ rf: 298.3,
+ ellipseName: "Fischer 1960"
+ };
+
+ exports$2.fschr68 = {
+ a: 6378150.0,
+ rf: 298.3,
+ ellipseName: "Fischer 1968"
+ };
+
+ exports$2.helmert = {
+ a: 6378200.0,
+ rf: 298.3,
+ ellipseName: "Helmert 1906"
+ };
+
+ exports$2.hough = {
+ a: 6378270.0,
+ rf: 297.0,
+ ellipseName: "Hough"
+ };
+
+ exports$2.intl = {
+ a: 6378388.0,
+ rf: 297.0,
+ ellipseName: "International 1909 (Hayford)"
+ };
+
+ exports$2.kaula = {
+ a: 6378163.0,
+ rf: 298.24,
+ ellipseName: "Kaula 1961"
+ };
+
+ exports$2.lerch = {
+ a: 6378139.0,
+ rf: 298.257,
+ ellipseName: "Lerch 1979"
+ };
+
+ exports$2.mprts = {
+ a: 6397300.0,
+ rf: 191.0,
+ ellipseName: "Maupertius 1738"
+ };
+
+ exports$2.new_intl = {
+ a: 6378157.5,
+ b: 6356772.2,
+ ellipseName: "New International 1967"
+ };
+
+ exports$2.plessis = {
+ a: 6376523.0,
+ rf: 6355863.0,
+ ellipseName: "Plessis 1817 (France)"
+ };
+
+ exports$2.krass = {
+ a: 6378245.0,
+ rf: 298.3,
+ ellipseName: "Krassovsky, 1942"
+ };
+
+ exports$2.SEasia = {
+ a: 6378155.0,
+ b: 6356773.3205,
+ ellipseName: "Southeast Asia"
+ };
+
+ exports$2.walbeck = {
+ a: 6376896.0,
+ b: 6355834.8467,
+ ellipseName: "Walbeck"
+ };
+
+ exports$2.WGS60 = {
+ a: 6378165.0,
+ rf: 298.3,
+ ellipseName: "WGS 60"
+ };
+
+ exports$2.WGS66 = {
+ a: 6378145.0,
+ rf: 298.25,
+ ellipseName: "WGS 66"
+ };
+
+ exports$2.WGS7 = {
+ a: 6378135.0,
+ rf: 298.26,
+ ellipseName: "WGS 72"
+ };
+
+ exports$2.WGS84 = {
+ a: 6378137.0,
+ rf: 298.257223563,
+ ellipseName: "WGS 84"
+ };
+
+ exports$2.sphere = {
+ a: 6370997.0,
+ b: 6370997.0,
+ ellipseName: "Normal Sphere (r=6370997)"
+ };
+
+ function eccentricity(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
+ };
+ }
+ var wgs84$1 = match(exports$2, 'WGS84');
+ function sphere(a, b, rf, ellps, sphere) {
+ if (!a) { // do we have an ellipsoid?
+ var ellipse = match(exports$2, ellps);
+ if (!ellipse) {
+ ellipse = wgs84$1;
+ }
+ a = ellipse.a;
+ b = ellipse.b;
+ rf = ellipse.rf;
+ }
+
+ if (rf && !b) {
+ b = (1.0 - 1.0 / rf) * a;
+ }
+ if (rf === 0 || Math.abs(a - b) < EPSLN) {
+ sphere = true;
+ b = a;
+ }
+ return {
+ a: a,
+ b: b,
+ rf: rf,
+ sphere: sphere
+ };
+ }
+
+ var exports$3 = {};
+ exports$3.wgs84 = {
+ towgs84: "0,0,0",
+ ellipse: "WGS84",
+ datumName: "WGS84"
+ };
+
+ exports$3.ch1903 = {
+ towgs84: "674.374,15.056,405.346",
+ ellipse: "bessel",
+ datumName: "swiss"
+ };
+
+ exports$3.ggrs87 = {
+ towgs84: "-199.87,74.79,246.62",
+ ellipse: "GRS80",
+ datumName: "Greek_Geodetic_Reference_System_1987"
+ };
+
+ exports$3.nad83 = {
+ towgs84: "0,0,0",
+ ellipse: "GRS80",
+ datumName: "North_American_Datum_1983"
+ };
+
+ exports$3.nad27 = {
+ nadgrids: "@conus, at alaska, at ntv2_0.gsb, at ntv1_can.dat",
+ ellipse: "clrk66",
+ datumName: "North_American_Datum_1927"
+ };
+
+ exports$3.potsdam = {
+ towgs84: "606.0,23.0,413.0",
+ ellipse: "bessel",
+ datumName: "Potsdam Rauenberg 1950 DHDN"
+ };
+
+ exports$3.carthage = {
+ towgs84: "-263.0,6.0,431.0",
+ ellipse: "clark80",
+ datumName: "Carthage 1934 Tunisia"
+ };
+
+ exports$3.hermannskogel = {
+ towgs84: "653.0,-212.0,449.0",
+ ellipse: "bessel",
+ datumName: "Hermannskogel"
+ };
+
+ exports$3.ire65 = {
+ towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",
+ ellipse: "mod_airy",
+ datumName: "Ireland 1965"
+ };
+
+ exports$3.rassadiran = {
+ towgs84: "-133.63,-157.5,-158.62",
+ ellipse: "intl",
+ datumName: "Rassadiran"
+ };
+
+ exports$3.nzgd49 = {
+ towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",
+ ellipse: "intl",
+ datumName: "New Zealand Geodetic Datum 1949"
+ };
+
+ exports$3.osgb36 = {
+ towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",
+ ellipse: "airy",
+ datumName: "Airy 1830"
+ };
+
+ exports$3.s_jtsk = {
+ towgs84: "589,76,480",
+ ellipse: 'bessel',
+ datumName: 'S-JTSK (Ferro)'
+ };
+
+ exports$3.beduaram = {
+ towgs84: '-106,-87,188',
+ ellipse: 'clrk80',
+ datumName: 'Beduaram'
+ };
+
+ exports$3.gunung_segara = {
+ towgs84: '-403,684,41',
+ ellipse: 'bessel',
+ datumName: 'Gunung Segara Jakarta'
+ };
+
+ exports$3.rnb72 = {
+ towgs84: "106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",
+ ellipse: "intl",
+ datumName: "Reseau National Belge 1972"
+ };
+
+ function datum(datumCode, datum_params, a, b, es, ep2) {
+ var out = {};
+
+ if (datumCode === undefined || datumCode === 'none') {
+ out.datum_type = PJD_NODATUM;
+ } else {
+ out.datum_type = PJD_WGS84;
+ }
+
+ 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 (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;
+ }
+ }
+ }
+
+ out.a = a; //datum object also uses these values
+ out.b = b;
+ out.es = es;
+ out.ep2 = ep2;
+ return out;
+ }
+
+ function Projection$1(srsCode,callback) {
+ if (!(this instanceof Projection$1)) {
+ return new Projection$1(srsCode);
+ }
+ callback = callback || function(error){
+ if(error){
+ throw error;
+ }
+ };
+ var json = parse(srsCode);
+ if(typeof json !== 'object'){
+ callback(srsCode);
+ return;
+ }
+ var ourProj = Projection$1.projections.get(json.projName);
+ if(!ourProj){
+ callback(srsCode);
+ return;
+ }
+ if (json.datumCode && json.datumCode !== 'none') {
+ var datumDef = match(exports$3, 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_ = sphere(json.a, json.b, json.rf, json.ellps, json.sphere);
+ var ecc = 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);
+
+ }
+ Projection$1.projections = projections;
+ Projection$1.projections.start();
+
+ function compareDatums(source, dest) {
+ if (source.datum_type !== dest.datum_type) {
+ return false; // false, datums are not equal
+ } else if (source.a !== dest.a || Math.abs(source.es - dest.es) > 0.000000000050) {
+ // the tolerance for es is to ensure that GRS80 and WGS84
+ // are considered identical
+ return false;
+ } else if (source.datum_type === PJD_3PARAM) {
+ return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2]);
+ } else if (source.datum_type === PJD_7PARAM) {
+ return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2] && source.datum_params[3] === dest.datum_params[3] && source.datum_params[4] === dest.datum_params[4] && source.datum_params[5] === dest.datum_params[5] && source.datum_params[6] === dest.datum_params[6]);
+ } 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)
+ *
+ */
+ function geodeticToGeocentric(p, es, a) {
+ var Longitude = p.x;
+ var Latitude = p.y;
+ var Height = p.z ? p.z : 0; //Z value not always supplied
+
+ 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 = a / (Math.sqrt(1.0e0 - es * Sin2_Lat));
+ return {
+ x: (Rn + Height) * Cos_Lat * Math.cos(Longitude),
+ y: (Rn + Height) * Cos_Lat * Math.sin(Longitude),
+ z: ((Rn * (1 - es)) + Height) * Sin_Lat
+ };
+ } // cs_geodetic_to_geocentric()
+
+ function geocentricToGeodetic(p, es, a, b) {
+ /* 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 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;
+
+ P = Math.sqrt(X * X + Y * Y);
+ RR = Math.sqrt(X * X + Y * Y + Z * Z);
+
+ /* special cases for latitude and longitude */
+ if (P / a < genau) {
+
+ /* special case, if P=0. (X=0., Y=0.) */
+ 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 / a < genau) {
+ Latitude = HALF_PI;
+ Height = -b;
+ return {
+ x: p.x,
+ y: p.y,
+ z: p.z
+ };
+ }
+ } 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 - es * (2.0 - es) * ST * ST);
+ CPHI0 = ST * (1.0 - 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 = a / Math.sqrt(1.0 - es * SPHI0 * SPHI0);
+
+ /* ellipsoidal (geodetic) height */
+ Height = P * CPHI0 + Z * SPHI0 - RN * (1.0 - es * SPHI0 * SPHI0);
+
+ RK = 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));
+ return {
+ x: Longitude,
+ y: Latitude,
+ z: Height
+ };
+ } // cs_geocentric_to_geodetic()
+
+ /****************************************************************/
+ // pj_geocentic_to_wgs84( p )
+ // p = point to transform in geocentric coordinates (x,y,z)
+
+
+ /** 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.
+ */
+ function geocentricToWgs84(p, datum_type, datum_params) {
+
+ if (datum_type === PJD_3PARAM) {
+ // if( x[io] === HUGE_VAL )
+ // continue;
+ return {
+ x: p.x + datum_params[0],
+ y: p.y + datum_params[1],
+ z: p.z + datum_params[2],
+ };
+ } else if (datum_type === PJD_7PARAM) {
+ var Dx_BF = datum_params[0];
+ var Dy_BF = datum_params[1];
+ var Dz_BF = datum_params[2];
+ var Rx_BF = datum_params[3];
+ var Ry_BF = datum_params[4];
+ var Rz_BF = datum_params[5];
+ var M_BF = datum_params[6];
+ // if( x[io] === HUGE_VAL )
+ // continue;
+ return {
+ x: M_BF * (p.x - Rz_BF * p.y + Ry_BF * p.z) + Dx_BF,
+ y: M_BF * (Rz_BF * p.x + p.y - Rx_BF * p.z) + Dy_BF,
+ z: M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF
+ };
+ }
+ } // cs_geocentric_to_wgs84
+
+ /****************************************************************/
+ // pj_geocentic_from_wgs84()
+ // coordinate system definition,
+ // point to transform in geocentric coordinates (x,y,z)
+ function geocentricFromWgs84(p, datum_type, datum_params) {
+
+ if (datum_type === PJD_3PARAM) {
+ //if( x[io] === HUGE_VAL )
+ // continue;
+ return {
+ x: p.x - datum_params[0],
+ y: p.y - datum_params[1],
+ z: p.z - datum_params[2],
+ };
+
+ } else if (datum_type === PJD_7PARAM) {
+ var Dx_BF = datum_params[0];
+ var Dy_BF = datum_params[1];
+ var Dz_BF = datum_params[2];
+ var Rx_BF = datum_params[3];
+ var Ry_BF = datum_params[4];
+ var Rz_BF = datum_params[5];
+ var M_BF = 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;
+
+ return {
+ x: x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp,
+ y: -Rz_BF * x_tmp + y_tmp + Rx_BF * z_tmp,
+ z: Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp
+ };
+ } //cs_geocentric_from_wgs84()
+ }
+
+ function checkParams(type) {
+ return (type === PJD_3PARAM || type === PJD_7PARAM);
+ }
+
+ var datum_transform = function(source, dest, point) {
+ // Short cut if the datums are identical.
+ if (compareDatums(source, dest)) {
+ return point; // in this case, zero is sucess,
+ // whereas cs_compare_datums returns 1 to indicate TRUE
+ // confusing, should fix this
+ }
+
+ // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
+ if (source.datum_type === PJD_NODATUM || dest.datum_type === PJD_NODATUM) {
+ return point;
+ }
+
+ // If this datum requires grid shifts, then apply it to geodetic coordinates.
+
+ // 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;
+ }
+
+ // Convert to geocentric coordinates.
+ point = geodeticToGeocentric(point, source.es, source.a);
+ // Convert between datums
+ if (checkParams(source.datum_type)) {
+ point = geocentricToWgs84(point, source.datum_type, source.datum_params);
+ }
+ if (checkParams(dest.datum_type)) {
+ point = geocentricFromWgs84(point, dest.datum_type, dest.datum_params);
+ }
+ return geocentricToGeodetic(point, dest.es, dest.a, dest.b);
+
+ };
+
+ var adjust_axis = function(crs, denorm, point) {
+ var xin = point.x,
+ yin = point.y,
+ zin = point.z || 0.0;
+ var v, t, i;
+ var out = {};
+ for (i = 0; i < 3; i++) {
+ if (denorm && i === 2 && point.z === undefined) {
+ continue;
+ }
+ if (i === 0) {
+ v = xin;
+ t = 'x';
+ }
+ else if (i === 1) {
+ v = yin;
+ t = 'y';
+ }
+ else {
+ v = zin;
+ t = 'z';
+ }
+ switch (crs.axis[i]) {
+ case 'e':
+ out[t] = v;
+ break;
+ case 'w':
+ out[t] = -v;
+ break;
+ case 'n':
+ out[t] = v;
+ break;
+ case 's':
+ out[t] = -v;
+ break;
+ case 'u':
+ if (point[t] !== undefined) {
+ out.z = v;
+ }
+ break;
+ case 'd':
+ if (point[t] !== undefined) {
+ out.z = -v;
+ }
+ break;
+ default:
+ //console.log("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
+ return null;
+ }
+ }
+ return out;
+ };
+
+ var toPoint = function (array){
+ var out = {
+ x: array[0],
+ y: array[1]
+ };
+ if (array.length>2) {
+ out.z = array[2];
+ }
+ if (array.length>3) {
+ out.m = array[3];
+ }
+ return out;
+ };
+
+ 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');
+ }
+
+ function transform(source, dest, point) {
+ var wgs84;
+ if (Array.isArray(point)) {
+ point = toPoint(point);
+ }
+
+ // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
+ if (source.datum && dest.datum && checkNotWGS(source, dest)) {
+ wgs84 = new Projection$1('WGS84');
+ point = transform(source, wgs84, point);
+ source = wgs84;
+ }
+ // DGR, 2010/11/12
+ 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: point.x * D2R,
+ y: point.y * D2R
+ };
+ }
+ else {
+ if (source.to_meter) {
+ point = {
+ x: point.x * source.to_meter,
+ y: point.y * source.to_meter
+ };
+ }
+ point = source.inverse(point); // Convert Cartesian to longlat
+ }
+ // Adjust for the prime meridian if necessary
+ if (source.from_greenwich) {
+ point.x += source.from_greenwich;
+ }
+
+ // Convert datums if needed, and if possible.
+ point = datum_transform(source.datum, dest.datum, point);
+
+ // Adjust for the prime meridian if necessary
+ if (dest.from_greenwich) {
+ point = {
+ x: point.x - dest.from_greenwich,
+ y: point.y
+ };
+ }
+
+ if (dest.projName === 'longlat') {
+ // convert radians to decimal degrees
+ point = {
+ x: point.x * R2D,
+ y: point.y * R2D
+ };
+ } else { // else project
+ point = dest.forward(point);
+ if (dest.to_meter) {
+ point = {
+ x: point.x / dest.to_meter,
+ y: point.y / dest.to_meter
+ };
+ }
+ }
+
+ // DGR, 2010/11/12
+ if (dest.axis !== 'enu') {
+ return adjust_axis(dest, true, point);
+ }
+
+ return point;
+ }
+
+ var wgs84 = Projection$1('WGS84');
+
+ function transformer(from, to, coords) {
+ var transformedArray;
+ if (Array.isArray(coords)) {
+ transformedArray = transform(from, to, coords);
+ if (coords.length === 3) {
+ return [transformedArray.x, transformedArray.y, transformedArray.z];
+ }
+ else {
+ return [transformedArray.x, transformedArray.y];
+ }
+ }
+ else {
+ return transform(from, to, coords);
+ }
+ }
+
+ function checkProj(item) {
+ if (item instanceof Projection$1) {
+ return item;
+ }
+ if (item.oProj) {
+ return item.oProj;
+ }
+ return Projection$1(item);
+ }
+ function proj4$1(fromProj, toProj, coord) {
+ fromProj = checkProj(fromProj);
+ var single = false;
+ var obj;
+ if (typeof toProj === 'undefined') {
+ toProj = fromProj;
+ fromProj = wgs84;
+ single = true;
+ }
+ else if (typeof toProj.x !== 'undefined' || Array.isArray(toProj)) {
+ coord = toProj;
+ toProj = fromProj;
+ fromProj = wgs84;
+ single = true;
+ }
+ toProj = checkProj(toProj);
+ if (coord) {
+ return transformer(fromProj, toProj, coord);
+ }
+ else {
+ obj = {
+ forward: function(coords) {
+ return transformer(fromProj, toProj, coords);
+ },
+ inverse: function(coords) {
+ return transformer(toProj, fromProj, coords);
+ }
+ };
+ if (single) {
+ obj.oProj = toProj;
+ }
+ return obj;
+ }
+ }
+
+ /**
+ * UTM zones are grouped, and assigned to one of a group of 6
+ * sets.
+ *
+ * {int} @private
+ */
+ var NUM_100K_SETS = 6;
+
+ /**
+ * The column letters (for easting) of the lower left value, per
+ * set.
+ *
+ * {string} @private
+ */
+ var SET_ORIGIN_COLUMN_LETTERS = 'AJSAJS';
+
+ /**
+ * The row letters (for northing) of the lower left value, per
+ * set.
+ *
+ * {string} @private
+ */
+ var SET_ORIGIN_ROW_LETTERS = 'AFAFAF';
+
+ var A = 65; // A
+ var I = 73; // I
+ var O = 79; // O
+ var V = 86; // V
+ var Z = 90; // Z
+ var mgrs = {
+ forward: forward$1,
+ inverse: inverse$1,
+ toPoint: toPoint$1
+ };
+ /**
+ * Conversion of lat/lon to MGRS.
+ *
+ * @param {object} ll Object literal with lat and lon properties on a
+ * WGS84 ellipsoid.
+ * @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for
+ * 100 m, 2 for 1000 m or 1 for 10000 m). Optional, default is 5.
+ * @return {string} the MGRS string for the given location and accuracy.
+ */
+ function forward$1(ll, accuracy) {
+ accuracy = accuracy || 5; // default accuracy 1m
+ return encode(LLtoUTM({
+ lat: ll[1],
+ lon: ll[0]
+ }), accuracy);
+ }
+
+ /**
+ * Conversion of MGRS to lat/lon.
+ *
+ * @param {string} mgrs MGRS string.
+ * @return {array} An array with left (longitude), bottom (latitude), right
+ * (longitude) and top (latitude) values in WGS84, representing the
+ * bounding box for the provided MGRS reference.
+ */
+ function inverse$1(mgrs) {
+ var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
+ if (bbox.lat && bbox.lon) {
+ return [bbox.lon, bbox.lat, bbox.lon, bbox.lat];
+ }
+ return [bbox.left, bbox.bottom, bbox.right, bbox.top];
+ }
+
+ function toPoint$1(mgrs) {
+ var bbox = UTMtoLL(decode(mgrs.toUpperCase()));
+ if (bbox.lat && bbox.lon) {
+ return [bbox.lon, bbox.lat];
+ }
+ return [(bbox.left + bbox.right) / 2, (bbox.top + bbox.bottom) / 2];
+ }
+ /**
+ * Conversion from degrees to radians.
+ *
+ * @private
+ * @param {number} deg the angle in degrees.
+ * @return {number} the angle in radians.
+ */
+ function degToRad(deg) {
+ return (deg * (Math.PI / 180.0));
+ }
+
+ /**
+ * Conversion from radians to degrees.
+ *
+ * @private
+ * @param {number} rad the angle in radians.
+ * @return {number} the angle in degrees.
+ */
+ function radToDeg(rad) {
+ return (180.0 * (rad / Math.PI));
+ }
+
+ /**
+ * Converts a set of Longitude and Latitude co-ordinates to UTM
+ * using the WGS84 ellipsoid.
+ *
+ * @private
+ * @param {object} ll Object literal with lat and lon properties
+ * representing the WGS84 coordinate to be converted.
+ * @return {object} Object literal containing the UTM value with easting,
+ * northing, zoneNumber and zoneLetter properties, and an optional
+ * accuracy property in digits. Returns null if the conversion failed.
+ */
+ function LLtoUTM(ll) {
+ var Lat = ll.lat;
+ var Long = ll.lon;
+ var a = 6378137.0; //ellip.radius;
+ var eccSquared = 0.00669438; //ellip.eccsq;
+ var k0 = 0.9996;
+ var LongOrigin;
+ var eccPrimeSquared;
+ var N, T, C, A, M;
+ var LatRad = degToRad(Lat);
+ var LongRad = degToRad(Long);
+ var LongOriginRad;
+ var ZoneNumber;
+ // (int)
+ ZoneNumber = Math.floor((Long + 180) / 6) + 1;
+
+ //Make sure the longitude 180.00 is in Zone 60
+ if (Long === 180) {
+ ZoneNumber = 60;
+ }
+
+ // Special zone for Norway
+ if (Lat >= 56.0 && Lat < 64.0 && Long >= 3.0 && Long < 12.0) {
+ ZoneNumber = 32;
+ }
+
+ // Special zones for Svalbard
+ if (Lat >= 72.0 && Lat < 84.0) {
+ if (Long >= 0.0 && Long < 9.0) {
+ ZoneNumber = 31;
+ }
+ else if (Long >= 9.0 && Long < 21.0) {
+ ZoneNumber = 33;
+ }
+ else if (Long >= 21.0 && Long < 33.0) {
+ ZoneNumber = 35;
+ }
+ else if (Long >= 33.0 && Long < 42.0) {
+ ZoneNumber = 37;
+ }
+ }
+
+ LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin
+ // in middle of
+ // zone
+ LongOriginRad = degToRad(LongOrigin);
+
+ eccPrimeSquared = (eccSquared) / (1 - eccSquared);
+
+ N = a / Math.sqrt(1 - eccSquared * Math.sin(LatRad) * Math.sin(LatRad));
+ T = Math.tan(LatRad) * Math.tan(LatRad);
+ C = eccPrimeSquared * Math.cos(LatRad) * Math.cos(LatRad);
+ A = Math.cos(LatRad) * (LongRad - LongOriginRad);
+
+ M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(2 * LatRad) + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.sin(4 * LatRad) - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.sin(6 * LatRad));
+
+ var UTMEasting = (k0 * N * (A + (1 - T + C) * A * A * A / 6.0 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120.0) + 500000.0);
+
+ var UTMNorthing = (k0 * (M + N * Math.tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24.0 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720.0)));
+ if (Lat < 0.0) {
+ UTMNorthing += 10000000.0; //10000000 meter offset for
+ // southern hemisphere
+ }
+
+ return {
+ northing: Math.round(UTMNorthing),
+ easting: Math.round(UTMEasting),
+ zoneNumber: ZoneNumber,
+ zoneLetter: getLetterDesignator(Lat)
+ };
+ }
+
+ /**
+ * Converts UTM coords to lat/long, using the WGS84 ellipsoid. This is a convenience
+ * class where the Zone can be specified as a single string eg."60N" which
+ * is then broken down into the ZoneNumber and ZoneLetter.
+ *
+ * @private
+ * @param {object} utm An object literal with northing, easting, zoneNumber
+ * and zoneLetter properties. If an optional accuracy property is
+ * provided (in meters), a bounding box will be returned instead of
+ * latitude and longitude.
+ * @return {object} An object literal containing either lat and lon values
+ * (if no accuracy was provided), or top, right, bottom and left values
+ * for the bounding box calculated according to the provided accuracy.
+ * Returns null if the conversion failed.
+ */
+ function UTMtoLL(utm) {
+
+ var UTMNorthing = utm.northing;
+ var UTMEasting = utm.easting;
+ var zoneLetter = utm.zoneLetter;
+ var zoneNumber = utm.zoneNumber;
+ // check the ZoneNummber is valid
+ if (zoneNumber < 0 || zoneNumber > 60) {
+ return null;
+ }
+
+ var k0 = 0.9996;
+ var a = 6378137.0; //ellip.radius;
+ var eccSquared = 0.00669438; //ellip.eccsq;
+ var eccPrimeSquared;
+ var e1 = (1 - Math.sqrt(1 - eccSquared)) / (1 + Math.sqrt(1 - eccSquared));
+ var N1, T1, C1, R1, D, M;
+ var LongOrigin;
+ var mu, phi1Rad;
+
+ // remove 500,000 meter offset for longitude
+ var x = UTMEasting - 500000.0;
+ var y = UTMNorthing;
+
+ // We must know somehow if we are in the Northern or Southern
+ // hemisphere, this is the only time we use the letter So even
+ // if the Zone letter isn't exactly correct it should indicate
+ // the hemisphere correctly
+ if (zoneLetter < 'N') {
+ y -= 10000000.0; // remove 10,000,000 meter offset used
+ // for southern hemisphere
+ }
+
+ // There are 60 zones with zone 1 being at West -180 to -174
+ LongOrigin = (zoneNumber - 1) * 6 - 180 + 3; // +3 puts origin
+ // in middle of
+ // zone
+
+ eccPrimeSquared = (eccSquared) / (1 - eccSquared);
+
+ M = y / k0;
+ mu = M / (a * (1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256));
+
+ phi1Rad = mu + (3 * e1 / 2 - 27 * e1 * e1 * e1 / 32) * Math.sin(2 * mu) + (21 * e1 * e1 / 16 - 55 * e1 * e1 * e1 * e1 / 32) * Math.sin(4 * mu) + (151 * e1 * e1 * e1 / 96) * Math.sin(6 * mu);
+ // double phi1 = ProjMath.radToDeg(phi1Rad);
+
+ N1 = a / Math.sqrt(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad));
+ T1 = Math.tan(phi1Rad) * Math.tan(phi1Rad);
+ C1 = eccPrimeSquared * Math.cos(phi1Rad) * Math.cos(phi1Rad);
+ R1 = a * (1 - eccSquared) / Math.pow(1 - eccSquared * Math.sin(phi1Rad) * Math.sin(phi1Rad), 1.5);
+ D = x / (N1 * k0);
+
+ var lat = phi1Rad - (N1 * Math.tan(phi1Rad) / R1) * (D * D / 2 - (5 + 3 * T1 + 10 * C1 - 4 * C1 * C1 - 9 * eccPrimeSquared) * D * D * D * D / 24 + (61 + 90 * T1 + 298 * C1 + 45 * T1 * T1 - 252 * eccPrimeSquared - 3 * C1 * C1) * D * D * D * D * D * D / 720);
+ lat = radToDeg(lat);
+
+ var lon = (D - (1 + 2 * T1 + C1) * D * D * D / 6 + (5 - 2 * C1 + 28 * T1 - 3 * C1 * C1 + 8 * eccPrimeSquared + 24 * T1 * T1) * D * D * D * D * D / 120) / Math.cos(phi1Rad);
+ lon = LongOrigin + radToDeg(lon);
+
+ var result;
+ if (utm.accuracy) {
+ var topRight = UTMtoLL({
+ northing: utm.northing + utm.accuracy,
+ easting: utm.easting + utm.accuracy,
+ zoneLetter: utm.zoneLetter,
+ zoneNumber: utm.zoneNumber
+ });
+ result = {
+ top: topRight.lat,
+ right: topRight.lon,
+ bottom: lat,
+ left: lon
+ };
+ }
+ else {
+ result = {
+ lat: lat,
+ lon: lon
+ };
+ }
+ return result;
+ }
+
+ /**
+ * Calculates the MGRS letter designator for the given latitude.
+ *
+ * @private
+ * @param {number} lat The latitude in WGS84 to get the letter designator
+ * for.
+ * @return {char} The letter designator.
+ */
+ function getLetterDesignator(lat) {
+ //This is here as an error flag to show that the Latitude is
+ //outside MGRS limits
+ var LetterDesignator = 'Z';
+
+ if ((84 >= lat) && (lat >= 72)) {
+ LetterDesignator = 'X';
+ }
+ else if ((72 > lat) && (lat >= 64)) {
+ LetterDesignator = 'W';
+ }
+ else if ((64 > lat) && (lat >= 56)) {
+ LetterDesignator = 'V';
+ }
+ else if ((56 > lat) && (lat >= 48)) {
+ LetterDesignator = 'U';
+ }
+ else if ((48 > lat) && (lat >= 40)) {
+ LetterDesignator = 'T';
+ }
+ else if ((40 > lat) && (lat >= 32)) {
+ LetterDesignator = 'S';
+ }
+ else if ((32 > lat) && (lat >= 24)) {
+ LetterDesignator = 'R';
+ }
+ else if ((24 > lat) && (lat >= 16)) {
+ LetterDesignator = 'Q';
+ }
+ else if ((16 > lat) && (lat >= 8)) {
+ LetterDesignator = 'P';
+ }
+ else if ((8 > lat) && (lat >= 0)) {
+ LetterDesignator = 'N';
+ }
+ else if ((0 > lat) && (lat >= -8)) {
+ LetterDesignator = 'M';
+ }
+ else if ((-8 > lat) && (lat >= -16)) {
+ LetterDesignator = 'L';
+ }
+ else if ((-16 > lat) && (lat >= -24)) {
+ LetterDesignator = 'K';
+ }
+ else if ((-24 > lat) && (lat >= -32)) {
+ LetterDesignator = 'J';
+ }
+ else if ((-32 > lat) && (lat >= -40)) {
+ LetterDesignator = 'H';
+ }
+ else if ((-40 > lat) && (lat >= -48)) {
+ LetterDesignator = 'G';
+ }
+ else if ((-48 > lat) && (lat >= -56)) {
+ LetterDesignator = 'F';
+ }
+ else if ((-56 > lat) && (lat >= -64)) {
+ LetterDesignator = 'E';
+ }
+ else if ((-64 > lat) && (lat >= -72)) {
+ LetterDesignator = 'D';
+ }
+ else if ((-72 > lat) && (lat >= -80)) {
+ LetterDesignator = 'C';
+ }
+ return LetterDesignator;
+ }
+
+ /**
+ * Encodes a UTM location as MGRS string.
+ *
+ * @private
+ * @param {object} utm An object literal with easting, northing,
+ * zoneLetter, zoneNumber
+ * @param {number} accuracy Accuracy in digits (1-5).
+ * @return {string} MGRS string for the given UTM location.
+ */
+ function encode(utm, accuracy) {
+ // prepend with leading zeroes
+ var seasting = "00000" + utm.easting,
+ snorthing = "00000" + utm.northing;
+
+ return utm.zoneNumber + utm.zoneLetter + get100kID(utm.easting, utm.northing, utm.zoneNumber) + seasting.substr(seasting.length - 5, accuracy) + snorthing.substr(snorthing.length - 5, accuracy);
+ }
+
+ /**
+ * Get the two letter 100k designator for a given UTM easting,
+ * northing and zone number value.
+ *
+ * @private
+ * @param {number} easting
+ * @param {number} northing
+ * @param {number} zoneNumber
+ * @return the two letter 100k designator for the given UTM location.
+ */
+ function get100kID(easting, northing, zoneNumber) {
+ var setParm = get100kSetForZone(zoneNumber);
+ var setColumn = Math.floor(easting / 100000);
+ var setRow = Math.floor(northing / 100000) % 20;
+ return getLetter100kID(setColumn, setRow, setParm);
+ }
+
+ /**
+ * Given a UTM zone number, figure out the MGRS 100K set it is in.
+ *
+ * @private
+ * @param {number} i An UTM zone number.
+ * @return {number} the 100k set the UTM zone is in.
+ */
+ function get100kSetForZone(i) {
+ var setParm = i % NUM_100K_SETS;
+ if (setParm === 0) {
+ setParm = NUM_100K_SETS;
+ }
+
+ return setParm;
+ }
+
+ /**
+ * Get the two-letter MGRS 100k designator given information
+ * translated from the UTM northing, easting and zone number.
+ *
+ * @private
+ * @param {number} column the column index as it relates to the MGRS
+ * 100k set spreadsheet, created from the UTM easting.
+ * Values are 1-8.
+ * @param {number} row the row index as it relates to the MGRS 100k set
+ * spreadsheet, created from the UTM northing value. Values
+ * are from 0-19.
+ * @param {number} parm the set block, as it relates to the MGRS 100k set
+ * spreadsheet, created from the UTM zone. Values are from
+ * 1-60.
+ * @return two letter MGRS 100k code.
+ */
+ function getLetter100kID(column, row, parm) {
+ // colOrigin and rowOrigin are the letters at the origin of the set
+ var index = parm - 1;
+ var colOrigin = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(index);
+ var rowOrigin = SET_ORIGIN_ROW_LETTERS.charCodeAt(index);
+
+ // colInt and rowInt are the letters to build to return
+ var colInt = colOrigin + column - 1;
+ var rowInt = rowOrigin + row;
+ var rollover = false;
+
+ if (colInt > Z) {
+ colInt = colInt - Z + A - 1;
+ rollover = true;
+ }
+
+ if (colInt === I || (colOrigin < I && colInt > I) || ((colInt > I || colOrigin < I) && rollover)) {
+ colInt++;
+ }
+
+ if (colInt === O || (colOrigin < O && colInt > O) || ((colInt > O || colOrigin < O) && rollover)) {
+ colInt++;
+
+ if (colInt === I) {
+ colInt++;
+ }
+ }
+
+ if (colInt > Z) {
+ colInt = colInt - Z + A - 1;
+ }
+
+ if (rowInt > V) {
+ rowInt = rowInt - V + A - 1;
+ rollover = true;
+ }
+ else {
+ rollover = false;
+ }
+
+ if (((rowInt === I) || ((rowOrigin < I) && (rowInt > I))) || (((rowInt > I) || (rowOrigin < I)) && rollover)) {
+ rowInt++;
+ }
+
+ if (((rowInt === O) || ((rowOrigin < O) && (rowInt > O))) || (((rowInt > O) || (rowOrigin < O)) && rollover)) {
+ rowInt++;
+
+ if (rowInt === I) {
+ rowInt++;
+ }
+ }
+
+ if (rowInt > V) {
+ rowInt = rowInt - V + A - 1;
+ }
+
+ var twoLetter = String.fromCharCode(colInt) + String.fromCharCode(rowInt);
+ return twoLetter;
+ }
+
+ /**
+ * Decode the UTM parameters from a MGRS string.
+ *
+ * @private
+ * @param {string} mgrsString an UPPERCASE coordinate string is expected.
+ * @return {object} An object literal with easting, northing, zoneLetter,
+ * zoneNumber and accuracy (in meters) properties.
+ */
+ function decode(mgrsString) {
+
+ if (mgrsString && mgrsString.length === 0) {
+ throw ("MGRSPoint coverting from nothing");
+ }
+
+ var length = mgrsString.length;
+
+ var hunK = null;
+ var sb = "";
+ var testChar;
+ var i = 0;
+
+ // get Zone number
+ while (!(/[A-Z]/).test(testChar = mgrsString.charAt(i))) {
+ if (i >= 2) {
+ throw ("MGRSPoint bad conversion from: " + mgrsString);
+ }
+ sb += testChar;
+ i++;
+ }
+
+ var zoneNumber = parseInt(sb, 10);
+
+ if (i === 0 || i + 3 > length) {
+ // A good MGRS string has to be 4-5 digits long,
+ // ##AAA/#AAA at least.
+ throw ("MGRSPoint bad conversion from: " + mgrsString);
+ }
+
+ var zoneLetter = mgrsString.charAt(i++);
+
+ // Should we check the zone letter here? Why not.
+ if (zoneLetter <= 'A' || zoneLetter === 'B' || zoneLetter === 'Y' || zoneLetter >= 'Z' || zoneLetter === 'I' || zoneLetter === 'O') {
+ throw ("MGRSPoint zone letter " + zoneLetter + " not handled: " + mgrsString);
+ }
+
+ hunK = mgrsString.substring(i, i += 2);
+
+ var set = get100kSetForZone(zoneNumber);
+
+ var east100k = getEastingFromChar(hunK.charAt(0), set);
+ var north100k = getNorthingFromChar(hunK.charAt(1), set);
+
+ // We have a bug where the northing may be 2000000 too low.
+ // How
+ // do we know when to roll over?
+
+ while (north100k < getMinNorthing(zoneLetter)) {
+ north100k += 2000000;
+ }
+
+ // calculate the char index for easting/northing separator
+ var remainder = length - i;
+
+ if (remainder % 2 !== 0) {
+ throw ("MGRSPoint has to have an even number \nof digits after the zone letter and two 100km letters - front \nhalf for easting meters, second half for \nnorthing meters" + mgrsString);
+ }
+
+ var sep = remainder / 2;
+
+ var sepEasting = 0.0;
+ var sepNorthing = 0.0;
+ var accuracyBonus, sepEastingString, sepNorthingString, easting, northing;
+ if (sep > 0) {
+ accuracyBonus = 100000.0 / Math.pow(10, sep);
+ sepEastingString = mgrsString.substring(i, i + sep);
+ sepEasting = parseFloat(sepEastingString) * accuracyBonus;
+ sepNorthingString = mgrsString.substring(i + sep);
+ sepNorthing = parseFloat(sepNorthingString) * accuracyBonus;
+ }
+
+ easting = sepEasting + east100k;
+ northing = sepNorthing + north100k;
+
+ return {
+ easting: easting,
+ northing: northing,
+ zoneLetter: zoneLetter,
+ zoneNumber: zoneNumber,
+ accuracy: accuracyBonus
+ };
+ }
+
+ /**
+ * Given the first letter from a two-letter MGRS 100k zone, and given the
+ * MGRS table set for the zone number, figure out the easting value that
+ * should be added to the other, secondary easting value.
+ *
+ * @private
+ * @param {char} e The first letter from a two-letter MGRS 100´k zone.
+ * @param {number} set The MGRS table set for the zone number.
+ * @return {number} The easting value for the given letter and set.
+ */
+ function getEastingFromChar(e, set) {
+ // colOrigin is the letter at the origin of the set for the
+ // column
+ var curCol = SET_ORIGIN_COLUMN_LETTERS.charCodeAt(set - 1);
+ var eastingValue = 100000.0;
+ var rewindMarker = false;
+
+ while (curCol !== e.charCodeAt(0)) {
+ curCol++;
+ if (curCol === I) {
+ curCol++;
+ }
+ if (curCol === O) {
+ curCol++;
+ }
+ if (curCol > Z) {
+ if (rewindMarker) {
+ throw ("Bad character: " + e);
+ }
+ curCol = A;
+ rewindMarker = true;
+ }
+ eastingValue += 100000.0;
+ }
+
+ return eastingValue;
+ }
+
+ /**
+ * Given the second letter from a two-letter MGRS 100k zone, and given the
+ * MGRS table set for the zone number, figure out the northing value that
+ * should be added to the other, secondary northing value. You have to
+ * remember that Northings are determined from the equator, and the vertical
+ * cycle of letters mean a 2000000 additional northing meters. This happens
+ * approx. every 18 degrees of latitude. This method does *NOT* count any
+ * additional northings. You have to figure out how many 2000000 meters need
+ * to be added for the zone letter of the MGRS coordinate.
+ *
+ * @private
+ * @param {char} n Second letter of the MGRS 100k zone
+ * @param {number} set The MGRS table set number, which is dependent on the
+ * UTM zone number.
+ * @return {number} The northing value for the given letter and set.
+ */
+ function getNorthingFromChar(n, set) {
+
+ if (n > 'V') {
+ throw ("MGRSPoint given invalid Northing " + n);
+ }
+
+ // rowOrigin is the letter at the origin of the set for the
+ // column
+ var curRow = SET_ORIGIN_ROW_LETTERS.charCodeAt(set - 1);
+ var northingValue = 0.0;
+ var rewindMarker = false;
+
+ while (curRow !== n.charCodeAt(0)) {
+ curRow++;
+ if (curRow === I) {
+ curRow++;
+ }
+ if (curRow === O) {
+ curRow++;
+ }
+ // fixing a bug making whole application hang in this loop
+ // when 'n' is a wrong character
+ if (curRow > V) {
+ if (rewindMarker) { // making sure that this loop ends
+ throw ("Bad character: " + n);
+ }
+ curRow = A;
+ rewindMarker = true;
+ }
+ northingValue += 100000.0;
+ }
+
+ return northingValue;
+ }
+
+ /**
+ * The function getMinNorthing returns the minimum northing value of a MGRS
+ * zone.
+ *
+ * Ported from Geotrans' c Lattitude_Band_Value structure table.
+ *
+ * @private
+ * @param {char} zoneLetter The MGRS zone to get the min northing for.
+ * @return {number}
+ */
+ function getMinNorthing(zoneLetter) {
+ var northing;
+ switch (zoneLetter) {
+ case 'C':
+ northing = 1100000.0;
+ break;
+ case 'D':
+ northing = 2000000.0;
+ break;
+ case 'E':
+ northing = 2800000.0;
+ break;
+ case 'F':
+ northing = 3700000.0;
+ break;
+ case 'G':
+ northing = 4600000.0;
+ break;
+ case 'H':
+ northing = 5500000.0;
+ break;
+ case 'J':
+ northing = 6400000.0;
+ break;
+ case 'K':
+ northing = 7300000.0;
+ break;
+ case 'L':
+ northing = 8200000.0;
+ break;
+ case 'M':
+ northing = 9100000.0;
+ break;
+ case 'N':
+ northing = 0.0;
+ break;
+ case 'P':
+ northing = 800000.0;
+ break;
+ case 'Q':
+ northing = 1700000.0;
+ break;
+ case 'R':
+ northing = 2600000.0;
+ break;
+ case 'S':
+ northing = 3500000.0;
+ break;
+ case 'T':
+ northing = 4400000.0;
+ break;
+ case 'U':
+ northing = 5300000.0;
+ break;
+ case 'V':
+ northing = 6200000.0;
+ break;
+ case 'W':
+ northing = 7000000.0;
+ break;
+ case 'X':
+ northing = 7900000.0;
+ break;
+ default:
+ northing = -1.0;
+ }
+ if (northing >= 0.0) {
+ return northing;
+ }
+ else {
+ throw ("Invalid zone letter: " + zoneLetter);
+ }
+
+ }
+
+ function Point(x, y, z) {
+ if (!(this instanceof Point)) {
+ return new Point(x, y, z);
+ }
+ if (Array.isArray(x)) {
+ this.x = x[0];
+ this.y = x[1];
+ this.z = x[2] || 0.0;
+ } else if(typeof x === 'object') {
+ this.x = x.x;
+ this.y = x.y;
+ this.z = x.z || 0.0;
+ } else if (typeof x === 'string' && typeof y === 'undefined') {
+ var coords = x.split(',');
+ this.x = parseFloat(coords[0], 10);
+ this.y = parseFloat(coords[1], 10);
+ this.z = parseFloat(coords[2], 10) || 0.0;
+ } else {
+ this.x = x;
+ this.y = y;
+ this.z = z || 0.0;
+ }
+ console.warn('proj4.Point will be removed in version 3, use proj4.toPoint');
+ }
+
+ Point.fromMGRS = function(mgrsStr) {
+ return new Point(toPoint$1(mgrsStr));
+ };
+ Point.prototype.toMGRS = function(accuracy) {
+ return forward$1([this.x, this.y], accuracy);
+ };
+
+ var version = "2.4.0";
+
+ var C00 = 1;
+ var C02 = 0.25;
+ var C04 = 0.046875;
+ var C06 = 0.01953125;
+ var C08 = 0.01068115234375;
+ var C22 = 0.75;
+ var C44 = 0.46875;
+ var C46 = 0.01302083333333333333;
+ var C48 = 0.00712076822916666666;
+ var C66 = 0.36458333333333333333;
+ var C68 = 0.00569661458333333333;
+ var C88 = 0.3076171875;
+
+ var pj_enfn = function(es) {
+ var en = [];
+ en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
+ en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
+ var t = es * es;
+ en[2] = t * (C44 - es * (C46 + es * C48));
+ t *= es;
+ en[3] = t * (C66 - es * C68);
+ en[4] = t * es * C88;
+ return en;
+ };
+
+ var pj_mlfn = function(phi, sphi, cphi, en) {
+ cphi *= sphi;
+ sphi *= sphi;
+ return (en[0] * phi - cphi * (en[1] + sphi * (en[2] + sphi * (en[3] + sphi * en[4]))));
+ };
+
+ var MAX_ITER = 20;
+
+ var pj_inv_mlfn = function(arg, es, en) {
+ var k = 1 / (1 - es);
+ var phi = arg;
+ for (var i = MAX_ITER; i; --i) { /* rarely goes over 2 iterations */
+ var s = Math.sin(phi);
+ var t = 1 - es * s * s;
+ //t = this.pj_mlfn(phi, s, Math.cos(phi), en) - arg;
+ //phi -= t * (t * Math.sqrt(t)) * k;
+ t = (pj_mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
+ phi -= t;
+ if (Math.abs(t) < EPSLN) {
+ return phi;
+ }
+ }
+ //..reportError("cass:pj_inv_mlfn: Convergence error");
+ return phi;
+ };
+
+ // Heavily based on this tmerc projection implementation
+ // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/tmerc.js
+
+ function init$2() {
+ 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);
+ }
+ }
+
+ /**
+ Transverse Mercator Forward - long/lat to x/y
+ long/lat in radians
+ */
+ function forward$2(p) {
+ var lon = p.x;
+ var lat = p.y;
+
+ var delta_lon = adjust_lon(lon - this.long0);
+ var con;
+ var x, y;
+ var sin_phi = Math.sin(lat);
+ var cos_phi = Math.cos(lat);
+
+ if (!this.es) {
+ var b = cos_phi * Math.sin(delta_lon);
+
+ if ((Math.abs(Math.abs(b) - 1)) < EPSLN) {
+ return (93);
+ }
+ else {
+ 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) {
+ y = -y;
+ }
+
+ y = this.a * this.k0 * (y - this.lat0) + this.y0;
+ }
+ }
+ else {
+ var al = cos_phi * delta_lon;
+ var als = Math.pow(al, 2);
+ var c = this.ep2 * Math.pow(cos_phi, 2);
+ 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);
+ al = al / Math.sqrt(con);
+ var ml = pj_mlfn(lat, sin_phi, cos_phi, this.en);
+
+ 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;
+ }
+
+ /**
+ Transverse Mercator Inverse - x/y to long/lat
+ */
+ function inverse$2(p) {
+ var con, phi;
+ var lat, lon;
+ var x = (p.x - this.x0) * (1 / this.a);
+ var y = (p.y - this.y0) * (1 / this.a);
+
+ if (!this.es) {
+ var f = Math.exp(x / this.k0);
+ var g = 0.5 * (f - 1 / f);
+ var temp = this.lat0 + y / this.k0;
+ var h = Math.cos(temp);
+ 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 = 0;
+ }
+ else {
+ lon = adjust_lon(Math.atan2(g, h) + this.long0);
+ }
+ }
+ else { // ellipsoidal form
+ con = this.ml0 + y / this.k0;
+ phi = pj_inv_mlfn(con, this.es, this.en);
+
+ if (Math.abs(phi) < HALF_PI) {
+ var sin_phi = Math.sin(phi);
+ var cos_phi = Math.cos(phi);
+ var tan_phi = Math.abs(cos_phi) > EPSLN ? Math.tan(phi) : 0;
+ var c = this.ep2 * Math.pow(cos_phi, 2);
+ var cs = Math.pow(c, 2);
+ var t = Math.pow(tan_phi, 2);
+ var ts = Math.pow(t, 2);
+ con = 1 - this.es * Math.pow(sin_phi, 2);
+ var d = x * Math.sqrt(con) / this.k0;
+ var ds = Math.pow(d, 2);
+ 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 = 0;
+ }
+ }
+
+ p.x = lon;
+ p.y = lat;
+
+ return p;
+ }
+
+ var names$3 = ["Transverse_Mercator", "Transverse Mercator", "tmerc"];
+ var tmerc = {
+ init: init$2,
+ forward: forward$2,
+ inverse: inverse$2,
+ names: names$3
+ };
+
+ var sinh = function(x) {
+ var r = Math.exp(x);
+ r = (r - 1 / r) / 2;
+ return r;
+ };
+
+ var hypot = function(x, y) {
+ x = Math.abs(x);
+ y = Math.abs(y);
+ var a = Math.max(x, y);
+ var b = Math.min(x, y) / (a ? a : 1);
+
+ return a * Math.sqrt(1 + Math.pow(b, 2));
+ };
+
+ var log1py = function(x) {
+ var y = 1 + x;
+ var z = y - 1;
+
+ return z === 0 ? x : x * Math.log(y) / z;
+ };
+
+ var asinhy = function(x) {
+ var y = Math.abs(x);
+ y = log1py(y * (1 + y / (hypot(1, y) + 1)));
+
+ return x < 0 ? -y : y;
+ };
+
+ var gatg = function(pp, B) {
+ var cos_2B = 2 * Math.cos(2 * B);
+ var i = pp.length - 1;
+ var h1 = pp[i];
+ var h2 = 0;
+ var h;
+
+ while (--i >= 0) {
+ h = -h2 + cos_2B * h1 + pp[i];
+ h2 = h1;
+ h1 = h;
+ }
+
+ return (B + h * Math.sin(2 * B));
+ };
+
+ var clens = function(pp, arg_r) {
+ var r = 2 * Math.cos(arg_r);
+ var i = pp.length - 1;
+ var hr1 = pp[i];
+ var hr2 = 0;
+ var hr;
+
+ while (--i >= 0) {
+ hr = -hr2 + r * hr1 + pp[i];
+ hr2 = hr1;
+ hr1 = hr;
+ }
+
+ return Math.sin(arg_r) * hr;
+ };
+
+ var cosh = function(x) {
+ var r = Math.exp(x);
+ r = (r + 1 / r) / 2;
+ return r;
+ };
+
+ var clens_cmplx = function(pp, arg_r, arg_i) {
+ var sin_arg_r = Math.sin(arg_r);
+ var cos_arg_r = Math.cos(arg_r);
+ var sinh_arg_i = sinh(arg_i);
+ var cosh_arg_i = cosh(arg_i);
+ var r = 2 * cos_arg_r * cosh_arg_i;
+ var i = -2 * sin_arg_r * sinh_arg_i;
+ var j = pp.length - 1;
+ var hr = pp[j];
+ var hi1 = 0;
+ var hr1 = 0;
+ var hi = 0;
+ var hr2;
+ var hi2;
+
+ while (--j >= 0) {
+ hr2 = hr1;
+ hi2 = hi1;
+ hr1 = hr;
+ hi1 = hi;
+ hr = -hr2 + r * hr1 - i * hi1 + pp[j];
+ hi = -hi2 + i * hr1 + r * hi1;
+ }
+
+ r = sin_arg_r * cosh_arg_i;
+ i = cos_arg_r * sinh_arg_i;
+
+ return [r * hr - i * hi, r * hi + i * hr];
+ };
+
+ // Heavily based on this etmerc projection implementation
+ // https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/etmerc.js
+
+ function init$3() {
+ if (this.es === undefined || this.es <= 0) {
+ throw new Error('incorrect elliptical usage');
+ }
+
+ 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;
+
+ this.cgb = [];
+ this.cbg = [];
+ this.utg = [];
+ this.gtu = [];
+
+ var f = this.es / (1 + Math.sqrt(1 - this.es));
+ var n = f / (2 - f);
+ var np = n;
+
+ this.cgb[0] = n * (2 + n * (-2 / 3 + n * (-2 + n * (116 / 45 + n * (26 / 45 + n * (-2854 / 675 ))))));
+ this.cbg[0] = n * (-2 + n * ( 2 / 3 + n * ( 4 / 3 + n * (-82 / 45 + n * (32 / 45 + n * (4642 / 4725))))));
+
+ np = np * n;
+ this.cgb[1] = np * (7 / 3 + n * (-8 / 5 + n * (-227 / 45 + n * (2704 / 315 + n * (2323 / 945)))));
+ this.cbg[1] = np * (5 / 3 + n * (-16 / 15 + n * ( -13 / 9 + n * (904 / 315 + n * (-1522 / 945)))));
+
+ np = np * n;
+ this.cgb[2] = np * (56 / 15 + n * (-136 / 35 + n * (-1262 / 105 + n * (73814 / 2835))));
+ this.cbg[2] = np * (-26 / 15 + n * (34 / 21 + n * (8 / 5 + n * (-12686 / 2835))));
+
+ np = np * n;
+ this.cgb[3] = np * (4279 / 630 + n * (-332 / 35 + n * (-399572 / 14175)));
+ this.cbg[3] = np * (1237 / 630 + n * (-12 / 5 + n * ( -24832 / 14175)));
+
+ np = np * n;
+ this.cgb[4] = np * (4174 / 315 + n * (-144838 / 6237));
+ this.cbg[4] = np * (-734 / 315 + n * (109598 / 31185));
+
+ np = np * n;
+ this.cgb[5] = np * (601676 / 22275);
+ this.cbg[5] = np * (444337 / 155925);
+
+ np = Math.pow(n, 2);
+ this.Qn = this.k0 / (1 + n) * (1 + np * (1 / 4 + np * (1 / 64 + np / 256)));
+
+ this.utg[0] = n * (-0.5 + n * ( 2 / 3 + n * (-37 / 96 + n * ( 1 / 360 + n * (81 / 512 + n * (-96199 / 604800))))));
+ this.gtu[0] = n * (0.5 + n * (-2 / 3 + n * (5 / 16 + n * (41 / 180 + n * (-127 / 288 + n * (7891 / 37800))))));
+
+ this.utg[1] = np * (-1 / 48 + n * (-1 / 15 + n * (437 / 1440 + n * (-46 / 105 + n * (1118711 / 3870720)))));
+ this.gtu[1] = np * (13 / 48 + n * (-3 / 5 + n * (557 / 1440 + n * (281 / 630 + n * (-1983433 / 1935360)))));
+
+ np = np * n;
+ this.utg[2] = np * (-17 / 480 + n * (37 / 840 + n * (209 / 4480 + n * (-5569 / 90720 ))));
+ this.gtu[2] = np * (61 / 240 + n * (-103 / 140 + n * (15061 / 26880 + n * (167603 / 181440))));
+
+ np = np * n;
+ this.utg[3] = np * (-4397 / 161280 + n * (11 / 504 + n * (830251 / 7257600)));
+ this.gtu[3] = np * (49561 / 161280 + n * (-179 / 168 + n * (6601661 / 7257600)));
+
+ np = np * n;
+ this.utg[4] = np * (-4583 / 161280 + n * (108847 / 3991680));
+ this.gtu[4] = np * (34729 / 80640 + n * (-3418889 / 1995840));
+
+ np = np * n;
+ this.utg[5] = np * (-20648693 / 638668800);
+ this.gtu[5] = np * (212378941 / 319334400);
+
+ var Z = gatg(this.cbg, this.lat0);
+ this.Zb = -this.Qn * (Z + clens(this.gtu, 2 * Z));
+ }
+
+ function forward$3(p) {
+ var Ce = adjust_lon(p.x - this.long0);
+ var Cn = p.y;
+
+ Cn = gatg(this.cbg, Cn);
+
+ var sin_Cn = Math.sin(Cn);
+ var cos_Cn = Math.cos(Cn);
+ var sin_Ce = Math.sin(Ce);
+ var cos_Ce = Math.cos(Ce);
+
+ Cn = Math.atan2(sin_Cn, cos_Ce * cos_Cn);
+ Ce = Math.atan2(sin_Ce * cos_Cn, hypot(sin_Cn, cos_Cn * cos_Ce));
+ Ce = asinhy(Math.tan(Ce));
+
+ var tmp = clens_cmplx(this.gtu, 2 * Cn, 2 * Ce);
+
+ Cn = Cn + tmp[0];
+ Ce = Ce + tmp[1];
+
+ var x;
+ var y;
+
+ if (Math.abs(Ce) <= 2.623395162778) {
+ x = this.a * (this.Qn * Ce) + this.x0;
+ y = this.a * (this.Qn * Cn + this.Zb) + this.y0;
+ }
+ else {
+ x = Infinity;
+ y = Infinity;
+ }
+
+ p.x = x;
+ p.y = y;
+
+ return p;
+ }
+
+ function inverse$3(p) {
+ var Ce = (p.x - this.x0) * (1 / this.a);
+ var Cn = (p.y - this.y0) * (1 / this.a);
+
+ Cn = (Cn - this.Zb) / this.Qn;
+ Ce = Ce / this.Qn;
+
+ var lon;
+ var lat;
+
+ if (Math.abs(Ce) <= 2.623395162778) {
+ var tmp = clens_cmplx(this.utg, 2 * Cn, 2 * Ce);
+
+ Cn = Cn + tmp[0];
+ Ce = Ce + tmp[1];
+ Ce = Math.atan(sinh(Ce));
+
+ var sin_Cn = Math.sin(Cn);
+ var cos_Cn = Math.cos(Cn);
+ var sin_Ce = Math.sin(Ce);
+ var cos_Ce = Math.cos(Ce);
+
+ Cn = Math.atan2(sin_Cn * cos_Ce, hypot(sin_Ce, cos_Ce * cos_Cn));
+ Ce = Math.atan2(sin_Ce, cos_Ce * cos_Cn);
+
+ lon = adjust_lon(Ce + this.long0);
+ lat = gatg(this.cgb, Cn);
+ }
+ else {
+ lon = Infinity;
+ lat = Infinity;
+ }
+
+ p.x = lon;
+ p.y = lat;
+
+ return p;
+ }
+
+ var names$4 = ["Extended_Transverse_Mercator", "Extended Transverse Mercator", "etmerc"];
+ var etmerc = {
+ init: init$3,
+ forward: forward$3,
+ inverse: inverse$3,
+ names: names$4
+ };
+
+ var adjust_zone = function(zone, lon) {
+ if (zone === undefined) {
+ zone = Math.floor((adjust_lon(lon) + Math.PI) * 30 / Math.PI);
+
+ if (zone < 0) {
+ return 0;
+ } else if (zone >= 60) {
+ return 59;
+ }
+ return zone;
+ } else {
+ if (zone > 0 && zone <= 60) {
+ return zone - 1;
+ }
+ }
+ };
+
+ var dependsOn = 'etmerc';
+
+
+ function init$4() {
+ var zone = adjust_zone(this.zone, this.long0);
+ if (zone === undefined) {
+ throw new Error('unknown utm zone');
+ }
+
+ this.lat0 = 0;
+ this.long0 = (zone + 0.5) * Math.PI / 30 - Math.PI;
+ this.x0 = 500000;
+ this.y0 = this.utmSouth ? 10000000 : 0;
+ this.k0 = 0.9996;
+
+ etmerc.init.apply(this);
+ this.forward = etmerc.forward;
+ this.inverse = etmerc.inverse;
+ }
+
+ var names$5 = ["Universal Transverse Mercator System", "utm"];
+ var utm = {
+ init: init$4,
+ names: names$5,
+ dependsOn: dependsOn
+ };
+
+ var srat = function(esinp, exp) {
+ return (Math.pow((1 - esinp) / (1 + esinp), exp));
+ };
+
+ var MAX_ITER$1 = 20;
+ function init$6() {
+ var sphi = Math.sin(this.lat0);
+ var cphi = Math.cos(this.lat0);
+ cphi *= cphi;
+ this.rc = Math.sqrt(1 - this.es) / (1 - this.es * sphi * sphi);
+ this.C = Math.sqrt(1 + this.es * cphi * cphi / (1 - this.es));
+ this.phic0 = Math.asin(sphi / this.C);
+ this.ratexp = 0.5 * this.C * this.e;
+ this.K = Math.tan(0.5 * this.phic0 + FORTPI) / (Math.pow(Math.tan(0.5 * this.lat0 + FORTPI), this.C) * srat(this.e * sphi, this.ratexp));
+ }
+
+ function forward$5(p) {
+ var lon = p.x;
+ var lat = p.y;
+
+ p.y = 2 * Math.atan(this.K * Math.pow(Math.tan(0.5 * lat + FORTPI), this.C) * srat(this.e * Math.sin(lat), this.ratexp)) - HALF_PI;
+ p.x = this.C * lon;
+ return p;
+ }
+
+ function inverse$5(p) {
+ var DEL_TOL = 1e-14;
+ var lon = p.x / this.C;
+ var lat = p.y;
+ var num = Math.pow(Math.tan(0.5 * lat + FORTPI) / this.K, 1 / this.C);
+ for (var i = MAX_ITER$1; i > 0; --i) {
+ lat = 2 * Math.atan(num * srat(this.e * Math.sin(p.y), - 0.5 * this.e)) - HALF_PI;
+ if (Math.abs(lat - p.y) < DEL_TOL) {
+ break;
+ }
+ p.y = lat;
+ }
+ /* convergence failed */
+ if (!i) {
+ return null;
+ }
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$7 = ["gauss"];
+ var gauss = {
+ init: init$6,
+ forward: forward$5,
+ inverse: inverse$5,
+ names: names$7
+ };
+
+ function init$5() {
+ gauss.init.apply(this);
+ if (!this.rc) {
+ return;
+ }
+ this.sinc0 = Math.sin(this.phic0);
+ this.cosc0 = Math.cos(this.phic0);
+ this.R2 = 2 * this.rc;
+ if (!this.title) {
+ this.title = "Oblique Stereographic Alternative";
+ }
+ }
+
+ function forward$4(p) {
+ var sinc, cosc, cosl, k;
+ p.x = adjust_lon(p.x - this.long0);
+ gauss.forward.apply(this, [p]);
+ sinc = Math.sin(p.y);
+ cosc = Math.cos(p.y);
+ cosl = Math.cos(p.x);
+ k = this.k0 * this.R2 / (1 + this.sinc0 * sinc + this.cosc0 * cosc * cosl);
+ p.x = k * cosc * Math.sin(p.x);
+ p.y = k * (this.cosc0 * sinc - this.sinc0 * cosc * cosl);
+ p.x = this.a * p.x + this.x0;
+ p.y = this.a * p.y + this.y0;
+ return p;
+ }
+
+ function inverse$4(p) {
+ var sinc, cosc, lon, lat, rho;
+ p.x = (p.x - this.x0) / this.a;
+ p.y = (p.y - this.y0) / this.a;
+
+ p.x /= this.k0;
+ p.y /= this.k0;
+ if ((rho = Math.sqrt(p.x * p.x + p.y * p.y))) {
+ var c = 2 * Math.atan2(rho, this.R2);
+ sinc = Math.sin(c);
+ cosc = Math.cos(c);
+ lat = Math.asin(cosc * this.sinc0 + p.y * sinc * this.cosc0 / rho);
+ lon = Math.atan2(p.x * sinc, rho * this.cosc0 * cosc - p.y * this.sinc0 * sinc);
+ }
+ else {
+ lat = this.phic0;
+ lon = 0;
+ }
+
+ p.x = lon;
+ p.y = lat;
+ gauss.inverse.apply(this, [p]);
+ p.x = adjust_lon(p.x + this.long0);
+ return p;
+ }
+
+ var names$6 = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea","Oblique Stereographic Alternative"];
+ var sterea = {
+ init: init$5,
+ forward: forward$4,
+ inverse: inverse$4,
+ names: names$6
+ };
+
+ function ssfn_(phit, sinphi, eccen) {
+ sinphi *= eccen;
+ return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen));
+ }
+
+ function init$7() {
+ this.coslat0 = Math.cos(this.lat0);
+ this.sinlat0 = Math.sin(this.lat0);
+ if (this.sphere) {
+ if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
+ this.k0 = 0.5 * (1 + sign(this.lat0) * Math.sin(this.lat_ts));
+ }
+ }
+ else {
+ if (Math.abs(this.coslat0) <= EPSLN) {
+ if (this.lat0 > 0) {
+ //North pole
+ //trace('stere:north pole');
+ this.con = 1;
+ }
+ else {
+ //South pole
+ //trace('stere:south pole');
+ this.con = -1;
+ }
+ }
+ this.cons = Math.sqrt(Math.pow(1 + this.e, 1 + this.e) * Math.pow(1 - this.e, 1 - this.e));
+ if (this.k0 === 1 && !isNaN(this.lat_ts) && Math.abs(this.coslat0) <= EPSLN) {
+ this.k0 = 0.5 * this.cons * msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts)) / tsfnz(this.e, this.con * this.lat_ts, this.con * Math.sin(this.lat_ts));
+ }
+ this.ms1 = msfnz(this.e, this.sinlat0, this.coslat0);
+ this.X0 = 2 * Math.atan(this.ssfn_(this.lat0, this.sinlat0, this.e)) - HALF_PI;
+ this.cosX0 = Math.cos(this.X0);
+ this.sinX0 = Math.sin(this.X0);
+ }
+ }
+
+ // Stereographic forward equations--mapping lat,long to x,y
+ function forward$6(p) {
+ var lon = p.x;
+ var lat = p.y;
+ var sinlat = Math.sin(lat);
+ var coslat = Math.cos(lat);
+ var A, X, sinX, cosX, ts, rh;
+ var dlon = adjust_lon(lon - this.long0);
+
+ if (Math.abs(Math.abs(lon - this.long0) - Math.PI) <= EPSLN && Math.abs(lat + this.lat0) <= EPSLN) {
+ //case of the origine point
+ //trace('stere:this is the origin point');
+ p.x = NaN;
+ p.y = NaN;
+ return p;
+ }
+ if (this.sphere) {
+ //trace('stere:sphere case');
+ A = 2 * this.k0 / (1 + 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 {
+ X = 2 * Math.atan(this.ssfn_(lat, sinlat, this.e)) - HALF_PI;
+ cosX = Math.cos(X);
+ sinX = Math.sin(X);
+ if (Math.abs(this.coslat0) <= EPSLN) {
+ ts = tsfnz(this.e, lat * this.con, this.con * sinlat);
+ rh = 2 * 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) < EPSLN) {
+ //Eq
+ //trace('stere:equateur');
+ A = 2 * this.a * this.k0 / (1 + cosX * Math.cos(dlon));
+ p.y = A * sinX;
+ }
+ else {
+ //other case
+ //trace('stere:normal case');
+ A = 2 * this.a * this.k0 * this.ms1 / (this.cosX0 * (1 + 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;
+ }
+
+ //* Stereographic inverse equations--mapping x,y to lat/long
+ function inverse$6(p) {
+ p.x -= this.x0;
+ p.y -= this.y0;
+ 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));
+ lon = this.long0;
+ lat = this.lat0;
+ if (rh <= EPSLN) {
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+ lat = Math.asin(Math.cos(c) * this.sinlat0 + p.y * Math.sin(c) * this.coslat0 / rh);
+ if (Math.abs(this.coslat0) < EPSLN) {
+ if (this.lat0 > 0) {
+ lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
+ }
+ else {
+ lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
+ }
+ }
+ else {
+ lon = 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 {
+ if (Math.abs(this.coslat0) <= EPSLN) {
+ if (rh <= 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;
+ ts = rh * this.cons / (2 * this.a * this.k0);
+ lat = this.con * phi2z(this.e, ts);
+ lon = this.con * adjust_lon(this.con * this.long0 + Math.atan2(p.x, - 1 * p.y));
+ }
+ else {
+ ce = 2 * Math.atan(rh * this.cosX0 / (2 * this.a * this.k0 * this.ms1));
+ lon = this.long0;
+ if (rh <= EPSLN) {
+ Chi = this.X0;
+ }
+ else {
+ Chi = Math.asin(Math.cos(ce) * this.sinX0 + p.y * Math.sin(ce) * this.cosX0 / rh);
+ lon = 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 * phi2z(this.e, Math.tan(0.5 * (HALF_PI + Chi)));
+ }
+ }
+ p.x = lon;
+ p.y = lat;
+
+ //trace(p.toString());
+ return p;
+
+ }
+
+ var names$8 = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)"];
+ var stere = {
+ init: init$7,
+ forward: forward$6,
+ inverse: inverse$6,
+ names: names$8,
+ ssfn_: ssfn_
+ };
+
+ /*
+ references:
+ Formules et constantes pour le Calcul pour la
+ projection cylindrique conforme à axe oblique et pour la transformation entre
+ des systèmes de référence.
+ http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf
+ */
+
+ function init$8() {
+ var phy0 = this.lat0;
+ this.lambda0 = this.long0;
+ var sinPhy0 = Math.sin(phy0);
+ var semiMajorAxis = this.a;
+ var invF = this.rf;
+ var flattening = 1 / invF;
+ var e2 = 2 * flattening - Math.pow(flattening, 2);
+ var e = this.e = Math.sqrt(e2);
+ this.R = this.k0 * semiMajorAxis * Math.sqrt(1 - e2) / (1 - e2 * Math.pow(sinPhy0, 2));
+ this.alpha = Math.sqrt(1 + e2 / (1 - e2) * Math.pow(Math.cos(phy0), 4));
+ this.b0 = Math.asin(sinPhy0 / this.alpha);
+ var k1 = Math.log(Math.tan(Math.PI / 4 + this.b0 / 2));
+ var k2 = Math.log(Math.tan(Math.PI / 4 + phy0 / 2));
+ var k3 = Math.log((1 + e * sinPhy0) / (1 - e * sinPhy0));
+ this.K = k1 - this.alpha * k2 + this.alpha * e / 2 * k3;
+ }
+
+ function forward$7(p) {
+ var Sa1 = Math.log(Math.tan(Math.PI / 4 - p.y / 2));
+ var Sa2 = this.e / 2 * Math.log((1 + this.e * Math.sin(p.y)) / (1 - this.e * Math.sin(p.y)));
+ var S = -this.alpha * (Sa1 + Sa2) + this.K;
+
+ // spheric latitude
+ var b = 2 * (Math.atan(Math.exp(S)) - Math.PI / 4);
+
+ // spheric longitude
+ var I = this.alpha * (p.x - this.lambda0);
+
+ // psoeudo equatorial rotation
+ var rotI = Math.atan(Math.sin(I) / (Math.sin(this.b0) * Math.tan(b) + Math.cos(this.b0) * Math.cos(I)));
+
+ var rotB = Math.asin(Math.cos(this.b0) * Math.sin(b) - Math.sin(this.b0) * Math.cos(b) * Math.cos(I));
+
+ p.y = this.R / 2 * Math.log((1 + Math.sin(rotB)) / (1 - Math.sin(rotB))) + this.y0;
+ p.x = this.R * rotI + this.x0;
+ return p;
+ }
+
+ function inverse$7(p) {
+ var Y = p.x - this.x0;
+ var X = p.y - this.y0;
+
+ var rotI = Y / this.R;
+ var rotB = 2 * (Math.atan(Math.exp(X / this.R)) - Math.PI / 4);
+
+ var b = Math.asin(Math.cos(this.b0) * Math.sin(rotB) + Math.sin(this.b0) * Math.cos(rotB) * Math.cos(rotI));
+ var I = Math.atan(Math.sin(rotI) / (Math.cos(this.b0) * Math.cos(rotI) - Math.sin(this.b0) * Math.tan(rotB)));
+
+ var lambda = this.lambda0 + I / this.alpha;
+
+ var S = 0;
+ var phy = b;
+ var prevPhy = -1000;
+ var iteration = 0;
+ while (Math.abs(phy - prevPhy) > 0.0000001) {
+ if (++iteration > 20) {
+ //...reportError("omercFwdInfinity");
+ return;
+ }
+ //S = Math.log(Math.tan(Math.PI / 4 + phy / 2));
+ S = 1 / this.alpha * (Math.log(Math.tan(Math.PI / 4 + b / 2)) - this.K) + this.e * Math.log(Math.tan(Math.PI / 4 + Math.asin(this.e * Math.sin(phy)) / 2));
+ prevPhy = phy;
+ phy = 2 * Math.atan(Math.exp(S)) - Math.PI / 2;
+ }
+
+ p.x = lambda;
+ p.y = phy;
+ return p;
+ }
+
+ var names$9 = ["somerc"];
+ var somerc = {
+ init: init$8,
+ forward: forward$7,
+ inverse: inverse$7,
+ names: names$9
+ };
+
+ /* Initialize the Oblique Mercator projection
+ ------------------------------------------*/
+ function init$9() {
+ this.no_off = this.no_off || false;
+ this.no_rot = this.no_rot || false;
+
+ if (isNaN(this.k0)) {
+ this.k0 = 1;
+ }
+ var sinlat = Math.sin(this.lat0);
+ var coslat = Math.cos(this.lat0);
+ var con = this.e * sinlat;
+
+ this.bl = Math.sqrt(1 + this.es / (1 - this.es) * Math.pow(coslat, 4));
+ this.al = this.a * this.bl * this.k0 * Math.sqrt(1 - this.es) / (1 - con * con);
+ var t0 = tsfnz(this.e, this.lat0, sinlat);
+ var dl = this.bl / coslat * Math.sqrt((1 - this.es) / (1 - con * con));
+ if (dl * dl < 1) {
+ dl = 1;
+ }
+ var fl;
+ var gl;
+ if (!isNaN(this.longc)) {
+ //Central point and azimuth method
+
+ if (this.lat0 >= 0) {
+ fl = dl + Math.sqrt(dl * dl - 1);
+ }
+ else {
+ fl = dl - Math.sqrt(dl * dl - 1);
+ }
+ this.el = fl * Math.pow(t0, this.bl);
+ gl = 0.5 * (fl - 1 / fl);
+ this.gamma0 = Math.asin(Math.sin(this.alpha) / dl);
+ this.long0 = this.longc - Math.asin(gl * Math.tan(this.gamma0)) / this.bl;
+
+ }
+ else {
+ //2 points method
+ var t1 = tsfnz(this.e, this.lat1, Math.sin(this.lat1));
+ var t2 = tsfnz(this.e, this.lat2, Math.sin(this.lat2));
+ if (this.lat0 >= 0) {
+ this.el = (dl + Math.sqrt(dl * dl - 1)) * Math.pow(t0, this.bl);
+ }
+ else {
+ this.el = (dl - Math.sqrt(dl * dl - 1)) * Math.pow(t0, this.bl);
+ }
+ var hl = Math.pow(t1, this.bl);
+ var ll = Math.pow(t2, this.bl);
+ fl = this.el / hl;
+ gl = 0.5 * (fl - 1 / fl);
+ var jl = (this.el * this.el - ll * hl) / (this.el * this.el + ll * hl);
+ var pl = (ll - hl) / (ll + hl);
+ var dlon12 = adjust_lon(this.long1 - this.long2);
+ this.long0 = 0.5 * (this.long1 + this.long2) - Math.atan(jl * Math.tan(0.5 * this.bl * (dlon12)) / pl) / this.bl;
+ this.long0 = adjust_lon(this.long0);
+ var dlon10 = adjust_lon(this.long1 - this.long0);
+ this.gamma0 = Math.atan(Math.sin(this.bl * (dlon10)) / gl);
+ this.alpha = Math.asin(dl * Math.sin(this.gamma0));
+ }
+
+ if (this.no_off) {
+ this.uc = 0;
+ }
+ else {
+ if (this.lat0 >= 0) {
+ this.uc = this.al / this.bl * Math.atan2(Math.sqrt(dl * dl - 1), Math.cos(this.alpha));
+ }
+ else {
+ this.uc = -1 * this.al / this.bl * Math.atan2(Math.sqrt(dl * dl - 1), Math.cos(this.alpha));
+ }
+ }
+
+ }
+
+ /* Oblique Mercator forward equations--mapping lat,long to x,y
+ ----------------------------------------------------------*/
+ function forward$8(p) {
+ var lon = p.x;
+ var lat = p.y;
+ var dlon = adjust_lon(lon - this.long0);
+ var us, vs;
+ var con;
+ if (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN) {
+ if (lat > 0) {
+ con = -1;
+ }
+ else {
+ con = 1;
+ }
+ vs = this.al / this.bl * Math.log(Math.tan(FORTPI + con * this.gamma0 * 0.5));
+ us = -1 * con * HALF_PI * this.al / this.bl;
+ }
+ else {
+ var t = tsfnz(this.e, lat, Math.sin(lat));
+ var ql = this.el / Math.pow(t, this.bl);
+ var sl = 0.5 * (ql - 1 / ql);
+ var tl = 0.5 * (ql + 1 / ql);
+ var vl = Math.sin(this.bl * (dlon));
+ var ul = (sl * Math.sin(this.gamma0) - vl * Math.cos(this.gamma0)) / tl;
+ if (Math.abs(Math.abs(ul) - 1) <= EPSLN) {
+ vs = Number.POSITIVE_INFINITY;
+ }
+ else {
+ vs = 0.5 * this.al * Math.log((1 - ul) / (1 + ul)) / this.bl;
+ }
+ if (Math.abs(Math.cos(this.bl * (dlon))) <= EPSLN) {
+ us = this.al * this.bl * (dlon);
+ }
+ else {
+ us = this.al * Math.atan2(sl * Math.cos(this.gamma0) + vl * Math.sin(this.gamma0), Math.cos(this.bl * dlon)) / this.bl;
+ }
+ }
+
+ if (this.no_rot) {
+ p.x = this.x0 + us;
+ p.y = this.y0 + vs;
+ }
+ else {
+
+ us -= this.uc;
+ p.x = this.x0 + vs * Math.cos(this.alpha) + us * Math.sin(this.alpha);
+ p.y = this.y0 + us * Math.cos(this.alpha) - vs * Math.sin(this.alpha);
+ }
+ return p;
+ }
+
+ function inverse$8(p) {
+ var us, vs;
+ if (this.no_rot) {
+ vs = p.y - this.y0;
+ us = p.x - this.x0;
+ }
+ else {
+ vs = (p.x - this.x0) * Math.cos(this.alpha) - (p.y - this.y0) * Math.sin(this.alpha);
+ us = (p.y - this.y0) * Math.cos(this.alpha) + (p.x - this.x0) * Math.sin(this.alpha);
+ us += this.uc;
+ }
+ var qp = Math.exp(-1 * this.bl * vs / this.al);
+ var sp = 0.5 * (qp - 1 / qp);
+ var tp = 0.5 * (qp + 1 / qp);
+ var vp = Math.sin(this.bl * us / this.al);
+ var up = (vp * Math.cos(this.gamma0) + sp * Math.sin(this.gamma0)) / tp;
+ var ts = Math.pow(this.el / Math.sqrt((1 + up) / (1 - up)), 1 / this.bl);
+ if (Math.abs(up - 1) < EPSLN) {
+ p.x = this.long0;
+ p.y = HALF_PI;
+ }
+ else if (Math.abs(up + 1) < EPSLN) {
+ p.x = this.long0;
+ p.y = -1 * HALF_PI;
+ }
+ else {
+ p.y = phi2z(this.e, ts);
+ p.x = adjust_lon(this.long0 - Math.atan2(sp * Math.cos(this.gamma0) - vp * Math.sin(this.gamma0), Math.cos(this.bl * us / this.al)) / this.bl);
+ }
+ return p;
+ }
+
+ var names$10 = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "omerc"];
+ var omerc = {
+ init: init$9,
+ forward: forward$8,
+ inverse: inverse$8,
+ names: names$10
+ };
+
+ function init$10() {
+
+ // array of: r_maj,r_min,lat1,lat2,c_lon,c_lat,false_east,false_north
+ //double c_lat; /* center latitude */
+ //double c_lon; /* center longitude */
+ //double lat1; /* first standard parallel */
+ //double lat2; /* second standard parallel */
+ //double r_maj; /* major axis */
+ //double r_min; /* minor axis */
+ //double false_east; /* x offset in meters */
+ //double false_north; /* y offset in meters */
+
+ if (!this.lat2) {
+ this.lat2 = this.lat1;
+ } //if lat2 is not defined
+ if (!this.k0) {
+ this.k0 = 1;
+ }
+ this.x0 = this.x0 || 0;
+ this.y0 = this.y0 || 0;
+ // Standard Parallels cannot be equal and on opposite sides of the equator
+ if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
+ return;
+ }
+
+ var temp = this.b / this.a;
+ this.e = Math.sqrt(1 - temp * temp);
+
+ var sin1 = Math.sin(this.lat1);
+ var cos1 = Math.cos(this.lat1);
+ var ms1 = msfnz(this.e, sin1, cos1);
+ var ts1 = tsfnz(this.e, this.lat1, sin1);
+
+ var sin2 = Math.sin(this.lat2);
+ var cos2 = Math.cos(this.lat2);
+ var ms2 = msfnz(this.e, sin2, cos2);
+ var ts2 = tsfnz(this.e, this.lat2, sin2);
+
+ var ts0 = tsfnz(this.e, this.lat0, Math.sin(this.lat0));
+
+ if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
+ this.ns = Math.log(ms1 / ms2) / Math.log(ts1 / ts2);
+ }
+ else {
+ this.ns = sin1;
+ }
+ if (isNaN(this.ns)) {
+ this.ns = sin1;
+ }
+ this.f0 = ms1 / (this.ns * Math.pow(ts1, this.ns));
+ this.rh = this.a * this.f0 * Math.pow(ts0, this.ns);
+ if (!this.title) {
+ this.title = "Lambert Conformal Conic";
+ }
+ }
+
+ // Lambert Conformal conic forward equations--mapping lat,long to x,y
+ // -----------------------------------------------------------------
+ function forward$9(p) {
+
+ var lon = p.x;
+ var lat = p.y;
+
+ // singular cases :
+ if (Math.abs(2 * Math.abs(lat) - Math.PI) <= EPSLN) {
+ lat = sign(lat) * (HALF_PI - 2 * EPSLN);
+ }
+
+ var con = Math.abs(Math.abs(lat) - HALF_PI);
+ var ts, rh1;
+ if (con > EPSLN) {
+ ts = tsfnz(this.e, lat, Math.sin(lat));
+ rh1 = this.a * this.f0 * Math.pow(ts, this.ns);
+ }
+ else {
+ con = lat * this.ns;
+ if (con <= 0) {
+ return null;
+ }
+ rh1 = 0;
+ }
+ var theta = this.ns * adjust_lon(lon - this.long0);
+ p.x = this.k0 * (rh1 * Math.sin(theta)) + this.x0;
+ p.y = this.k0 * (this.rh - rh1 * Math.cos(theta)) + this.y0;
+
+ return p;
+ }
+
+ // Lambert Conformal Conic inverse equations--mapping x,y to lat/long
+ // -----------------------------------------------------------------
+ function inverse$9(p) {
+
+ var rh1, con, ts;
+ var lat, lon;
+ var x = (p.x - this.x0) / this.k0;
+ var y = (this.rh - (p.y - this.y0) / this.k0);
+ if (this.ns > 0) {
+ rh1 = Math.sqrt(x * x + y * y);
+ con = 1;
+ }
+ else {
+ rh1 = -Math.sqrt(x * x + y * y);
+ con = -1;
+ }
+ var theta = 0;
+ if (rh1 !== 0) {
+ theta = Math.atan2((con * x), (con * y));
+ }
+ if ((rh1 !== 0) || (this.ns > 0)) {
+ con = 1 / this.ns;
+ ts = Math.pow((rh1 / (this.a * this.f0)), con);
+ lat = phi2z(this.e, ts);
+ if (lat === -9999) {
+ return null;
+ }
+ }
+ else {
+ lat = -HALF_PI;
+ }
+ lon = adjust_lon(theta / this.ns + this.long0);
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$11 = ["Lambert Tangential Conformal Conic Projection", "Lambert_Conformal_Conic", "Lambert_Conformal_Conic_2SP", "lcc"];
+ var lcc = {
+ init: init$10,
+ forward: forward$9,
+ inverse: inverse$9,
+ names: names$11
+ };
+
+ function init$11() {
+ this.a = 6377397.155;
+ this.es = 0.006674372230614;
+ this.e = Math.sqrt(this.es);
+ if (!this.lat0) {
+ this.lat0 = 0.863937979737193;
+ }
+ if (!this.long0) {
+ this.long0 = 0.7417649320975901 - 0.308341501185665;
+ }
+ /* if scale not set default to 0.9999 */
+ if (!this.k0) {
+ this.k0 = 0.9999;
+ }
+ this.s45 = 0.785398163397448; /* 45 */
+ this.s90 = 2 * this.s45;
+ this.fi0 = this.lat0;
+ this.e2 = this.es;
+ this.e = Math.sqrt(this.e2);
+ this.alfa = Math.sqrt(1 + (this.e2 * Math.pow(Math.cos(this.fi0), 4)) / (1 - this.e2));
+ this.uq = 1.04216856380474;
+ this.u0 = Math.asin(Math.sin(this.fi0) / this.alfa);
+ this.g = Math.pow((1 + this.e * Math.sin(this.fi0)) / (1 - this.e * Math.sin(this.fi0)), this.alfa * this.e / 2);
+ this.k = Math.tan(this.u0 / 2 + this.s45) / Math.pow(Math.tan(this.fi0 / 2 + this.s45), this.alfa) * this.g;
+ this.k1 = this.k0;
+ this.n0 = this.a * Math.sqrt(1 - this.e2) / (1 - this.e2 * Math.pow(Math.sin(this.fi0), 2));
+ this.s0 = 1.37008346281555;
+ this.n = Math.sin(this.s0);
+ this.ro0 = this.k1 * this.n0 / Math.tan(this.s0);
+ this.ad = this.s90 - this.uq;
+ }
+
+ /* ellipsoid */
+ /* calculate xy from lat/lon */
+ /* Constants, identical to inverse transform function */
+ function forward$10(p) {
+ var gfi, u, deltav, s, d, eps, ro;
+ var lon = p.x;
+ var lat = p.y;
+ var delta_lon = adjust_lon(lon - this.long0);
+ /* Transformation */
+ gfi = Math.pow(((1 + this.e * Math.sin(lat)) / (1 - this.e * Math.sin(lat))), (this.alfa * this.e / 2));
+ u = 2 * (Math.atan(this.k * Math.pow(Math.tan(lat / 2 + this.s45), this.alfa) / gfi) - this.s45);
+ deltav = -delta_lon * this.alfa;
+ s = Math.asin(Math.cos(this.ad) * Math.sin(u) + Math.sin(this.ad) * Math.cos(u) * Math.cos(deltav));
+ d = Math.asin(Math.cos(u) * Math.sin(deltav) / Math.cos(s));
+ eps = this.n * d;
+ ro = this.ro0 * Math.pow(Math.tan(this.s0 / 2 + this.s45), this.n) / Math.pow(Math.tan(s / 2 + this.s45), this.n);
+ p.y = ro * Math.cos(eps) / 1;
+ p.x = ro * Math.sin(eps) / 1;
+
+ if (!this.czech) {
+ p.y *= -1;
+ p.x *= -1;
+ }
+ return (p);
+ }
+
+ /* calculate lat/lon from xy */
+ function inverse$10(p) {
+ var u, deltav, s, d, eps, ro, fi1;
+ var ok;
+
+ /* Transformation */
+ /* revert y, x*/
+ var tmp = p.x;
+ p.x = p.y;
+ p.y = tmp;
+ if (!this.czech) {
+ p.y *= -1;
+ p.x *= -1;
+ }
+ ro = Math.sqrt(p.x * p.x + p.y * p.y);
+ eps = Math.atan2(p.y, p.x);
+ d = eps / Math.sin(this.s0);
+ s = 2 * (Math.atan(Math.pow(this.ro0 / ro, 1 / this.n) * Math.tan(this.s0 / 2 + this.s45)) - this.s45);
+ u = Math.asin(Math.cos(this.ad) * Math.sin(s) - Math.sin(this.ad) * Math.cos(s) * Math.cos(d));
+ deltav = Math.asin(Math.cos(s) * Math.sin(d) / Math.cos(u));
+ p.x = this.long0 - deltav / this.alfa;
+ fi1 = u;
+ ok = 0;
+ var iter = 0;
+ do {
+ p.y = 2 * (Math.atan(Math.pow(this.k, - 1 / this.alfa) * Math.pow(Math.tan(u / 2 + this.s45), 1 / this.alfa) * Math.pow((1 + this.e * Math.sin(fi1)) / (1 - this.e * Math.sin(fi1)), this.e / 2)) - this.s45);
+ if (Math.abs(fi1 - p.y) < 0.0000000001) {
+ ok = 1;
+ }
+ fi1 = p.y;
+ iter += 1;
+ } while (ok === 0 && iter < 15);
+ if (iter >= 15) {
+ return null;
+ }
+
+ return (p);
+ }
+
+ var names$12 = ["Krovak", "krovak"];
+ var krovak = {
+ init: init$11,
+ forward: forward$10,
+ inverse: inverse$10,
+ names: names$12
+ };
+
+ var mlfn = function(e0, e1, e2, e3, phi) {
+ return (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi));
+ };
+
+ var e0fn = function(x) {
+ return (1 - 0.25 * x * (1 + x / 16 * (3 + 1.25 * x)));
+ };
+
+ var e1fn = function(x) {
+ return (0.375 * x * (1 + 0.25 * x * (1 + 0.46875 * x)));
+ };
+
+ var e2fn = function(x) {
+ return (0.05859375 * x * x * (1 + 0.75 * x));
+ };
+
+ var e3fn = function(x) {
+ return (x * x * x * (35 / 3072));
+ };
+
+ var gN = function(a, e, sinphi) {
+ var temp = e * sinphi;
+ return a / Math.sqrt(1 - temp * temp);
+ };
+
+ var adjust_lat = function(x) {
+ return (Math.abs(x) < HALF_PI) ? x : (x - (sign(x) * Math.PI));
+ };
+
+ var 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 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi))) / (e0 - 2 * e1 * Math.cos(2 * phi) + 4 * e2 * Math.cos(4 * phi) - 6 * e3 * Math.cos(6 * phi));
+ phi += dphi;
+ if (Math.abs(dphi) <= 0.0000000001) {
+ return phi;
+ }
+ }
+
+ //..reportError("IMLFN-CONV:Latitude failed to converge after 15 iterations");
+ return NaN;
+ };
+
+ function init$12() {
+ if (!this.sphere) {
+ 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);
+ }
+ }
+
+ /* Cassini forward equations--mapping lat,long to x,y
+ -----------------------------------------------------------------------*/
+ function forward$11(p) {
+
+ /* Forward equations
+ -----------------*/
+ var x, y;
+ var lam = p.x;
+ var phi = p.y;
+ lam = adjust_lon(lam - this.long0);
+
+ if (this.sphere) {
+ x = this.a * Math.asin(Math.cos(phi) * Math.sin(lam));
+ y = this.a * (Math.atan2(Math.tan(phi), Math.cos(lam)) - this.lat0);
+ }
+ else {
+ //ellipsoid
+ var sinphi = Math.sin(phi);
+ var cosphi = Math.cos(phi);
+ var nl = gN(this.a, this.e, sinphi);
+ var tl = Math.tan(phi) * Math.tan(phi);
+ var al = lam * Math.cos(phi);
+ var asq = al * al;
+ var cl = this.es * cosphi * cosphi / (1 - this.es);
+ var ml = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
+
+ x = nl * al * (1 - asq * tl * (1 / 6 - (8 - tl + 8 * cl) * asq / 120));
+ y = ml - this.ml0 + nl * sinphi / cosphi * asq * (0.5 + (5 - tl + 6 * cl) * asq / 24);
+
+
+ }
+
+ p.x = x + this.x0;
+ p.y = y + this.y0;
+ return p;
+ }
+
+ /* Inverse equations
+ -----------------*/
+ function inverse$11(p) {
+ p.x -= this.x0;
+ p.y -= this.y0;
+ var x = p.x / this.a;
+ var y = p.y / this.a;
+ var phi, lam;
+
+ if (this.sphere) {
+ var dd = y + this.lat0;
+ phi = Math.asin(Math.sin(dd) * Math.cos(x));
+ lam = Math.atan2(Math.tan(x), Math.cos(dd));
+ }
+ else {
+ /* ellipsoid */
+ var ml1 = this.ml0 / this.a + y;
+ var phi1 = imlfn(ml1, this.e0, this.e1, this.e2, this.e3);
+ if (Math.abs(Math.abs(phi1) - HALF_PI) <= EPSLN) {
+ p.x = this.long0;
+ p.y = HALF_PI;
+ if (y < 0) {
+ p.y *= -1;
+ }
+ return p;
+ }
+ var nl1 = gN(this.a, this.e, Math.sin(phi1));
+
+ var rl1 = nl1 * nl1 * nl1 / this.a / this.a * (1 - this.es);
+ var tl1 = Math.pow(Math.tan(phi1), 2);
+ var dl = x * this.a / nl1;
+ var dsq = dl * dl;
+ phi = phi1 - nl1 * Math.tan(phi1) / rl1 * dl * dl * (0.5 - (1 + 3 * tl1) * dl * dl / 24);
+ lam = dl * (1 - dsq * (tl1 / 3 + (1 + 3 * tl1) * tl1 * dsq / 15)) / Math.cos(phi1);
+
+ }
+
+ p.x = adjust_lon(lam + this.long0);
+ p.y = adjust_lat(phi);
+ return p;
+
+ }
+
+ var names$13 = ["Cassini", "Cassini_Soldner", "cass"];
+ var cass = {
+ init: init$12,
+ forward: forward$11,
+ inverse: inverse$11,
+ names: names$13
+ };
+
+ var qsfnz = function(eccent, sinphi) {
+ var con;
+ if (eccent > 1.0e-7) {
+ con = eccent * sinphi;
+ return ((1 - eccent * eccent) * (sinphi / (1 - con * con) - (0.5 / eccent) * Math.log((1 - con) / (1 + con))));
+ }
+ else {
+ return (2 * sinphi);
+ }
+ };
+
+ /*
+ reference
+ "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
+ The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
+ */
+
+ var S_POLE = 1;
+
+ var N_POLE = 2;
+ var EQUIT = 3;
+ var OBLIQ = 4;
+
+ /* Initialize the Lambert Azimuthal Equal Area projection
+ ------------------------------------------------------*/
+ function init$13() {
+ var t = Math.abs(this.lat0);
+ if (Math.abs(t - HALF_PI) < EPSLN) {
+ this.mode = this.lat0 < 0 ? this.S_POLE : this.N_POLE;
+ }
+ else if (Math.abs(t) < EPSLN) {
+ this.mode = this.EQUIT;
+ }
+ else {
+ this.mode = this.OBLIQ;
+ }
+ if (this.es > 0) {
+ var sinphi;
+
+ this.qp = qsfnz(this.e, 1);
+ this.mmf = 0.5 / (1 - this.es);
+ this.apa = authset(this.es);
+ switch (this.mode) {
+ case this.N_POLE:
+ this.dd = 1;
+ break;
+ case this.S_POLE:
+ this.dd = 1;
+ break;
+ case this.EQUIT:
+ this.rq = Math.sqrt(0.5 * this.qp);
+ this.dd = 1 / this.rq;
+ this.xmf = 1;
+ this.ymf = 0.5 * this.qp;
+ break;
+ case this.OBLIQ:
+ this.rq = Math.sqrt(0.5 * this.qp);
+ sinphi = Math.sin(this.lat0);
+ this.sinb1 = qsfnz(this.e, sinphi) / this.qp;
+ this.cosb1 = Math.sqrt(1 - this.sinb1 * this.sinb1);
+ this.dd = Math.cos(this.lat0) / (Math.sqrt(1 - this.es * sinphi * sinphi) * this.rq * this.cosb1);
+ this.ymf = (this.xmf = this.rq) / this.dd;
+ this.xmf *= this.dd;
+ break;
+ }
+ }
+ else {
+ if (this.mode === this.OBLIQ) {
+ this.sinph0 = Math.sin(this.lat0);
+ this.cosph0 = Math.cos(this.lat0);
+ }
+ }
+ }
+
+ /* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
+ -----------------------------------------------------------------------*/
+ function forward$12(p) {
+
+ /* Forward equations
+ -----------------*/
+ var x, y, coslam, sinlam, sinphi, q, sinb, cosb, b, cosphi;
+ var lam = p.x;
+ var phi = p.y;
+
+ lam = adjust_lon(lam - this.long0);
+ if (this.sphere) {
+ sinphi = Math.sin(phi);
+ cosphi = Math.cos(phi);
+ coslam = Math.cos(lam);
+ if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
+ y = (this.mode === this.EQUIT) ? 1 + cosphi * coslam : 1 + this.sinph0 * sinphi + this.cosph0 * cosphi * coslam;
+ if (y <= EPSLN) {
+ return null;
+ }
+ y = Math.sqrt(2 / y);
+ x = y * cosphi * Math.sin(lam);
+ y *= (this.mode === this.EQUIT) ? sinphi : this.cosph0 * sinphi - this.sinph0 * cosphi * coslam;
+ }
+ else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
+ if (this.mode === this.N_POLE) {
+ coslam = -coslam;
+ }
+ if (Math.abs(phi + this.phi0) < EPSLN) {
+ return null;
+ }
+ y = FORTPI - phi * 0.5;
+ y = 2 * ((this.mode === this.S_POLE) ? Math.cos(y) : Math.sin(y));
+ x = y * Math.sin(lam);
+ y *= coslam;
+ }
+ }
+ else {
+ sinb = 0;
+ cosb = 0;
+ b = 0;
+ coslam = Math.cos(lam);
+ sinlam = Math.sin(lam);
+ sinphi = Math.sin(phi);
+ q = qsfnz(this.e, sinphi);
+ if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
+ sinb = q / this.qp;
+ cosb = Math.sqrt(1 - sinb * sinb);
+ }
+ switch (this.mode) {
+ case this.OBLIQ:
+ b = 1 + this.sinb1 * sinb + this.cosb1 * cosb * coslam;
+ break;
+ case this.EQUIT:
+ b = 1 + cosb * coslam;
+ break;
+ case this.N_POLE:
+ b = HALF_PI + phi;
+ q = this.qp - q;
+ break;
+ case this.S_POLE:
+ b = phi - HALF_PI;
+ q = this.qp + q;
+ break;
+ }
+ if (Math.abs(b) < EPSLN) {
+ return null;
+ }
+ switch (this.mode) {
+ case this.OBLIQ:
+ case this.EQUIT:
+ b = Math.sqrt(2 / b);
+ if (this.mode === this.OBLIQ) {
+ y = this.ymf * b * (this.cosb1 * sinb - this.sinb1 * cosb * coslam);
+ }
+ else {
+ y = (b = Math.sqrt(2 / (1 + cosb * coslam))) * sinb * this.ymf;
+ }
+ x = this.xmf * b * cosb * sinlam;
+ break;
+ case this.N_POLE:
+ case this.S_POLE:
+ if (q >= 0) {
+ x = (b = Math.sqrt(q)) * sinlam;
+ y = coslam * ((this.mode === this.S_POLE) ? b : -b);
+ }
+ else {
+ x = y = 0;
+ }
+ break;
+ }
+ }
+
+ p.x = this.a * x + this.x0;
+ p.y = this.a * y + this.y0;
+ return p;
+ }
+
+ /* Inverse equations
+ -----------------*/
+ function inverse$12(p) {
+ p.x -= this.x0;
+ p.y -= this.y0;
+ var x = p.x / this.a;
+ var y = p.y / this.a;
+ var lam, phi, cCe, sCe, q, rho, ab;
+ if (this.sphere) {
+ var cosz = 0,
+ rh, sinz = 0;
+
+ rh = Math.sqrt(x * x + y * y);
+ phi = rh * 0.5;
+ if (phi > 1) {
+ return null;
+ }
+ phi = 2 * Math.asin(phi);
+ if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
+ sinz = Math.sin(phi);
+ cosz = Math.cos(phi);
+ }
+ switch (this.mode) {
+ case this.EQUIT:
+ phi = (Math.abs(rh) <= EPSLN) ? 0 : Math.asin(y * sinz / rh);
+ x *= sinz;
+ y = cosz * rh;
+ break;
+ case this.OBLIQ:
+ phi = (Math.abs(rh) <= EPSLN) ? this.phi0 : Math.asin(cosz * this.sinph0 + y * sinz * this.cosph0 / rh);
+ x *= sinz * this.cosph0;
+ y = (cosz - Math.sin(phi) * this.sinph0) * rh;
+ break;
+ case this.N_POLE:
+ y = -y;
+ phi = HALF_PI - phi;
+ break;
+ case this.S_POLE:
+ phi -= HALF_PI;
+ break;
+ }
+ lam = (y === 0 && (this.mode === this.EQUIT || this.mode === this.OBLIQ)) ? 0 : Math.atan2(x, y);
+ }
+ else {
+ ab = 0;
+ if (this.mode === this.OBLIQ || this.mode === this.EQUIT) {
+ x /= this.dd;
+ y *= this.dd;
+ rho = Math.sqrt(x * x + y * y);
+ if (rho < EPSLN) {
+ p.x = 0;
+ p.y = this.phi0;
+ return p;
+ }
+ sCe = 2 * Math.asin(0.5 * rho / this.rq);
+ cCe = Math.cos(sCe);
+ x *= (sCe = Math.sin(sCe));
+ if (this.mode === this.OBLIQ) {
+ ab = cCe * this.sinb1 + y * sCe * this.cosb1 / rho;
+ q = this.qp * ab;
+ y = rho * this.cosb1 * cCe - y * this.sinb1 * sCe;
+ }
+ else {
+ ab = y * sCe / rho;
+ q = this.qp * ab;
+ y = rho * cCe;
+ }
+ }
+ else if (this.mode === this.N_POLE || this.mode === this.S_POLE) {
+ if (this.mode === this.N_POLE) {
+ y = -y;
+ }
+ q = (x * x + y * y);
+ if (!q) {
+ p.x = 0;
+ p.y = this.phi0;
+ return p;
+ }
+ ab = 1 - q / this.qp;
+ if (this.mode === this.S_POLE) {
+ ab = -ab;
+ }
+ }
+ lam = Math.atan2(x, y);
+ phi = authlat(Math.asin(ab), this.apa);
+ }
+
+ p.x = adjust_lon(this.long0 + lam);
+ p.y = phi;
+ return p;
+ }
+
+ /* determine latitude from authalic latitude */
+ var P00 = 0.33333333333333333333;
+
+ var P01 = 0.17222222222222222222;
+ var P02 = 0.10257936507936507936;
+ var P10 = 0.06388888888888888888;
+ var P11 = 0.06640211640211640211;
+ var P20 = 0.01641501294219154443;
+
+ function authset(es) {
+ var t;
+ var APA = [];
+ APA[0] = es * P00;
+ t = es * es;
+ APA[0] += t * P01;
+ APA[1] = t * P10;
+ t *= es;
+ APA[0] += t * P02;
+ APA[1] += t * P11;
+ APA[2] = t * P20;
+ return APA;
+ }
+
+ function authlat(beta, APA) {
+ var t = beta + beta;
+ return (beta + APA[0] * Math.sin(t) + APA[1] * Math.sin(t + t) + APA[2] * Math.sin(t + t + t));
+ }
+
+ var names$14 = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"];
+ var laea = {
+ init: init$13,
+ forward: forward$12,
+ inverse: inverse$12,
+ names: names$14,
+ S_POLE: S_POLE,
+ N_POLE: N_POLE,
+ EQUIT: EQUIT,
+ OBLIQ: OBLIQ
+ };
+
+ var asinz = function(x) {
+ if (Math.abs(x) > 1) {
+ x = (x > 1) ? 1 : -1;
+ }
+ return Math.asin(x);
+ };
+
+ function init$14() {
+
+ if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
+ return;
+ }
+ this.temp = this.b / this.a;
+ this.es = 1 - Math.pow(this.temp, 2);
+ this.e3 = Math.sqrt(this.es);
+
+ this.sin_po = Math.sin(this.lat1);
+ this.cos_po = Math.cos(this.lat1);
+ this.t1 = this.sin_po;
+ this.con = this.sin_po;
+ this.ms1 = msfnz(this.e3, this.sin_po, this.cos_po);
+ this.qs1 = qsfnz(this.e3, this.sin_po, this.cos_po);
+
+ this.sin_po = Math.sin(this.lat2);
+ this.cos_po = Math.cos(this.lat2);
+ this.t2 = this.sin_po;
+ this.ms2 = msfnz(this.e3, this.sin_po, this.cos_po);
+ this.qs2 = qsfnz(this.e3, this.sin_po, this.cos_po);
+
+ this.sin_po = Math.sin(this.lat0);
+ this.cos_po = Math.cos(this.lat0);
+ this.t3 = this.sin_po;
+ this.qs0 = qsfnz(this.e3, this.sin_po, this.cos_po);
+
+ if (Math.abs(this.lat1 - this.lat2) > EPSLN) {
+ this.ns0 = (this.ms1 * this.ms1 - this.ms2 * this.ms2) / (this.qs2 - this.qs1);
+ }
+ else {
+ this.ns0 = this.con;
+ }
+ this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
+ this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0) / this.ns0;
+ }
+
+ /* Albers Conical Equal Area forward equations--mapping lat,long to x,y
+ -------------------------------------------------------------------*/
+ function forward$13(p) {
+
+ var lon = p.x;
+ var lat = p.y;
+
+ this.sin_phi = Math.sin(lat);
+ this.cos_phi = Math.cos(lat);
+
+ var qs = qsfnz(this.e3, this.sin_phi, this.cos_phi);
+ var rh1 = this.a * Math.sqrt(this.c - this.ns0 * qs) / this.ns0;
+ var theta = this.ns0 * adjust_lon(lon - this.long0);
+ var x = rh1 * Math.sin(theta) + this.x0;
+ var y = this.rh - rh1 * Math.cos(theta) + this.y0;
+
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ function inverse$13(p) {
+ var rh1, qs, con, theta, lon, lat;
+
+ p.x -= this.x0;
+ p.y = this.rh - p.y + this.y0;
+ if (this.ns0 >= 0) {
+ rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
+ con = 1;
+ }
+ else {
+ rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
+ con = -1;
+ }
+ theta = 0;
+ if (rh1 !== 0) {
+ theta = Math.atan2(con * p.x, con * p.y);
+ }
+ con = rh1 * this.ns0 / this.a;
+ if (this.sphere) {
+ lat = Math.asin((this.c - con * con) / (2 * this.ns0));
+ }
+ else {
+ qs = (this.c - con * con) / this.ns0;
+ lat = this.phi1z(this.e3, qs);
+ }
+
+ lon = adjust_lon(theta / this.ns0 + this.long0);
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ /* Function to compute phi1, the latitude for the inverse of the
+ Albers Conical Equal-Area projection.
+ -------------------------------------------*/
+ function phi1z(eccent, qs) {
+ var sinphi, cosphi, con, com, dphi;
+ var phi = asinz(0.5 * qs);
+ if (eccent < EPSLN) {
+ return phi;
+ }
+
+ var eccnts = eccent * eccent;
+ for (var i = 1; i <= 25; i++) {
+ sinphi = Math.sin(phi);
+ cosphi = Math.cos(phi);
+ con = eccent * sinphi;
+ com = 1 - con * con;
+ dphi = 0.5 * com * com / cosphi * (qs / (1 - eccnts) - sinphi / com + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
+ phi = phi + dphi;
+ if (Math.abs(dphi) <= 1e-7) {
+ return phi;
+ }
+ }
+ return null;
+ }
+
+ var names$15 = ["Albers_Conic_Equal_Area", "Albers", "aea"];
+ var aea = {
+ init: init$14,
+ forward: forward$13,
+ inverse: inverse$13,
+ names: names$15,
+ phi1z: phi1z
+ };
+
+ /*
+ reference:
+ Wolfram Mathworld "Gnomonic Projection"
+ http://mathworld.wolfram.com/GnomonicProjection.html
+ Accessed: 12th November 2009
+ */
+ function init$15() {
+
+ /* Place parameters in static storage for common use
+ -------------------------------------------------*/
+ this.sin_p14 = Math.sin(this.lat0);
+ this.cos_p14 = Math.cos(this.lat0);
+ // Approximation for projecting points to the horizon (infinity)
+ this.infinity_dist = 1000 * this.a;
+ this.rc = 1;
+ }
+
+ /* Gnomonic forward equations--mapping lat,long to x,y
+ ---------------------------------------------------*/
+ function forward$14(p) {
+ var sinphi, cosphi; /* sin and cos value */
+ var dlon; /* delta longitude value */
+ var coslon; /* cos of longitude */
+ var ksp; /* scale factor */
+ var g;
+ var x, y;
+ var lon = p.x;
+ var lat = p.y;
+ /* Forward equations
+ -----------------*/
+ dlon = adjust_lon(lon - this.long0);
+
+ sinphi = Math.sin(lat);
+ cosphi = Math.cos(lat);
+
+ coslon = Math.cos(dlon);
+ g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
+ ksp = 1;
+ if ((g > 0) || (Math.abs(g) <= EPSLN)) {
+ x = this.x0 + this.a * ksp * cosphi * Math.sin(dlon) / g;
+ y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon) / g;
+ }
+ else {
+
+ // Point is in the opposing hemisphere and is unprojectable
+ // We still need to return a reasonable point, so we project
+ // to infinity, on a bearing
+ // equivalent to the northern hemisphere equivalent
+ // This is a reasonable approximation for short shapes and lines that
+ // straddle the horizon.
+
+ x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon);
+ y = this.y0 + this.infinity_dist * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
+
+ }
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ function inverse$14(p) {
+ var rh; /* Rho */
+ var sinc, cosc;
+ var c;
+ var lon, lat;
+
+ /* Inverse equations
+ -----------------*/
+ p.x = (p.x - this.x0) / this.a;
+ p.y = (p.y - this.y0) / this.a;
+
+ p.x /= this.k0;
+ p.y /= this.k0;
+
+ if ((rh = Math.sqrt(p.x * p.x + p.y * p.y))) {
+ c = Math.atan2(rh, this.rc);
+ sinc = Math.sin(c);
+ cosc = Math.cos(c);
+
+ lat = asinz(cosc * this.sin_p14 + (p.y * sinc * this.cos_p14) / rh);
+ lon = Math.atan2(p.x * sinc, rh * this.cos_p14 * cosc - p.y * this.sin_p14 * sinc);
+ lon = adjust_lon(this.long0 + lon);
+ }
+ else {
+ lat = this.phic0;
+ lon = 0;
+ }
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$16 = ["gnom"];
+ var gnom = {
+ init: init$15,
+ forward: forward$14,
+ inverse: inverse$14,
+ names: names$16
+ };
+
+ var iqsfnz = function(eccent, q) {
+ var temp = 1 - (1 - eccent * eccent) / (2 * eccent) * Math.log((1 - eccent) / (1 + eccent));
+ if (Math.abs(Math.abs(q) - temp) < 1.0E-6) {
+ if (q < 0) {
+ return (-1 * HALF_PI);
+ }
+ else {
+ return 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 - con * con, 2) / (2 * cos_phi) * (q / (1 - eccent * eccent) - sin_phi / (1 - con * con) + 0.5 / eccent * Math.log((1 - con) / (1 + con)));
+ phi += dphi;
+ if (Math.abs(dphi) <= 0.0000000001) {
+ return phi;
+ }
+ }
+
+ //console.log("IQSFN-CONV:Latitude failed to converge after 30 iterations");
+ return NaN;
+ };
+
+ /*
+ reference:
+ "Cartographic Projection Procedures for the UNIX Environment-
+ A User's Manual" by Gerald I. Evenden,
+ USGS Open File Report 90-284and Release 4 Interim Reports (2003)
+ */
+ function init$16() {
+ //no-op
+ if (!this.sphere) {
+ this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
+ }
+ }
+
+ /* Cylindrical Equal Area forward equations--mapping lat,long to x,y
+ ------------------------------------------------------------*/
+ function forward$15(p) {
+ var lon = p.x;
+ var lat = p.y;
+ var x, y;
+ /* Forward equations
+ -----------------*/
+ var dlon = adjust_lon(lon - this.long0);
+ if (this.sphere) {
+ x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
+ y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
+ }
+ else {
+ var qs = qsfnz(this.e, Math.sin(lat));
+ x = this.x0 + this.a * this.k0 * dlon;
+ y = this.y0 + this.a * qs * 0.5 / this.k0;
+ }
+
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ /* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
+ ------------------------------------------------------------*/
+ function inverse$15(p) {
+ p.x -= this.x0;
+ p.y -= this.y0;
+ var lon, lat;
+
+ if (this.sphere) {
+ lon = adjust_lon(this.long0 + (p.x / this.a) / Math.cos(this.lat_ts));
+ lat = Math.asin((p.y / this.a) * Math.cos(this.lat_ts));
+ }
+ else {
+ lat = iqsfnz(this.e, 2 * p.y * this.k0 / this.a);
+ lon = adjust_lon(this.long0 + p.x / (this.a * this.k0));
+ }
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$17 = ["cea"];
+ var cea = {
+ init: init$16,
+ forward: forward$15,
+ inverse: inverse$15,
+ names: names$17
+ };
+
+ function init$17() {
+
+ this.x0 = this.x0 || 0;
+ this.y0 = this.y0 || 0;
+ this.lat0 = this.lat0 || 0;
+ this.long0 = this.long0 || 0;
+ this.lat_ts = this.lat_ts || 0;
+ this.title = this.title || "Equidistant Cylindrical (Plate Carre)";
+
+ this.rc = Math.cos(this.lat_ts);
+ }
+
+ // forward equations--mapping lat,long to x,y
+ // -----------------------------------------------------------------
+ function forward$16(p) {
+
+ var lon = p.x;
+ var lat = p.y;
+
+ var dlon = adjust_lon(lon - this.long0);
+ var dlat = adjust_lat(lat - this.lat0);
+ p.x = this.x0 + (this.a * dlon * this.rc);
+ p.y = this.y0 + (this.a * dlat);
+ return p;
+ }
+
+ // inverse equations--mapping x,y to lat/long
+ // -----------------------------------------------------------------
+ function inverse$16(p) {
+
+ var x = p.x;
+ var y = p.y;
+
+ p.x = adjust_lon(this.long0 + ((x - this.x0) / (this.a * this.rc)));
+ p.y = adjust_lat(this.lat0 + ((y - this.y0) / (this.a)));
+ return p;
+ }
+
+ var names$18 = ["Equirectangular", "Equidistant_Cylindrical", "eqc"];
+ var eqc = {
+ init: init$17,
+ forward: forward$16,
+ inverse: inverse$16,
+ names: names$18
+ };
+
+ var MAX_ITER$2 = 20;
+
+ function init$18() {
+ /* Place parameters in static storage for common use
+ -------------------------------------------------*/
+ this.temp = this.b / this.a;
+ this.es = 1 - Math.pow(this.temp, 2); // devait etre dans tmerc.js mais n y est pas donc je commente sinon retour de valeurs nulles
+ this.e = Math.sqrt(this.es);
+ 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); //si que des zeros le calcul ne se fait pas
+ }
+
+ /* Polyconic forward equations--mapping lat,long to x,y
+ ---------------------------------------------------*/
+ function forward$17(p) {
+ var lon = p.x;
+ var lat = p.y;
+ var x, y, el;
+ var dlon = adjust_lon(lon - this.long0);
+ el = dlon * Math.sin(lat);
+ if (this.sphere) {
+ if (Math.abs(lat) <= EPSLN) {
+ x = this.a * dlon;
+ y = -1 * this.a * this.lat0;
+ }
+ else {
+ x = this.a * Math.sin(el) / Math.tan(lat);
+ y = this.a * (adjust_lat(lat - this.lat0) + (1 - Math.cos(el)) / Math.tan(lat));
+ }
+ }
+ else {
+ if (Math.abs(lat) <= EPSLN) {
+ x = this.a * dlon;
+ y = -1 * this.ml0;
+ }
+ else {
+ var nl = gN(this.a, this.e, Math.sin(lat)) / Math.tan(lat);
+ x = nl * Math.sin(el);
+ y = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, lat) - this.ml0 + nl * (1 - Math.cos(el));
+ }
+
+ }
+ p.x = x + this.x0;
+ p.y = y + this.y0;
+ return p;
+ }
+
+ /* Inverse equations
+ -----------------*/
+ function inverse$17(p) {
+ var lon, lat, x, y, i;
+ var al, bl;
+ var phi, dphi;
+ x = p.x - this.x0;
+ y = p.y - this.y0;
+
+ if (this.sphere) {
+ if (Math.abs(y + this.a * this.lat0) <= EPSLN) {
+ lon = adjust_lon(x / this.a + this.long0);
+ lat = 0;
+ }
+ else {
+ al = this.lat0 + y / this.a;
+ bl = x * x / this.a / this.a + al * al;
+ phi = al;
+ var tanphi;
+ for (i = MAX_ITER$2; i; --i) {
+ tanphi = Math.tan(phi);
+ dphi = -1 * (al * (phi * tanphi + 1) - phi - 0.5 * (phi * phi + bl) * tanphi) / ((phi - al) / tanphi - 1);
+ phi += dphi;
+ if (Math.abs(dphi) <= EPSLN) {
+ lat = phi;
+ break;
+ }
+ }
+ lon = adjust_lon(this.long0 + (Math.asin(x * Math.tan(phi) / this.a)) / Math.sin(lat));
+ }
+ }
+ else {
+ if (Math.abs(y + this.ml0) <= EPSLN) {
+ lat = 0;
+ lon = adjust_lon(this.long0 + x / this.a);
+ }
+ else {
+
+ al = (this.ml0 + y) / this.a;
+ bl = x * x / this.a / this.a + al * al;
+ phi = al;
+ var cl, mln, mlnp, ma;
+ var con;
+ for (i = MAX_ITER$2; i; --i) {
+ con = this.e * Math.sin(phi);
+ cl = Math.sqrt(1 - con * con) * Math.tan(phi);
+ mln = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, phi);
+ mlnp = this.e0 - 2 * this.e1 * Math.cos(2 * phi) + 4 * this.e2 * Math.cos(4 * phi) - 6 * this.e3 * Math.cos(6 * phi);
+ ma = mln / this.a;
+ dphi = (al * (cl * ma + 1) - ma - 0.5 * cl * (ma * ma + bl)) / (this.es * Math.sin(2 * phi) * (ma * ma + bl - 2 * al * ma) / (4 * cl) + (al - ma) * (cl * mlnp - 2 / Math.sin(2 * phi)) - mlnp);
+ phi -= dphi;
+ if (Math.abs(dphi) <= EPSLN) {
+ lat = phi;
+ break;
+ }
+ }
+
+ //lat=phi4z(this.e,this.e0,this.e1,this.e2,this.e3,al,bl,0,0);
+ cl = Math.sqrt(1 - this.es * Math.pow(Math.sin(lat), 2)) * Math.tan(lat);
+ lon = adjust_lon(this.long0 + Math.asin(x * cl / this.a) / Math.sin(lat));
+ }
+ }
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$19 = ["Polyconic", "poly"];
+ var poly = {
+ init: init$18,
+ forward: forward$17,
+ inverse: inverse$17,
+ names: names$19
+ };
+
+ /*
+ reference
+ Department of Land and Survey Technical Circular 1973/32
+ http://www.linz.govt.nz/docs/miscellaneous/nz-map-definition.pdf
+ OSG Technical Report 4.1
+ http://www.linz.govt.nz/docs/miscellaneous/nzmg.pdf
+ */
+
+ /**
+ * iterations: Number of iterations to refine inverse transform.
+ * 0 -> km accuracy
+ * 1 -> m accuracy -- suitable for most mapping applications
+ * 2 -> mm accuracy
+ */
+
+
+ function init$19() {
+ this.A = [];
+ this.A[1] = 0.6399175073;
+ this.A[2] = -0.1358797613;
+ this.A[3] = 0.063294409;
+ this.A[4] = -0.02526853;
+ this.A[5] = 0.0117879;
+ this.A[6] = -0.0055161;
+ this.A[7] = 0.0026906;
+ this.A[8] = -0.001333;
+ this.A[9] = 0.00067;
+ this.A[10] = -0.00034;
+
+ this.B_re = [];
+ this.B_im = [];
+ this.B_re[1] = 0.7557853228;
+ this.B_im[1] = 0;
+ this.B_re[2] = 0.249204646;
+ this.B_im[2] = 0.003371507;
+ this.B_re[3] = -0.001541739;
+ this.B_im[3] = 0.041058560;
+ this.B_re[4] = -0.10162907;
+ this.B_im[4] = 0.01727609;
+ this.B_re[5] = -0.26623489;
+ this.B_im[5] = -0.36249218;
+ this.B_re[6] = -0.6870983;
+ this.B_im[6] = -1.1651967;
+
+ this.C_re = [];
+ this.C_im = [];
+ this.C_re[1] = 1.3231270439;
+ this.C_im[1] = 0;
+ this.C_re[2] = -0.577245789;
+ this.C_im[2] = -0.007809598;
+ this.C_re[3] = 0.508307513;
+ this.C_im[3] = -0.112208952;
+ this.C_re[4] = -0.15094762;
+ this.C_im[4] = 0.18200602;
+ this.C_re[5] = 1.01418179;
+ this.C_im[5] = 1.64497696;
+ this.C_re[6] = 1.9660549;
+ this.C_im[6] = 2.5127645;
+
+ this.D = [];
+ this.D[1] = 1.5627014243;
+ this.D[2] = 0.5185406398;
+ this.D[3] = -0.03333098;
+ this.D[4] = -0.1052906;
+ this.D[5] = -0.0368594;
+ this.D[6] = 0.007317;
+ this.D[7] = 0.01220;
+ this.D[8] = 0.00394;
+ this.D[9] = -0.0013;
+ }
+
+ /**
+ New Zealand Map Grid Forward - long/lat to x/y
+ long/lat in radians
+ */
+ function forward$18(p) {
+ var n;
+ var lon = p.x;
+ var lat = p.y;
+
+ var delta_lat = lat - this.lat0;
+ var delta_lon = lon - this.long0;
+
+ // 1. Calculate d_phi and d_psi ... // and d_lambda
+ // For this algorithm, delta_latitude is in seconds of arc x 10-5, so we need to scale to those units. Longitude is radians.
+ var d_phi = delta_lat / SEC_TO_RAD * 1E-5;
+ var d_lambda = delta_lon;
+ var d_phi_n = 1; // d_phi^0
+
+ var d_psi = 0;
+ for (n = 1; n <= 10; n++) {
+ d_phi_n = d_phi_n * d_phi;
+ d_psi = d_psi + this.A[n] * d_phi_n;
+ }
+
+ // 2. Calculate theta
+ var th_re = d_psi;
+ var th_im = d_lambda;
+
+ // 3. Calculate z
+ var th_n_re = 1;
+ var th_n_im = 0; // theta^0
+ var th_n_re1;
+ var th_n_im1;
+
+ var z_re = 0;
+ var z_im = 0;
+ for (n = 1; n <= 6; n++) {
+ th_n_re1 = th_n_re * th_re - th_n_im * th_im;
+ th_n_im1 = th_n_im * th_re + th_n_re * th_im;
+ th_n_re = th_n_re1;
+ th_n_im = th_n_im1;
+ z_re = z_re + this.B_re[n] * th_n_re - this.B_im[n] * th_n_im;
+ z_im = z_im + this.B_im[n] * th_n_re + this.B_re[n] * th_n_im;
+ }
+
+ // 4. Calculate easting and northing
+ p.x = (z_im * this.a) + this.x0;
+ p.y = (z_re * this.a) + this.y0;
+
+ return p;
+ }
+
+ /**
+ New Zealand Map Grid Inverse - x/y to long/lat
+ */
+ function inverse$18(p) {
+ var n;
+ var x = p.x;
+ var y = p.y;
+
+ var delta_x = x - this.x0;
+ var delta_y = y - this.y0;
+
+ // 1. Calculate z
+ var z_re = delta_y / this.a;
+ var z_im = delta_x / this.a;
+
+ // 2a. Calculate theta - first approximation gives km accuracy
+ var z_n_re = 1;
+ var z_n_im = 0; // z^0
+ var z_n_re1;
+ var z_n_im1;
+
+ var th_re = 0;
+ var th_im = 0;
+ for (n = 1; n <= 6; n++) {
+ z_n_re1 = z_n_re * z_re - z_n_im * z_im;
+ z_n_im1 = z_n_im * z_re + z_n_re * z_im;
+ z_n_re = z_n_re1;
+ z_n_im = z_n_im1;
+ th_re = th_re + this.C_re[n] * z_n_re - this.C_im[n] * z_n_im;
+ th_im = th_im + this.C_im[n] * z_n_re + this.C_re[n] * z_n_im;
+ }
+
+ // 2b. Iterate to refine the accuracy of the calculation
+ // 0 iterations gives km accuracy
+ // 1 iteration gives m accuracy -- good enough for most mapping applications
+ // 2 iterations bives mm accuracy
+ for (var i = 0; i < this.iterations; i++) {
+ var th_n_re = th_re;
+ var th_n_im = th_im;
+ var th_n_re1;
+ var th_n_im1;
+
+ var num_re = z_re;
+ var num_im = z_im;
+ for (n = 2; n <= 6; n++) {
+ th_n_re1 = th_n_re * th_re - th_n_im * th_im;
+ th_n_im1 = th_n_im * th_re + th_n_re * th_im;
+ th_n_re = th_n_re1;
+ th_n_im = th_n_im1;
+ num_re = num_re + (n - 1) * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
+ num_im = num_im + (n - 1) * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
+ }
+
+ th_n_re = 1;
+ th_n_im = 0;
+ var den_re = this.B_re[1];
+ var den_im = this.B_im[1];
+ for (n = 2; n <= 6; n++) {
+ th_n_re1 = th_n_re * th_re - th_n_im * th_im;
+ th_n_im1 = th_n_im * th_re + th_n_re * th_im;
+ th_n_re = th_n_re1;
+ th_n_im = th_n_im1;
+ den_re = den_re + n * (this.B_re[n] * th_n_re - this.B_im[n] * th_n_im);
+ den_im = den_im + n * (this.B_im[n] * th_n_re + this.B_re[n] * th_n_im);
+ }
+
+ // Complex division
+ var den2 = den_re * den_re + den_im * den_im;
+ th_re = (num_re * den_re + num_im * den_im) / den2;
+ th_im = (num_im * den_re - num_re * den_im) / den2;
+ }
+
+ // 3. Calculate d_phi ... // and d_lambda
+ var d_psi = th_re;
+ var d_lambda = th_im;
+ var d_psi_n = 1; // d_psi^0
+
+ var d_phi = 0;
+ for (n = 1; n <= 9; n++) {
+ d_psi_n = d_psi_n * d_psi;
+ d_phi = d_phi + this.D[n] * d_psi_n;
+ }
+
+ // 4. Calculate latitude and longitude
+ // d_phi is calcuated in second of arc * 10^-5, so we need to scale back to radians. d_lambda is in radians.
+ var lat = this.lat0 + (d_phi * SEC_TO_RAD * 1E5);
+ var lon = this.long0 + d_lambda;
+
+ p.x = lon;
+ p.y = lat;
+
+ return p;
+ }
+
+ var names$20 = ["New_Zealand_Map_Grid", "nzmg"];
+ var nzmg = {
+ init: init$19,
+ forward: forward$18,
+ inverse: inverse$18,
+ names: names$20
+ };
+
+ /*
+ reference
+ "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
+ The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
+ */
+
+
+ /* Initialize the Miller Cylindrical projection
+ -------------------------------------------*/
+ function init$20() {
+ //no-op
+ }
+
+ /* Miller Cylindrical forward equations--mapping lat,long to x,y
+ ------------------------------------------------------------*/
+ function forward$19(p) {
+ var lon = p.x;
+ var lat = p.y;
+ /* Forward equations
+ -----------------*/
+ var dlon = adjust_lon(lon - this.long0);
+ var x = this.x0 + this.a * dlon;
+ var y = this.y0 + this.a * Math.log(Math.tan((Math.PI / 4) + (lat / 2.5))) * 1.25;
+
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ /* Miller Cylindrical inverse equations--mapping x,y to lat/long
+ ------------------------------------------------------------*/
+ function inverse$19(p) {
+ p.x -= this.x0;
+ p.y -= this.y0;
+
+ var lon = adjust_lon(this.long0 + p.x / this.a);
+ var lat = 2.5 * (Math.atan(Math.exp(0.8 * p.y / this.a)) - Math.PI / 4);
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$21 = ["Miller_Cylindrical", "mill"];
+ var mill = {
+ init: init$20,
+ forward: forward$19,
+ inverse: inverse$19,
+ names: names$21
+ };
+
+ var MAX_ITER$3 = 20;
+ function init$21() {
+ /* Place parameters in static storage for common use
+ -------------------------------------------------*/
+
+
+ if (!this.sphere) {
+ this.en = pj_enfn(this.es);
+ }
+ else {
+ this.n = 1;
+ this.m = 0;
+ this.es = 0;
+ this.C_y = Math.sqrt((this.m + 1) / this.n);
+ this.C_x = this.C_y / (this.m + 1);
+ }
+
+ }
+
+ /* Sinusoidal forward equations--mapping lat,long to x,y
+ -----------------------------------------------------*/
+ function forward$20(p) {
+ var x, y;
+ var lon = p.x;
+ var lat = p.y;
+ /* Forward equations
+ -----------------*/
+ lon = adjust_lon(lon - this.long0);
+
+ if (this.sphere) {
+ if (!this.m) {
+ lat = this.n !== 1 ? Math.asin(this.n * Math.sin(lat)) : lat;
+ }
+ else {
+ var k = this.n * Math.sin(lat);
+ for (var i = MAX_ITER$3; i; --i) {
+ var V = (this.m * lat + Math.sin(lat) - k) / (this.m + Math.cos(lat));
+ lat -= V;
+ if (Math.abs(V) < EPSLN) {
+ break;
+ }
+ }
+ }
+ x = this.a * this.C_x * lon * (this.m + Math.cos(lat));
+ y = this.a * this.C_y * lat;
+
+ }
+ else {
+
+ var s = Math.sin(lat);
+ var c = Math.cos(lat);
+ y = this.a * pj_mlfn(lat, s, c, this.en);
+ x = this.a * lon * c / Math.sqrt(1 - this.es * s * s);
+ }
+
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ function inverse$20(p) {
+ var lat, temp, lon, s;
+
+ p.x -= this.x0;
+ lon = p.x / this.a;
+ p.y -= this.y0;
+ lat = p.y / this.a;
+
+ if (this.sphere) {
+ lat /= this.C_y;
+ lon = lon / (this.C_x * (this.m + Math.cos(lat)));
+ if (this.m) {
+ lat = asinz((this.m * lat + Math.sin(lat)) / this.n);
+ }
+ else if (this.n !== 1) {
+ lat = asinz(Math.sin(lat) / this.n);
+ }
+ lon = adjust_lon(lon + this.long0);
+ lat = adjust_lat(lat);
+ }
+ else {
+ lat = pj_inv_mlfn(p.y / this.a, this.es, this.en);
+ s = Math.abs(lat);
+ if (s < HALF_PI) {
+ s = Math.sin(lat);
+ temp = this.long0 + p.x * Math.sqrt(1 - this.es * s * s) / (this.a * Math.cos(lat));
+ //temp = this.long0 + p.x / (this.a * Math.cos(lat));
+ lon = adjust_lon(temp);
+ }
+ else if ((s - EPSLN) < HALF_PI) {
+ lon = this.long0;
+ }
+ }
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$22 = ["Sinusoidal", "sinu"];
+ var sinu = {
+ init: init$21,
+ forward: forward$20,
+ inverse: inverse$20,
+ names: names$22
+ };
+
+ function init$22() {}
+ /* Mollweide forward equations--mapping lat,long to x,y
+ ----------------------------------------------------*/
+ function forward$21(p) {
+
+ /* Forward equations
+ -----------------*/
+ var lon = p.x;
+ var lat = p.y;
+
+ var delta_lon = adjust_lon(lon - this.long0);
+ var theta = lat;
+ var con = Math.PI * Math.sin(lat);
+
+ /* Iterate using the Newton-Raphson method to find theta
+ -----------------------------------------------------*/
+ for (var i = 0; true; i++) {
+ var delta_theta = -(theta + Math.sin(theta) - con) / (1 + Math.cos(theta));
+ theta += delta_theta;
+ if (Math.abs(delta_theta) < EPSLN) {
+ break;
+ }
+ }
+ theta /= 2;
+
+ /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
+ this is done here because of precision problems with "cos(theta)"
+ --------------------------------------------------------------------------*/
+ if (Math.PI / 2 - Math.abs(lat) < EPSLN) {
+ delta_lon = 0;
+ }
+ var x = 0.900316316158 * this.a * delta_lon * Math.cos(theta) + this.x0;
+ var y = 1.4142135623731 * this.a * Math.sin(theta) + this.y0;
+
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ function inverse$21(p) {
+ var theta;
+ var arg;
+
+ /* Inverse equations
+ -----------------*/
+ p.x -= this.x0;
+ p.y -= this.y0;
+ arg = p.y / (1.4142135623731 * this.a);
+
+ /* Because of division by zero problems, 'arg' can not be 1. Therefore
+ a number very close to one is used instead.
+ -------------------------------------------------------------------*/
+ if (Math.abs(arg) > 0.999999999999) {
+ arg = 0.999999999999;
+ }
+ theta = Math.asin(arg);
+ var lon = adjust_lon(this.long0 + (p.x / (0.900316316158 * this.a * Math.cos(theta))));
+ if (lon < (-Math.PI)) {
+ lon = -Math.PI;
+ }
+ if (lon > Math.PI) {
+ lon = Math.PI;
+ }
+ arg = (2 * theta + Math.sin(2 * theta)) / Math.PI;
+ if (Math.abs(arg) > 1) {
+ arg = 1;
+ }
+ var lat = Math.asin(arg);
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$23 = ["Mollweide", "moll"];
+ var moll = {
+ init: init$22,
+ forward: forward$21,
+ inverse: inverse$21,
+ names: names$23
+ };
+
+ function init$23() {
+
+ /* Place parameters in static storage for common use
+ -------------------------------------------------*/
+ // Standard Parallels cannot be equal and on opposite sides of the equator
+ if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
+ return;
+ }
+ this.lat2 = this.lat2 || this.lat1;
+ this.temp = this.b / this.a;
+ this.es = 1 - Math.pow(this.temp, 2);
+ this.e = Math.sqrt(this.es);
+ this.e0 = e0fn(this.es);
+ this.e1 = e1fn(this.es);
+ this.e2 = e2fn(this.es);
+ this.e3 = e3fn(this.es);
+
+ this.sinphi = Math.sin(this.lat1);
+ this.cosphi = Math.cos(this.lat1);
+
+ this.ms1 = msfnz(this.e, this.sinphi, this.cosphi);
+ this.ml1 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat1);
+
+ if (Math.abs(this.lat1 - this.lat2) < EPSLN) {
+ this.ns = this.sinphi;
+ }
+ else {
+ this.sinphi = Math.sin(this.lat2);
+ this.cosphi = Math.cos(this.lat2);
+ this.ms2 = msfnz(this.e, this.sinphi, this.cosphi);
+ this.ml2 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat2);
+ this.ns = (this.ms1 - this.ms2) / (this.ml2 - this.ml1);
+ }
+ this.g = this.ml1 + this.ms1 / this.ns;
+ this.ml0 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
+ this.rh = this.a * (this.g - this.ml0);
+ }
+
+ /* Equidistant Conic forward equations--mapping lat,long to x,y
+ -----------------------------------------------------------*/
+ function forward$22(p) {
+ var lon = p.x;
+ var lat = p.y;
+ var rh1;
+
+ /* Forward equations
+ -----------------*/
+ if (this.sphere) {
+ rh1 = this.a * (this.g - lat);
+ }
+ else {
+ var ml = mlfn(this.e0, this.e1, this.e2, this.e3, lat);
+ rh1 = this.a * (this.g - ml);
+ }
+ var theta = this.ns * adjust_lon(lon - this.long0);
+ var x = this.x0 + rh1 * Math.sin(theta);
+ var y = this.y0 + this.rh - rh1 * Math.cos(theta);
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ /* Inverse equations
+ -----------------*/
+ function inverse$22(p) {
+ p.x -= this.x0;
+ p.y = this.rh - p.y + this.y0;
+ var con, rh1, lat, lon;
+ if (this.ns >= 0) {
+ rh1 = Math.sqrt(p.x * p.x + p.y * p.y);
+ con = 1;
+ }
+ else {
+ rh1 = -Math.sqrt(p.x * p.x + p.y * p.y);
+ con = -1;
+ }
+ var theta = 0;
+ if (rh1 !== 0) {
+ theta = Math.atan2(con * p.x, con * p.y);
+ }
+
+ if (this.sphere) {
+ lon = adjust_lon(this.long0 + theta / this.ns);
+ lat = adjust_lat(this.g - rh1 / this.a);
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+ else {
+ var ml = this.g - rh1 / this.a;
+ lat = imlfn(ml, this.e0, this.e1, this.e2, this.e3);
+ lon = adjust_lon(this.long0 + theta / this.ns);
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ }
+
+ var names$24 = ["Equidistant_Conic", "eqdc"];
+ var eqdc = {
+ init: init$23,
+ forward: forward$22,
+ inverse: inverse$22,
+ names: names$24
+ };
+
+ /* Initialize the Van Der Grinten projection
+ ----------------------------------------*/
+ function init$24() {
+ //this.R = 6370997; //Radius of earth
+ this.R = this.a;
+ }
+
+ function forward$23(p) {
+
+ var lon = p.x;
+ var lat = p.y;
+
+ /* Forward equations
+ -----------------*/
+ var dlon = adjust_lon(lon - this.long0);
+ var x, y;
+
+ if (Math.abs(lat) <= EPSLN) {
+ x = this.x0 + this.R * dlon;
+ y = this.y0;
+ }
+ var theta = asinz(2 * Math.abs(lat / Math.PI));
+ if ((Math.abs(dlon) <= EPSLN) || (Math.abs(Math.abs(lat) - HALF_PI) <= EPSLN)) {
+ x = this.x0;
+ if (lat >= 0) {
+ y = this.y0 + Math.PI * this.R * Math.tan(0.5 * theta);
+ }
+ else {
+ y = this.y0 + Math.PI * this.R * -Math.tan(0.5 * theta);
+ }
+ // return(OK);
+ }
+ var al = 0.5 * Math.abs((Math.PI / dlon) - (dlon / Math.PI));
+ var asq = al * al;
+ var sinth = Math.sin(theta);
+ var costh = Math.cos(theta);
+
+ var g = costh / (sinth + costh - 1);
+ var gsq = g * g;
+ var m = g * (2 / sinth - 1);
+ var msq = m * m;
+ var con = Math.PI * this.R * (al * (g - msq) + Math.sqrt(asq * (g - msq) * (g - msq) - (msq + asq) * (gsq - msq))) / (msq + asq);
+ if (dlon < 0) {
+ con = -con;
+ }
+ x = this.x0 + con;
+ //con = Math.abs(con / (Math.PI * this.R));
+ var q = asq + g;
+ con = Math.PI * this.R * (m * q - al * Math.sqrt((msq + asq) * (asq + 1) - q * q)) / (msq + asq);
+ if (lat >= 0) {
+ //y = this.y0 + Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
+ y = this.y0 + con;
+ }
+ else {
+ //y = this.y0 - Math.PI * this.R * Math.sqrt(1 - con * con - 2 * al * con);
+ y = this.y0 - con;
+ }
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ /* Van Der Grinten inverse equations--mapping x,y to lat/long
+ ---------------------------------------------------------*/
+ function inverse$23(p) {
+ var lon, lat;
+ var xx, yy, xys, c1, c2, c3;
+ var a1;
+ var m1;
+ var con;
+ var th1;
+ var d;
+
+ /* inverse equations
+ -----------------*/
+ p.x -= this.x0;
+ p.y -= this.y0;
+ con = Math.PI * this.R;
+ xx = p.x / con;
+ yy = p.y / con;
+ xys = xx * xx + yy * yy;
+ c1 = -Math.abs(yy) * (1 + xys);
+ c2 = c1 - 2 * yy * yy + xx * xx;
+ c3 = -2 * c1 + 1 + 2 * yy * yy + xys * xys;
+ d = yy * yy / c3 + (2 * c2 * c2 * c2 / c3 / c3 / c3 - 9 * c1 * c2 / c3 / c3) / 27;
+ a1 = (c1 - c2 * c2 / 3 / c3) / c3;
+ m1 = 2 * Math.sqrt(-a1 / 3);
+ con = ((3 * d) / a1) / m1;
+ if (Math.abs(con) > 1) {
+ if (con >= 0) {
+ con = 1;
+ }
+ else {
+ con = -1;
+ }
+ }
+ th1 = Math.acos(con) / 3;
+ if (p.y >= 0) {
+ lat = (-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
+ }
+ else {
+ lat = -(-m1 * Math.cos(th1 + Math.PI / 3) - c2 / 3 / c3) * Math.PI;
+ }
+
+ if (Math.abs(xx) < EPSLN) {
+ lon = this.long0;
+ }
+ else {
+ lon = adjust_lon(this.long0 + Math.PI * (xys - 1 + Math.sqrt(1 + 2 * (xx * xx - yy * yy) + xys * xys)) / 2 / xx);
+ }
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$25 = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
+ var vandg = {
+ init: init$24,
+ forward: forward$23,
+ inverse: inverse$23,
+ names: names$25
+ };
+
+ function init$25() {
+ this.sin_p12 = Math.sin(this.lat0);
+ this.cos_p12 = Math.cos(this.lat0);
+ }
+
+ function forward$24(p) {
+ var lon = p.x;
+ var lat = p.y;
+ var sinphi = Math.sin(p.y);
+ var cosphi = Math.cos(p.y);
+ var dlon = adjust_lon(lon - this.long0);
+ var e0, e1, e2, e3, Mlp, Ml, tanphi, Nl1, Nl, psi, Az, G, H, GH, Hs, c, kp, cos_c, s, s2, s3, s4, s5;
+ if (this.sphere) {
+ if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
+ //North Pole case
+ p.x = this.x0 + this.a * (HALF_PI - lat) * Math.sin(dlon);
+ p.y = this.y0 - this.a * (HALF_PI - lat) * Math.cos(dlon);
+ return p;
+ }
+ else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
+ //South Pole case
+ p.x = this.x0 + this.a * (HALF_PI + lat) * Math.sin(dlon);
+ p.y = this.y0 + this.a * (HALF_PI + lat) * Math.cos(dlon);
+ return p;
+ }
+ else {
+ //default case
+ cos_c = this.sin_p12 * sinphi + this.cos_p12 * cosphi * Math.cos(dlon);
+ c = Math.acos(cos_c);
+ kp = c / Math.sin(c);
+ p.x = this.x0 + this.a * kp * cosphi * Math.sin(dlon);
+ p.y = this.y0 + this.a * kp * (this.cos_p12 * sinphi - this.sin_p12 * cosphi * Math.cos(dlon));
+ return p;
+ }
+ }
+ else {
+ e0 = e0fn(this.es);
+ e1 = e1fn(this.es);
+ e2 = e2fn(this.es);
+ e3 = e3fn(this.es);
+ if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
+ //North Pole case
+ Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
+ Ml = this.a * mlfn(e0, e1, e2, e3, lat);
+ p.x = this.x0 + (Mlp - Ml) * Math.sin(dlon);
+ p.y = this.y0 - (Mlp - Ml) * Math.cos(dlon);
+ return p;
+ }
+ else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
+ //South Pole case
+ Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
+ Ml = this.a * mlfn(e0, e1, e2, e3, lat);
+ p.x = this.x0 + (Mlp + Ml) * Math.sin(dlon);
+ p.y = this.y0 + (Mlp + Ml) * Math.cos(dlon);
+ return p;
+ }
+ else {
+ //Default case
+ tanphi = sinphi / cosphi;
+ Nl1 = gN(this.a, this.e, this.sin_p12);
+ Nl = gN(this.a, this.e, sinphi);
+ psi = Math.atan((1 - this.es) * tanphi + this.es * Nl1 * this.sin_p12 / (Nl * cosphi));
+ Az = Math.atan2(Math.sin(dlon), this.cos_p12 * Math.tan(psi) - this.sin_p12 * Math.cos(dlon));
+ if (Az === 0) {
+ s = Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
+ }
+ else if (Math.abs(Math.abs(Az) - Math.PI) <= EPSLN) {
+ s = -Math.asin(this.cos_p12 * Math.sin(psi) - this.sin_p12 * Math.cos(psi));
+ }
+ else {
+ s = Math.asin(Math.sin(dlon) * Math.cos(psi) / Math.sin(Az));
+ }
+ G = this.e * this.sin_p12 / Math.sqrt(1 - this.es);
+ H = this.e * this.cos_p12 * Math.cos(Az) / Math.sqrt(1 - this.es);
+ GH = G * H;
+ Hs = H * H;
+ s2 = s * s;
+ s3 = s2 * s;
+ s4 = s3 * s;
+ s5 = s4 * s;
+ c = Nl1 * s * (1 - s2 * Hs * (1 - Hs) / 6 + s3 / 8 * GH * (1 - 2 * Hs) + s4 / 120 * (Hs * (4 - 7 * Hs) - 3 * G * G * (1 - 7 * Hs)) - s5 / 48 * GH);
+ p.x = this.x0 + c * Math.sin(Az);
+ p.y = this.y0 + c * Math.cos(Az);
+ return p;
+ }
+ }
+
+
+ }
+
+ function inverse$24(p) {
+ p.x -= this.x0;
+ p.y -= this.y0;
+ var rh, z, sinz, cosz, lon, lat, con, e0, e1, e2, e3, Mlp, M, N1, psi, Az, cosAz, tmp, A, B, D, Ee, F;
+ if (this.sphere) {
+ rh = Math.sqrt(p.x * p.x + p.y * p.y);
+ if (rh > (2 * HALF_PI * this.a)) {
+ return;
+ }
+ z = rh / this.a;
+
+ sinz = Math.sin(z);
+ cosz = Math.cos(z);
+
+ lon = this.long0;
+ if (Math.abs(rh) <= EPSLN) {
+ lat = this.lat0;
+ }
+ else {
+ lat = asinz(cosz * this.sin_p12 + (p.y * sinz * this.cos_p12) / rh);
+ con = Math.abs(this.lat0) - HALF_PI;
+ if (Math.abs(con) <= EPSLN) {
+ if (this.lat0 >= 0) {
+ lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
+ }
+ else {
+ lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
+ }
+ }
+ else {
+ /*con = cosz - this.sin_p12 * Math.sin(lat);
+ if ((Math.abs(con) < EPSLN) && (Math.abs(p.x) < EPSLN)) {
+ //no-op, just keep the lon value as is
+ } else {
+ var temp = Math.atan2((p.x * sinz * this.cos_p12), (con * rh));
+ lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p12), (con * rh)));
+ }*/
+ lon = adjust_lon(this.long0 + Math.atan2(p.x * sinz, rh * this.cos_p12 * cosz - p.y * this.sin_p12 * sinz));
+ }
+ }
+
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+ else {
+ e0 = e0fn(this.es);
+ e1 = e1fn(this.es);
+ e2 = e2fn(this.es);
+ e3 = e3fn(this.es);
+ if (Math.abs(this.sin_p12 - 1) <= EPSLN) {
+ //North pole case
+ Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
+ rh = Math.sqrt(p.x * p.x + p.y * p.y);
+ M = Mlp - rh;
+ lat = imlfn(M / this.a, e0, e1, e2, e3);
+ lon = adjust_lon(this.long0 + Math.atan2(p.x, - 1 * p.y));
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+ else if (Math.abs(this.sin_p12 + 1) <= EPSLN) {
+ //South pole case
+ Mlp = this.a * mlfn(e0, e1, e2, e3, HALF_PI);
+ rh = Math.sqrt(p.x * p.x + p.y * p.y);
+ M = rh - Mlp;
+
+ lat = imlfn(M / this.a, e0, e1, e2, e3);
+ lon = adjust_lon(this.long0 + Math.atan2(p.x, p.y));
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+ else {
+ //default case
+ rh = Math.sqrt(p.x * p.x + p.y * p.y);
+ Az = Math.atan2(p.x, p.y);
+ N1 = gN(this.a, this.e, this.sin_p12);
+ cosAz = Math.cos(Az);
+ tmp = this.e * this.cos_p12 * cosAz;
+ A = -tmp * tmp / (1 - this.es);
+ B = 3 * this.es * (1 - A) * this.sin_p12 * this.cos_p12 * cosAz / (1 - this.es);
+ D = rh / N1;
+ Ee = D - A * (1 + A) * Math.pow(D, 3) / 6 - B * (1 + 3 * A) * Math.pow(D, 4) / 24;
+ F = 1 - A * Ee * Ee / 2 - D * Ee * Ee * Ee / 6;
+ psi = Math.asin(this.sin_p12 * Math.cos(Ee) + this.cos_p12 * Math.sin(Ee) * cosAz);
+ lon = adjust_lon(this.long0 + Math.asin(Math.sin(Az) * Math.sin(Ee) / Math.cos(psi)));
+ lat = Math.atan((1 - this.es * F * this.sin_p12 / Math.sin(psi)) * Math.tan(psi) / (1 - this.es));
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+ }
+
+ }
+
+ var names$26 = ["Azimuthal_Equidistant", "aeqd"];
+ var aeqd = {
+ init: init$25,
+ forward: forward$24,
+ inverse: inverse$24,
+ names: names$26
+ };
+
+ function init$26() {
+ //double temp; /* temporary variable */
+
+ /* Place parameters in static storage for common use
+ -------------------------------------------------*/
+ this.sin_p14 = Math.sin(this.lat0);
+ this.cos_p14 = Math.cos(this.lat0);
+ }
+
+ /* Orthographic forward equations--mapping lat,long to x,y
+ ---------------------------------------------------*/
+ function forward$25(p) {
+ var sinphi, cosphi; /* sin and cos value */
+ var dlon; /* delta longitude value */
+ var coslon; /* cos of longitude */
+ var ksp; /* scale factor */
+ var g, x, y;
+ var lon = p.x;
+ var lat = p.y;
+ /* Forward equations
+ -----------------*/
+ dlon = adjust_lon(lon - this.long0);
+
+ sinphi = Math.sin(lat);
+ cosphi = Math.cos(lat);
+
+ coslon = Math.cos(dlon);
+ g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
+ ksp = 1;
+ if ((g > 0) || (Math.abs(g) <= EPSLN)) {
+ x = this.a * ksp * cosphi * Math.sin(dlon);
+ y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
+ }
+ p.x = x;
+ p.y = y;
+ return p;
+ }
+
+ function inverse$25(p) {
+ var rh; /* height above ellipsoid */
+ var z; /* angle */
+ var sinz, cosz; /* sin of z and cos of z */
+ var con;
+ var lon, lat;
+ /* Inverse equations
+ -----------------*/
+ p.x -= this.x0;
+ p.y -= this.y0;
+ rh = Math.sqrt(p.x * p.x + p.y * p.y);
+ z = asinz(rh / this.a);
+
+ sinz = Math.sin(z);
+ cosz = Math.cos(z);
+
+ lon = this.long0;
+ if (Math.abs(rh) <= EPSLN) {
+ lat = this.lat0;
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+ lat = asinz(cosz * this.sin_p14 + (p.y * sinz * this.cos_p14) / rh);
+ con = Math.abs(this.lat0) - HALF_PI;
+ if (Math.abs(con) <= EPSLN) {
+ if (this.lat0 >= 0) {
+ lon = adjust_lon(this.long0 + Math.atan2(p.x, - p.y));
+ }
+ else {
+ lon = adjust_lon(this.long0 - Math.atan2(-p.x, p.y));
+ }
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+ lon = adjust_lon(this.long0 + Math.atan2((p.x * sinz), rh * this.cos_p14 * cosz - p.y * this.sin_p14 * sinz));
+ p.x = lon;
+ p.y = lat;
+ return p;
+ }
+
+ var names$27 = ["ortho"];
+ var ortho = {
+ init: init$26,
+ forward: forward$25,
+ inverse: inverse$25,
+ names: names$27
+ };
+
+ var includedProjections = function(proj4){
+ proj4.Proj.projections.add(tmerc);
+ proj4.Proj.projections.add(etmerc);
+ proj4.Proj.projections.add(utm);
+ proj4.Proj.projections.add(sterea);
+ proj4.Proj.projections.add(stere);
+ proj4.Proj.projections.add(somerc);
+ proj4.Proj.projections.add(omerc);
+ proj4.Proj.projections.add(lcc);
+ proj4.Proj.projections.add(krovak);
+ proj4.Proj.projections.add(cass);
+ proj4.Proj.projections.add(laea);
+ proj4.Proj.projections.add(aea);
+ proj4.Proj.projections.add(gnom);
+ proj4.Proj.projections.add(cea);
+ proj4.Proj.projections.add(eqc);
+ proj4.Proj.projections.add(poly);
+ proj4.Proj.projections.add(nzmg);
+ proj4.Proj.projections.add(mill);
+ proj4.Proj.projections.add(sinu);
+ proj4.Proj.projections.add(moll);
+ proj4.Proj.projections.add(eqdc);
+ proj4.Proj.projections.add(vandg);
+ proj4.Proj.projections.add(aeqd);
+ proj4.Proj.projections.add(ortho);
+ };
+
+ proj4$1.defaultDatum = 'WGS84'; //default datum
+ proj4$1.Proj = Projection$1;
+ proj4$1.WGS84 = new proj4$1.Proj('WGS84');
+ proj4$1.Point = Point;
+ proj4$1.toPoint = toPoint;
+ proj4$1.defs = defs;
+ proj4$1.transform = transform;
+ proj4$1.mgrs = mgrs;
+ proj4$1.version = version;
+ includedProjections(proj4$1);
+
+ return proj4$1;
+
+})));
diff --git a/lib/Point.js b/lib/Point.js
index 376eaf4..91b12ab 100644
--- a/lib/Point.js
+++ b/lib/Point.js
@@ -1,4 +1,4 @@
-var mgrs = require('mgrs');
+import {toPoint, forward} from 'mgrs';
function Point(x, y, z) {
if (!(this instanceof Point)) {
@@ -26,9 +26,9 @@ function Point(x, y, z) {
}
Point.fromMGRS = function(mgrsStr) {
- return new Point(mgrs.toPoint(mgrsStr));
+ return new Point(toPoint(mgrsStr));
};
Point.prototype.toMGRS = function(accuracy) {
- return mgrs.forward([this.x, this.y], accuracy);
+ return forward([this.x, this.y], accuracy);
};
-module.exports = Point;
+export default Point;
diff --git a/lib/Proj.js b/lib/Proj.js
index 7bc65db..6ddca38 100644
--- a/lib/Proj.js
+++ b/lib/Proj.js
@@ -1,10 +1,10 @@
-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');
-
+import parseCode from './parseCode';
+import extend from './extend';
+import projections from './projections';
+import {sphere as dc_sphere, eccentricity as dc_eccentricity} from './deriveConstants';
+import Datum from './constants/Datum';
+import datum from './datum';
+import match from './match';
function Projection(srsCode,callback) {
if (!(this instanceof Projection)) {
@@ -26,7 +26,7 @@ function Projection(srsCode,callback) {
return;
}
if (json.datumCode && json.datumCode !== 'none') {
- var datumDef = Datum[json.datumCode];
+ var datumDef = match(Datum, json.datumCode);
if (datumDef) {
json.datum_params = datumDef.towgs84 ? datumDef.towgs84.split(',') : null;
json.ellps = datumDef.ellipse;
@@ -36,18 +36,18 @@ function Projection(srsCode,callback) {
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);
+ var sphere_ = dc_sphere(json.a, json.b, json.rf, json.ellps, json.sphere);
+ var ecc = dc_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;
+ 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;
@@ -66,4 +66,4 @@ function Projection(srsCode,callback) {
}
Projection.projections = projections;
Projection.projections.start();
-module.exports = Projection;
+export default Projection;
diff --git a/lib/adjust_axis.js b/lib/adjust_axis.js
index 8a84296..0579dfc 100644
--- a/lib/adjust_axis.js
+++ b/lib/adjust_axis.js
@@ -1,4 +1,4 @@
-module.exports = function(crs, denorm, point) {
+export default function(crs, denorm, point) {
var xin = point.x,
yin = point.y,
zin = point.z || 0.0;
@@ -49,4 +49,4 @@ module.exports = function(crs, denorm, point) {
}
}
return out;
-};
+}
diff --git a/lib/common/acosh.js b/lib/common/acosh.js
index eaf13d3..4997f3c 100644
--- a/lib/common/acosh.js
+++ b/lib/common/acosh.js
@@ -1,3 +1,3 @@
-module.exports = function(x) {
+export default function(x) {
return 2 * Math.log(Math.sqrt((x + 1) / 2) + Math.sqrt((x - 1) / 2));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/adjust_lat.js b/lib/common/adjust_lat.js
index 057410c..be4c667 100644
--- a/lib/common/adjust_lat.js
+++ b/lib/common/adjust_lat.js
@@ -1,6 +1,6 @@
-var HALF_PI = Math.PI/2;
-var sign = require('./sign');
+import {HALF_PI} from '../constants/values';
+import sign from './sign';
-module.exports = function(x) {
+export default function(x) {
return (Math.abs(x) < HALF_PI) ? x : (x - (sign(x) * Math.PI));
-};
\ No newline at end of file
+}
diff --git a/lib/common/adjust_lon.js b/lib/common/adjust_lon.js
index 371f642..e2f60a3 100644
--- a/lib/common/adjust_lon.js
+++ b/lib/common/adjust_lon.js
@@ -1,11 +1,7 @@
-var TWO_PI = Math.PI * 2;
-// SPI is slightly greater than Math.PI, so values that exceed the -180..180
-// degree range by a tiny amount don't get wrapped. This prevents points that
-// have drifted from their original location along the 180th meridian (due to
-// floating point error) from changing their sign.
-var SPI = 3.14159265359;
-var sign = require('./sign');
-module.exports = function(x) {
+import {TWO_PI, SPI} from '../constants/values';
+import sign from './sign';
+
+export default function(x) {
return (Math.abs(x) <= SPI) ? x : (x - (sign(x) * TWO_PI));
-};
\ No newline at end of file
+}
diff --git a/lib/common/adjust_zone.js b/lib/common/adjust_zone.js
index 276ac15..f97268c 100644
--- a/lib/common/adjust_zone.js
+++ b/lib/common/adjust_zone.js
@@ -1,6 +1,6 @@
-var adjust_lon = require('./adjust_lon');
+import adjust_lon from './adjust_lon';
-module.exports = function(zone, lon) {
+export default function(zone, lon) {
if (zone === undefined) {
zone = Math.floor((adjust_lon(lon) + Math.PI) * 30 / Math.PI);
@@ -15,4 +15,4 @@ module.exports = function(zone, lon) {
return zone - 1;
}
}
-};
+}
diff --git a/lib/common/asinh.js b/lib/common/asinh.js
index 93cba42..51627ee 100644
--- a/lib/common/asinh.js
+++ b/lib/common/asinh.js
@@ -1,4 +1,4 @@
-module.exports = function(x) {
+export default function(x) {
var s = (x >= 0 ? 1 : -1);
return s * (Math.log(Math.abs(x) + Math.sqrt(x * x + 1)));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/asinhy.js b/lib/common/asinhy.js
new file mode 100644
index 0000000..a153f17
--- /dev/null
+++ b/lib/common/asinhy.js
@@ -0,0 +1,9 @@
+import hypot from './hypot';
+import log1py from './log1py';
+
+export default function(x) {
+ var y = Math.abs(x);
+ y = log1py(y * (1 + y / (hypot(1, y) + 1)));
+
+ return x < 0 ? -y : y;
+}
diff --git a/lib/common/asinz.js b/lib/common/asinz.js
index 5a6ef16..8f27ed6 100644
--- a/lib/common/asinz.js
+++ b/lib/common/asinz.js
@@ -1,6 +1,6 @@
-module.exports = function(x) {
+export default function(x) {
if (Math.abs(x) > 1) {
x = (x > 1) ? 1 : -1;
}
return Math.asin(x);
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/atanh.js b/lib/common/atanh.js
index 15ed016..2b082dc 100644
--- a/lib/common/atanh.js
+++ b/lib/common/atanh.js
@@ -1,3 +1,3 @@
-module.exports = function(x) {
+export default function(x) {
return Math.log((x - 1) / (x + 1)) / 2;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/clens.js b/lib/common/clens.js
new file mode 100644
index 0000000..79ece52
--- /dev/null
+++ b/lib/common/clens.js
@@ -0,0 +1,15 @@
+export default function(pp, arg_r) {
+ var r = 2 * Math.cos(arg_r);
+ var i = pp.length - 1;
+ var hr1 = pp[i];
+ var hr2 = 0;
+ var hr;
+
+ while (--i >= 0) {
+ hr = -hr2 + r * hr1 + pp[i];
+ hr2 = hr1;
+ hr1 = hr;
+ }
+
+ return Math.sin(arg_r) * hr;
+}
diff --git a/lib/common/clens_cmplx.js b/lib/common/clens_cmplx.js
new file mode 100644
index 0000000..d149d8c
--- /dev/null
+++ b/lib/common/clens_cmplx.js
@@ -0,0 +1,32 @@
+import sinh from './sinh';
+import cosh from './cosh';
+
+export default function(pp, arg_r, arg_i) {
+ var sin_arg_r = Math.sin(arg_r);
+ var cos_arg_r = Math.cos(arg_r);
+ var sinh_arg_i = sinh(arg_i);
+ var cosh_arg_i = cosh(arg_i);
+ var r = 2 * cos_arg_r * cosh_arg_i;
+ var i = -2 * sin_arg_r * sinh_arg_i;
+ var j = pp.length - 1;
+ var hr = pp[j];
+ var hi1 = 0;
+ var hr1 = 0;
+ var hi = 0;
+ var hr2;
+ var hi2;
+
+ while (--j >= 0) {
+ hr2 = hr1;
+ hi2 = hi1;
+ hr1 = hr;
+ hi1 = hi;
+ hr = -hr2 + r * hr1 - i * hi1 + pp[j];
+ hi = -hi2 + i * hr1 + r * hi1;
+ }
+
+ r = sin_arg_r * cosh_arg_i;
+ i = cos_arg_r * sinh_arg_i;
+
+ return [r * hr - i * hi, r * hi + i * hr];
+}
diff --git a/lib/common/cosh.js b/lib/common/cosh.js
index fcb1363..8b5174e 100644
--- a/lib/common/cosh.js
+++ b/lib/common/cosh.js
@@ -1,5 +1,5 @@
-module.exports = function(x) {
+export default function(x) {
var r = Math.exp(x);
r = (r + 1 / r) / 2;
return r;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/e0fn.js b/lib/common/e0fn.js
index e880467..33501ac 100644
--- a/lib/common/e0fn.js
+++ b/lib/common/e0fn.js
@@ -1,3 +1,3 @@
-module.exports = function(x) {
+export default function(x) {
return (1 - 0.25 * x * (1 + x / 16 * (3 + 1.25 * x)));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/e1fn.js b/lib/common/e1fn.js
index 32b46f5..c4c8500 100644
--- a/lib/common/e1fn.js
+++ b/lib/common/e1fn.js
@@ -1,3 +1,3 @@
-module.exports = function(x) {
+export default function(x) {
return (0.375 * x * (1 + 0.25 * x * (1 + 0.46875 * x)));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/e2fn.js b/lib/common/e2fn.js
index 756135f..55539a7 100644
--- a/lib/common/e2fn.js
+++ b/lib/common/e2fn.js
@@ -1,3 +1,3 @@
-module.exports = function(x) {
+export default function(x) {
return (0.05859375 * x * x * (1 + 0.75 * x));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/e3fn.js b/lib/common/e3fn.js
index d7ffc88..6010428 100644
--- a/lib/common/e3fn.js
+++ b/lib/common/e3fn.js
@@ -1,3 +1,3 @@
-module.exports = function(x) {
+export default function(x) {
return (x * x * x * (35 / 3072));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/fL.js b/lib/common/fL.js
index f834d9a..8440cd5 100644
--- a/lib/common/fL.js
+++ b/lib/common/fL.js
@@ -1,5 +1,5 @@
-var HALF_PI = Math.PI/2;
+import {HALF_PI} from '../constants/values';
-module.exports = function(x, L) {
+export default function(x, L) {
return 2 * Math.atan(x * Math.exp(L)) - HALF_PI;
-};
\ No newline at end of file
+}
diff --git a/lib/common/gN.js b/lib/common/gN.js
index 85dec88..29bd5f0 100644
--- a/lib/common/gN.js
+++ b/lib/common/gN.js
@@ -1,4 +1,4 @@
-module.exports = function(a, e, sinphi) {
+export default function(a, e, sinphi) {
var temp = e * sinphi;
return a / Math.sqrt(1 - temp * temp);
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/gatg.js b/lib/common/gatg.js
new file mode 100644
index 0000000..597f196
--- /dev/null
+++ b/lib/common/gatg.js
@@ -0,0 +1,15 @@
+export default function(pp, B) {
+ var cos_2B = 2 * Math.cos(2 * B);
+ var i = pp.length - 1;
+ var h1 = pp[i];
+ var h2 = 0;
+ var h;
+
+ while (--i >= 0) {
+ h = -h2 + cos_2B * h1 + pp[i];
+ h2 = h1;
+ h1 = h;
+ }
+
+ return (B + h * Math.sin(2 * B));
+}
diff --git a/lib/common/hypot.js b/lib/common/hypot.js
new file mode 100644
index 0000000..7b210a7
--- /dev/null
+++ b/lib/common/hypot.js
@@ -0,0 +1,8 @@
+export default function(x, y) {
+ x = Math.abs(x);
+ y = Math.abs(y);
+ var a = Math.max(x, y);
+ var b = Math.min(x, y) / (a ? a : 1);
+
+ return a * Math.sqrt(1 + Math.pow(b, 2));
+}
diff --git a/lib/common/imlfn.js b/lib/common/imlfn.js
index a8e2a08..70859dc 100644
--- a/lib/common/imlfn.js
+++ b/lib/common/imlfn.js
@@ -1,4 +1,4 @@
-module.exports = function(ml, e0, e1, e2, e3) {
+export default function(ml, e0, e1, e2, e3) {
var phi;
var dphi;
@@ -13,4 +13,4 @@ module.exports = function(ml, e0, e1, e2, e3) {
//..reportError("IMLFN-CONV:Latitude failed to converge after 15 iterations");
return NaN;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/inverseNadCvt.js b/lib/common/inverseNadCvt.js
index d90e0f2..ad9cb07 100644
--- a/lib/common/inverseNadCvt.js
+++ b/lib/common/inverseNadCvt.js
@@ -1,6 +1,7 @@
-var nad_intr = require('./nad_intr');
-var adjust_lon = require('./adjust_lon');
-module.exports = function(t, val, tb, ct) {
+import nad_intr from './nad_intr';
+import adjust_lon from './adjust_lon';
+
+export default function(t, val, tb, ct) {
if (isNaN(t.x)) {
return val;
}
@@ -27,4 +28,4 @@ module.exports = function(t, val, tb, ct) {
val.x = adjust_lon(t.x + ct.ll[0]);
val.y = t.y + ct.ll[1];
return val;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/invlatiso.js b/lib/common/invlatiso.js
index e0e2ce5..1417f38 100644
--- a/lib/common/invlatiso.js
+++ b/lib/common/invlatiso.js
@@ -1,6 +1,6 @@
-var fL = require('./fL');
+import fL from './fL';
-module.exports = function(eccent, ts) {
+export default function(eccent, ts) {
var phi = fL(1, ts);
var Iphi = 0;
var con = 0;
@@ -10,4 +10,4 @@ module.exports = function(eccent, ts) {
phi = fL(Math.exp(eccent * Math.log((1 + con) / (1 - con)) / 2), ts);
} while (Math.abs(phi - Iphi) > 1.0e-12);
return phi;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/iqsfnz.js b/lib/common/iqsfnz.js
index 6c8c952..6231355 100644
--- a/lib/common/iqsfnz.js
+++ b/lib/common/iqsfnz.js
@@ -1,6 +1,6 @@
-var HALF_PI = Math.PI/2;
+import {HALF_PI} from '../constants/values';
-module.exports = function(eccent, q) {
+export default function(eccent, q) {
var temp = 1 - (1 - eccent * eccent) / (2 * eccent) * Math.log((1 - eccent) / (1 + eccent));
if (Math.abs(Math.abs(q) - temp) < 1.0E-6) {
if (q < 0) {
@@ -29,4 +29,4 @@ module.exports = function(eccent, q) {
//console.log("IQSFN-CONV:Latitude failed to converge after 30 iterations");
return NaN;
-};
\ No newline at end of file
+}
diff --git a/lib/common/latiso.js b/lib/common/latiso.js
index f60d06c..61e0b09 100644
--- a/lib/common/latiso.js
+++ b/lib/common/latiso.js
@@ -1,6 +1,6 @@
-var HALF_PI = Math.PI/2;
+import {HALF_PI} from '../constants/values';
-module.exports = function(eccent, phi, sinphi) {
+export default function(eccent, phi, sinphi) {
if (Math.abs(phi) > HALF_PI) {
return Number.NaN;
}
@@ -13,4 +13,4 @@ module.exports = function(eccent, phi, sinphi) {
var con = eccent * sinphi;
return Math.log(Math.tan((HALF_PI + phi) / 2)) + eccent * Math.log((1 - con) / (1 + con)) / 2;
-};
\ No newline at end of file
+}
diff --git a/lib/common/log1py.js b/lib/common/log1py.js
new file mode 100644
index 0000000..ad63730
--- /dev/null
+++ b/lib/common/log1py.js
@@ -0,0 +1,6 @@
+export default function(x) {
+ var y = 1 + x;
+ var z = y - 1;
+
+ return z === 0 ? x : x * Math.log(y) / z;
+}
diff --git a/lib/common/mlfn.js b/lib/common/mlfn.js
index f84d02e..53dc3d2 100644
--- a/lib/common/mlfn.js
+++ b/lib/common/mlfn.js
@@ -1,3 +1,3 @@
-module.exports = function(e0, e1, e2, e3, phi) {
+export default function(e0, e1, e2, e3, phi) {
return (e0 * phi - e1 * Math.sin(2 * phi) + e2 * Math.sin(4 * phi) - e3 * Math.sin(6 * phi));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/msfnz.js b/lib/common/msfnz.js
index 18ce51a..433f347 100644
--- a/lib/common/msfnz.js
+++ b/lib/common/msfnz.js
@@ -1,4 +1,4 @@
-module.exports = function(eccent, sinphi, cosphi) {
+export default function(eccent, sinphi, cosphi) {
var con = eccent * sinphi;
return cosphi / (Math.sqrt(1 - con * con));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/nadInterBreakout.js b/lib/common/nadInterBreakout.js
index f37a967..1fdb9f8 100644
--- a/lib/common/nadInterBreakout.js
+++ b/lib/common/nadInterBreakout.js
@@ -1,4 +1,4 @@
-module.exports = function(indx, frct, letter, number, ct) {
+export default function(indx, frct, letter, number, ct) {
var inx;
if (indx[letter] < 0) {
if (!(indx[letter] === -1 && frct[letter] > 0.99999999999)) {
@@ -23,4 +23,4 @@ module.exports = function(indx, frct, letter, number, ct) {
}
}
return [indx, frct];
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/nad_cvt.js b/lib/common/nad_cvt.js
index 158ccff..e70a0fb 100644
--- a/lib/common/nad_cvt.js
+++ b/lib/common/nad_cvt.js
@@ -1,8 +1,8 @@
-var adjust_lon = require('./adjust_lon');
-var nad_intr = require('./nad_intr');
-var inverseNadCvt = require('./inverseNadCvt');
+import adjust_lon from './adjust_lon';
+import nad_intr from './nad_intr';
+import inverseNadCvt from './inverseNadCvt';
-module.exports = function(pin, inverse, ct) {
+export default function(pin, inverse, ct) {
var val = {
"x": Number.NaN,
"y": Number.NaN
@@ -28,4 +28,4 @@ module.exports = function(pin, inverse, ct) {
}
}
return val;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/nad_intr.js b/lib/common/nad_intr.js
index f10bdcc..861b5ec 100644
--- a/lib/common/nad_intr.js
+++ b/lib/common/nad_intr.js
@@ -1,6 +1,6 @@
-var nadInterBreakout = require("./nadInterBreakout");
+import nadInterBreakout from "./nadInterBreakout";
-module.exports = function(pin, ct) {
+export default function(pin, ct) {
// force computation by decreasing by 1e-7 to be as closed as possible
// from computation under C:C++ by leveraging rounding problems ...
var t = {
@@ -64,4 +64,4 @@ module.exports = function(pin, ct) {
val.x = (m00 * f00.x + m10 * f10.x + m01 * f01.x + m11 * f11.x);
val.y = (m00 * f00.y + m10 * f10.y + m01 * f01.y + m11 * f11.y);
return val;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/phi2z.js b/lib/common/phi2z.js
index a29e8a3..3c70422 100644
--- a/lib/common/phi2z.js
+++ b/lib/common/phi2z.js
@@ -1,5 +1,6 @@
-var HALF_PI = Math.PI/2;
-module.exports = function(eccent, ts) {
+import {HALF_PI} from '../constants/values';
+
+export default function(eccent, ts) {
var eccnth = 0.5 * eccent;
var con, dphi;
var phi = HALF_PI - 2 * Math.atan(ts);
@@ -13,4 +14,4 @@ module.exports = function(eccent, ts) {
}
//console.log("phi2z has NoConvergence");
return -9999;
-};
\ No newline at end of file
+}
diff --git a/lib/common/pj_enfn.js b/lib/common/pj_enfn.js
index d71c565..5d9be38 100644
--- a/lib/common/pj_enfn.js
+++ b/lib/common/pj_enfn.js
@@ -11,7 +11,7 @@ var C66 = 0.36458333333333333333;
var C68 = 0.00569661458333333333;
var C88 = 0.3076171875;
-module.exports = function(es) {
+export default function(es) {
var en = [];
en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
@@ -21,4 +21,4 @@ module.exports = function(es) {
en[3] = t * (C66 - es * C68);
en[4] = t * es * C88;
return en;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/pj_inv_mlfn.js b/lib/common/pj_inv_mlfn.js
index 64aaa31..7f91931 100644
--- a/lib/common/pj_inv_mlfn.js
+++ b/lib/common/pj_inv_mlfn.js
@@ -1,7 +1,9 @@
-var pj_mlfn = require("./pj_mlfn");
-var EPSLN = 1.0e-10;
+import pj_mlfn from "./pj_mlfn";
+import {EPSLN} from '../constants/values';
+
var MAX_ITER = 20;
-module.exports = function(arg, es, en) {
+
+export default function(arg, es, en) {
var k = 1 / (1 - es);
var phi = arg;
for (var i = MAX_ITER; i; --i) { /* rarely goes over 2 iterations */
@@ -17,4 +19,4 @@ module.exports = function(arg, es, en) {
}
//..reportError("cass:pj_inv_mlfn: Convergence error");
return phi;
-};
\ No newline at end of file
+}
diff --git a/lib/common/pj_mlfn.js b/lib/common/pj_mlfn.js
index 01156b9..6e898c3 100644
--- a/lib/common/pj_mlfn.js
+++ b/lib/common/pj_mlfn.js
@@ -1,5 +1,5 @@
-module.exports = function(phi, sphi, cphi, en) {
+export default function(phi, sphi, cphi, en) {
cphi *= sphi;
sphi *= sphi;
return (en[0] * phi - cphi * (en[1] + sphi * (en[2] + sphi * (en[3] + sphi * en[4]))));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/qsfnz.js b/lib/common/qsfnz.js
index bd6e515..6afb50a 100644
--- a/lib/common/qsfnz.js
+++ b/lib/common/qsfnz.js
@@ -1,4 +1,4 @@
-module.exports = function(eccent, sinphi) {
+export default function(eccent, sinphi) {
var con;
if (eccent > 1.0e-7) {
con = eccent * sinphi;
@@ -7,4 +7,4 @@ module.exports = function(eccent, sinphi) {
else {
return (2 * sinphi);
}
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/sign.js b/lib/common/sign.js
index e31dc08..c97da62 100644
--- a/lib/common/sign.js
+++ b/lib/common/sign.js
@@ -1,3 +1,3 @@
-module.exports = function(x) {
+export default function(x) {
return x<0 ? -1 : 1;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/sinh.js b/lib/common/sinh.js
index fa57607..db3fe4d 100644
--- a/lib/common/sinh.js
+++ b/lib/common/sinh.js
@@ -1,5 +1,5 @@
-module.exports = function(x) {
+export default function(x) {
var r = Math.exp(x);
r = (r - 1 / r) / 2;
return r;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/srat.js b/lib/common/srat.js
index c7db8e0..171b627 100644
--- a/lib/common/srat.js
+++ b/lib/common/srat.js
@@ -1,3 +1,3 @@
-module.exports = function(esinp, exp) {
+export default function(esinp, exp) {
return (Math.pow((1 - esinp) / (1 + esinp), exp));
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/tanh.js b/lib/common/tanh.js
index bc05c42..782414a 100644
--- a/lib/common/tanh.js
+++ b/lib/common/tanh.js
@@ -1,5 +1,5 @@
-module.exports = function(x) {
+export default function(x) {
var r = Math.exp(x);
r = (r - 1 / r) / (r + 1 / r);
return r;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/toPoint.js b/lib/common/toPoint.js
index d76dec8..7226892 100644
--- a/lib/common/toPoint.js
+++ b/lib/common/toPoint.js
@@ -1,4 +1,4 @@
-module.exports = function (array){
+export default function (array){
var out = {
x: array[0],
y: array[1]
@@ -10,4 +10,4 @@ module.exports = function (array){
out.m = array[3];
}
return out;
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/lib/common/tsfnz.js b/lib/common/tsfnz.js
index ad7c66a..6702d85 100644
--- a/lib/common/tsfnz.js
+++ b/lib/common/tsfnz.js
@@ -1,8 +1,8 @@
-var HALF_PI = Math.PI/2;
+import {HALF_PI} from '../constants/values';
-module.exports = function(eccent, phi, sinphi) {
+export default function(eccent, phi, sinphi) {
var con = eccent * sinphi;
var com = 0.5 * eccent;
con = Math.pow(((1 - con) / (1 + con)), com);
return (Math.tan(0.5 * (HALF_PI - phi)) / con);
-};
\ No newline at end of file
+}
diff --git a/lib/constants/Datum.js b/lib/constants/Datum.js
index a112b32..00d565f 100644
--- a/lib/constants/Datum.js
+++ b/lib/constants/Datum.js
@@ -1,80 +1,97 @@
+var exports = {};
+export {exports as default};
exports.wgs84 = {
towgs84: "0,0,0",
ellipse: "WGS84",
datumName: "WGS84"
};
+
exports.ch1903 = {
towgs84: "674.374,15.056,405.346",
ellipse: "bessel",
datumName: "swiss"
};
+
exports.ggrs87 = {
towgs84: "-199.87,74.79,246.62",
ellipse: "GRS80",
datumName: "Greek_Geodetic_Reference_System_1987"
};
+
exports.nad83 = {
towgs84: "0,0,0",
ellipse: "GRS80",
datumName: "North_American_Datum_1983"
};
+
exports.nad27 = {
nadgrids: "@conus, at alaska, at ntv2_0.gsb, at ntv1_can.dat",
ellipse: "clrk66",
datumName: "North_American_Datum_1927"
};
+
exports.potsdam = {
towgs84: "606.0,23.0,413.0",
ellipse: "bessel",
datumName: "Potsdam Rauenberg 1950 DHDN"
};
+
exports.carthage = {
towgs84: "-263.0,6.0,431.0",
ellipse: "clark80",
datumName: "Carthage 1934 Tunisia"
};
+
exports.hermannskogel = {
towgs84: "653.0,-212.0,449.0",
ellipse: "bessel",
datumName: "Hermannskogel"
};
+
exports.ire65 = {
towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15",
ellipse: "mod_airy",
datumName: "Ireland 1965"
};
+
exports.rassadiran = {
towgs84: "-133.63,-157.5,-158.62",
ellipse: "intl",
datumName: "Rassadiran"
};
+
exports.nzgd49 = {
towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993",
ellipse: "intl",
datumName: "New Zealand Geodetic Datum 1949"
};
+
exports.osgb36 = {
towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",
ellipse: "airy",
datumName: "Airy 1830"
};
+
exports.s_jtsk = {
towgs84: "589,76,480",
ellipse: 'bessel',
datumName: 'S-JTSK (Ferro)'
};
+
exports.beduaram = {
towgs84: '-106,-87,188',
ellipse: 'clrk80',
datumName: 'Beduaram'
};
+
exports.gunung_segara = {
towgs84: '-403,684,41',
ellipse: 'bessel',
datumName: 'Gunung Segara Jakarta'
};
+
exports.rnb72 = {
towgs84: "106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1",
ellipse: "intl",
datumName: "Reseau National Belge 1972"
-};
\ No newline at end of file
+};
diff --git a/lib/constants/Ellipsoid.js b/lib/constants/Ellipsoid.js
index 51afef8..3dde298 100644
--- a/lib/constants/Ellipsoid.js
+++ b/lib/constants/Ellipsoid.js
@@ -1,215 +1,259 @@
+var exports = {};
+export {exports as default};
exports.MERIT = {
a: 6378137.0,
rf: 298.257,
ellipseName: "MERIT 1983"
};
+
exports.SGS85 = {
a: 6378136.0,
rf: 298.257,
ellipseName: "Soviet Geodetic System 85"
};
+
exports.GRS80 = {
a: 6378137.0,
rf: 298.257222101,
ellipseName: "GRS 1980(IUGG, 1980)"
};
+
exports.IAU76 = {
a: 6378140.0,
rf: 298.257,
ellipseName: "IAU 1976"
};
+
exports.airy = {
a: 6377563.396,
b: 6356256.910,
ellipseName: "Airy 1830"
};
+
exports.APL4 = {
a: 6378137,
rf: 298.25,
ellipseName: "Appl. Physics. 1965"
};
+
exports.NWL9D = {
a: 6378145.0,
rf: 298.25,
ellipseName: "Naval Weapons Lab., 1965"
};
+
exports.mod_airy = {
a: 6377340.189,
b: 6356034.446,
ellipseName: "Modified Airy"
};
+
exports.andrae = {
a: 6377104.43,
rf: 300.0,
ellipseName: "Andrae 1876 (Den., Iclnd.)"
};
+
exports.aust_SA = {
a: 6378160.0,
rf: 298.25,
ellipseName: "Australian Natl & S. Amer. 1969"
};
+
exports.GRS67 = {
a: 6378160.0,
rf: 298.2471674270,
ellipseName: "GRS 67(IUGG 1967)"
};
+
exports.bessel = {
a: 6377397.155,
rf: 299.1528128,
ellipseName: "Bessel 1841"
};
+
exports.bess_nam = {
a: 6377483.865,
rf: 299.1528128,
ellipseName: "Bessel 1841 (Namibia)"
};
+
exports.clrk66 = {
a: 6378206.4,
b: 6356583.8,
ellipseName: "Clarke 1866"
};
+
exports.clrk80 = {
a: 6378249.145,
rf: 293.4663,
ellipseName: "Clarke 1880 mod."
};
+
exports.clrk58 = {
a: 6378293.645208759,
rf: 294.2606763692654,
ellipseName: "Clarke 1858"
};
+
exports.CPM = {
a: 6375738.7,
rf: 334.29,
ellipseName: "Comm. des Poids et Mesures 1799"
};
+
exports.delmbr = {
a: 6376428.0,
rf: 311.5,
ellipseName: "Delambre 1810 (Belgium)"
};
+
exports.engelis = {
a: 6378136.05,
rf: 298.2566,
ellipseName: "Engelis 1985"
};
+
exports.evrst30 = {
a: 6377276.345,
rf: 300.8017,
ellipseName: "Everest 1830"
};
+
exports.evrst48 = {
a: 6377304.063,
rf: 300.8017,
ellipseName: "Everest 1948"
};
+
exports.evrst56 = {
a: 6377301.243,
rf: 300.8017,
ellipseName: "Everest 1956"
};
+
exports.evrst69 = {
a: 6377295.664,
rf: 300.8017,
ellipseName: "Everest 1969"
};
+
exports.evrstSS = {
a: 6377298.556,
rf: 300.8017,
ellipseName: "Everest (Sabah & Sarawak)"
};
+
exports.fschr60 = {
a: 6378166.0,
rf: 298.3,
ellipseName: "Fischer (Mercury Datum) 1960"
};
+
exports.fschr60m = {
a: 6378155.0,
rf: 298.3,
ellipseName: "Fischer 1960"
};
+
exports.fschr68 = {
a: 6378150.0,
rf: 298.3,
ellipseName: "Fischer 1968"
};
+
exports.helmert = {
a: 6378200.0,
rf: 298.3,
ellipseName: "Helmert 1906"
};
+
exports.hough = {
a: 6378270.0,
rf: 297.0,
ellipseName: "Hough"
};
+
exports.intl = {
a: 6378388.0,
rf: 297.0,
ellipseName: "International 1909 (Hayford)"
};
+
exports.kaula = {
a: 6378163.0,
rf: 298.24,
ellipseName: "Kaula 1961"
};
+
exports.lerch = {
a: 6378139.0,
rf: 298.257,
ellipseName: "Lerch 1979"
};
+
exports.mprts = {
a: 6397300.0,
rf: 191.0,
ellipseName: "Maupertius 1738"
};
+
exports.new_intl = {
a: 6378157.5,
b: 6356772.2,
ellipseName: "New International 1967"
};
+
exports.plessis = {
a: 6376523.0,
rf: 6355863.0,
ellipseName: "Plessis 1817 (France)"
};
+
exports.krass = {
a: 6378245.0,
rf: 298.3,
ellipseName: "Krassovsky, 1942"
};
+
exports.SEasia = {
a: 6378155.0,
b: 6356773.3205,
ellipseName: "Southeast Asia"
};
+
exports.walbeck = {
a: 6376896.0,
b: 6355834.8467,
ellipseName: "Walbeck"
};
+
exports.WGS60 = {
a: 6378165.0,
rf: 298.3,
ellipseName: "WGS 60"
};
+
exports.WGS66 = {
a: 6378145.0,
rf: 298.25,
ellipseName: "WGS 66"
};
+
exports.WGS7 = {
a: 6378135.0,
rf: 298.26,
ellipseName: "WGS 72"
};
+
exports.WGS84 = {
a: 6378137.0,
rf: 298.257223563,
ellipseName: "WGS 84"
};
+
exports.sphere = {
a: 6370997.0,
b: 6370997.0,
ellipseName: "Normal Sphere (r=6370997)"
-};
\ No newline at end of file
+};
diff --git a/lib/constants/PrimeMeridian.js b/lib/constants/PrimeMeridian.js
index ae6556f..8e81d50 100644
--- a/lib/constants/PrimeMeridian.js
+++ b/lib/constants/PrimeMeridian.js
@@ -1,3 +1,6 @@
+var exports = {};
+export {exports as default};
+
exports.greenwich = 0.0; //"0dE",
exports.lisbon = -9.131906111111; //"9d07'54.862\"W",
exports.paris = 2.337229166667; //"2d20'14.025\"E",
@@ -10,4 +13,4 @@ exports.ferro = -17.666666666667; //"17d40'W",
exports.brussels = 4.367975; //"4d22'4.71\"E",
exports.stockholm = 18.058277777778; //"18d3'29.8\"E",
exports.athens = 23.7163375; //"23d42'58.815\"E",
-exports.oslo = 10.722916666667; //"10d43'22.5\"E"
\ No newline at end of file
+exports.oslo = 10.722916666667; //"10d43'22.5\"E"
diff --git a/lib/constants/grids.js b/lib/constants/grids.js
deleted file mode 100644
index 5394bf9..0000000
--- a/lib/constants/grids.js
+++ /dev/null
@@ -1,23 +0,0 @@
-// Based on . CTABLE structure :
- // FIXME: better to have array instead of object holding longitudes, latitudes members
- // In the former case, one has to document index 0 is longitude and
- // 1 is latitude ...
- // In the later case, grid object gets bigger !!!!
- // Solution 1 is chosen based on pj_gridinfo.c
-exports['null'] = { // name of grid's file
- "ll": [-3.14159265, - 1.57079633], // lower-left coordinates in radians (longitude, latitude):
- "del": [3.14159265, 1.57079633], // cell's size in radians (longitude, latitude):
- "lim": [3, 3], // number of nodes in longitude, latitude (including edges):
- "count": 9, // total number of nodes
- "cvs": [ // shifts : in ntv2 reverse order : lon, lat in radians ...
- [0.0, 0.0],
- [0.0, 0.0],
- [0.0, 0.0], // for (lon= 0; lon<lim[0]; lon++) {
- [0.0, 0.0],
- [0.0, 0.0],
- [0.0, 0.0], // for (lat= 0; lat<lim[1]; lat++) { p= cvs[lat*lim[0]+lon]; }
- [0.0, 0.0],
- [0.0, 0.0],
- [0.0, 0.0] // }
- ]
-};
diff --git a/lib/constants/units.js b/lib/constants/units.js
index c5188c2..39ed6f8 100644
--- a/lib/constants/units.js
+++ b/lib/constants/units.js
@@ -1,2 +1,4 @@
-exports.ft = {to_meter: 0.3048};
-exports['us-ft'] = {to_meter: 1200 / 3937};
+export default {
+ ft: {to_meter: 0.3048},
+ 'us-ft': {to_meter: 1200 / 3937}
+};
diff --git a/lib/constants/values.js b/lib/constants/values.js
new file mode 100644
index 0000000..6cde6fe
--- /dev/null
+++ b/lib/constants/values.js
@@ -0,0 +1,22 @@
+export var PJD_3PARAM = 1;
+export var PJD_7PARAM = 2;
+export var PJD_WGS84 = 4; // WGS84 or equivalent
+export var PJD_NODATUM = 5; // WGS84 or equivalent
+export var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
+export var HALF_PI = Math.PI/2;
+// ellipoid pj_set_ell.c
+export var SIXTH = 0.1666666666666666667;
+/* 1/6 */
+export var RA4 = 0.04722222222222222222;
+/* 17/360 */
+export var RA6 = 0.02215608465608465608;
+export var EPSLN = (typeof Number.EPSILON === 'undefined') ? 1.0e-10 : Number.EPSILON;
+export var D2R = 0.01745329251994329577;
+export var R2D = 57.29577951308232088;
+export var FORTPI = Math.PI/4;
+export var TWO_PI = Math.PI * 2;
+// SPI is slightly greater than Math.PI, so values that exceed the -180..180
+// degree range by a tiny amount don't get wrapped. This prevents points that
+// have drifted from their original location along the 180th meridian (due to
+// floating point error) from changing their sign.
+export var SPI = 3.14159265359;
diff --git a/lib/core.js b/lib/core.js
index 720d63a..0098351 100644
--- a/lib/core.js
+++ b/lib/core.js
@@ -1,5 +1,5 @@
-var proj = require('./Proj');
-var transform = require('./transform');
+import proj from './Proj';
+import transform from './transform';
var wgs84 = proj('WGS84');
function transformer(from, to, coords) {
@@ -61,4 +61,4 @@ function proj4(fromProj, toProj, coord) {
return obj;
}
}
-module.exports = proj4;
\ No newline at end of file
+export default proj4;
\ No newline at end of file
diff --git a/lib/datum.js b/lib/datum.js
index a7391c5..810f766 100644
--- a/lib/datum.js
+++ b/lib/datum.js
@@ -1,14 +1,12 @@
-var PJD_3PARAM = 1;
-var PJD_7PARAM = 2;
-var PJD_WGS84 = 4; // WGS84 or equivalent
-var PJD_NODATUM = 5; // WGS84 or equivalent
-var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
+import {PJD_3PARAM, PJD_7PARAM, PJD_WGS84, PJD_NODATUM, SEC_TO_RAD} from './constants/values';
function datum(datumCode, datum_params, a, b, es, ep2) {
var out = {};
- out.datum_type = PJD_WGS84; //default setting
- if (datumCode && datumCode === 'none') {
+
+ if (datumCode === undefined || datumCode === 'none') {
out.datum_type = PJD_NODATUM;
+ } else {
+ out.datum_type = PJD_WGS84;
}
if (datum_params) {
@@ -27,7 +25,6 @@ function datum(datumCode, datum_params, a, b, es, ep2) {
}
}
-
out.a = a; //datum object also uses these values
out.b = b;
out.es = es;
@@ -35,4 +32,4 @@ function datum(datumCode, datum_params, a, b, es, ep2) {
return out;
}
-module.exports = datum;
+export default datum;
diff --git a/lib/datumUtils.js b/lib/datumUtils.js
index d5a257e..b413273 100644
--- a/lib/datumUtils.js
+++ b/lib/datumUtils.js
@@ -1,23 +1,20 @@
'use strict';
-var PJD_3PARAM = 1;
-var PJD_7PARAM = 2;
-var HALF_PI = Math.PI/2;
-
-exports.compareDatums = function(source, dest) {
+import {PJD_3PARAM, PJD_7PARAM, HALF_PI} from './constants/values';
+export function compareDatums(source, dest) {
if (source.datum_type !== dest.datum_type) {
return false; // false, datums are not equal
- } else if (source.a !== dest.a || Math.abs(this.es - dest.es) > 0.000000000050) {
- // the tolerence for es is to ensure that GRS80 and WGS84
+ } else if (source.a !== dest.a || Math.abs(source.es - dest.es) > 0.000000000050) {
+ // the tolerance for es is to ensure that GRS80 and WGS84
// are considered identical
return false;
} else if (source.datum_type === PJD_3PARAM) {
- return (this.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2]);
+ return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2]);
} else if (source.datum_type === PJD_7PARAM) {
return (source.datum_params[0] === dest.datum_params[0] && source.datum_params[1] === dest.datum_params[1] && source.datum_params[2] === dest.datum_params[2] && source.datum_params[3] === dest.datum_params[3] && source.datum_params[4] === dest.datum_params[4] && source.datum_params[5] === dest.datum_params[5] && source.datum_params[6] === dest.datum_params[6]);
} else {
return true; // datums are equal
}
-}; // cs_compare_datums()
+} // cs_compare_datums()
/*
* The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
@@ -32,7 +29,7 @@ exports.compareDatums = function(source, dest) {
* Z : Calculated Geocentric Z coordinate, in meters (output)
*
*/
-exports.geodeticToGeocentric = function(p, es, a) {
+export function geodeticToGeocentric(p, es, a) {
var Longitude = p.x;
var Latitude = p.y;
var Height = p.z ? p.z : 0; //Z value not always supplied
@@ -69,10 +66,9 @@ exports.geodeticToGeocentric = function(p, es, a) {
y: (Rn + Height) * Cos_Lat * Math.sin(Longitude),
z: ((Rn * (1 - es)) + Height) * Sin_Lat
};
-}; // cs_geodetic_to_geocentric()
-
+} // cs_geodetic_to_geocentric()
-exports.geocentricToGeodetic = function(p, es, a, b) {
+export function geocentricToGeodetic(p, es, a, b) {
/* local defintions and variables */
/* end-criterium of loop, accuracy of sin(Latitude) */
var genau = 1e-12;
@@ -168,8 +164,7 @@ exports.geocentricToGeodetic = function(p, es, a, b) {
y: Latitude,
z: Height
};
-}; // cs_geocentric_to_geodetic()
-
+} // cs_geocentric_to_geodetic()
/****************************************************************/
// pj_geocentic_to_wgs84( p )
@@ -181,7 +176,7 @@ exports.geocentricToGeodetic = function(p, es, a, b) {
Other point classes may be used as long as they have
x and y properties, which will get modified in the transform method.
*/
-exports.geocentricToWgs84 = function(p, datum_type, datum_params) {
+export function geocentricToWgs84(p, datum_type, datum_params) {
if (datum_type === PJD_3PARAM) {
// if( x[io] === HUGE_VAL )
@@ -207,13 +202,13 @@ exports.geocentricToWgs84 = function(p, datum_type, datum_params) {
z: M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF
};
}
-}; // cs_geocentric_to_wgs84
+} // cs_geocentric_to_wgs84
/****************************************************************/
// pj_geocentic_from_wgs84()
// coordinate system definition,
// point to transform in geocentric coordinates (x,y,z)
-exports.geocentricFromWgs84 = function(p, datum_type, datum_params) {
+export function geocentricFromWgs84(p, datum_type, datum_params) {
if (datum_type === PJD_3PARAM) {
//if( x[io] === HUGE_VAL )
@@ -244,4 +239,4 @@ exports.geocentricFromWgs84 = function(p, datum_type, datum_params) {
z: Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp
};
} //cs_geocentric_from_wgs84()
-};
+}
diff --git a/lib/datum_transform.js b/lib/datum_transform.js
index b5a8b3f..63305e0 100644
--- a/lib/datum_transform.js
+++ b/lib/datum_transform.js
@@ -1,13 +1,13 @@
-var PJD_3PARAM = 1;
-var PJD_7PARAM = 2;
-var PJD_NODATUM = 5; // WGS84 or equivalent
-var datum = require('./datumUtils');
+import {PJD_3PARAM, PJD_7PARAM, PJD_NODATUM} from './constants/values';
+
+import {geodeticToGeocentric, geocentricToGeodetic, geocentricToWgs84, geocentricFromWgs84, compareDatums} from './datumUtils';
function checkParams(type) {
return (type === PJD_3PARAM || type === PJD_7PARAM);
}
-module.exports = function(source, dest, point) {
+
+export default function(source, dest, point) {
// Short cut if the datums are identical.
- if (datum.compareDatums(source, dest)) {
+ if (compareDatums(source, dest)) {
return point; // in this case, zero is sucess,
// whereas cs_compare_datums returns 1 to indicate TRUE
// confusing, should fix this
@@ -26,14 +26,14 @@ module.exports = function(source, dest, point) {
}
// Convert to geocentric coordinates.
- point = datum.geodeticToGeocentric(point, source.es, source.a);
+ point = geodeticToGeocentric(point, source.es, source.a);
// Convert between datums
if (checkParams(source.datum_type)) {
- point = datum.geocentricToWgs84(point, source.datum_type, source.datum_params);
+ point = geocentricToWgs84(point, source.datum_type, source.datum_params);
}
if (checkParams(dest.datum_type)) {
- point = datum.geocentricFromWgs84(point, dest.datum_type, dest.datum_params);
+ point = geocentricFromWgs84(point, dest.datum_type, dest.datum_params);
}
- return datum.geocentricToGeodetic(point, dest.es, dest.a, dest.b);
+ return geocentricToGeodetic(point, dest.es, dest.a, dest.b);
-};
+}
diff --git a/lib/defs.js b/lib/defs.js
index 66dbeb6..6655c80 100644
--- a/lib/defs.js
+++ b/lib/defs.js
@@ -1,6 +1,6 @@
-var globals = require('./global');
-var parseProj = require('./projString');
-var wkt = require('./wkt');
+import globals from './global';
+import parseProj from './projString';
+import wkt from 'wkt-parser';
function defs(name) {
/*global console*/
@@ -52,4 +52,4 @@ function defs(name) {
}
globals(defs);
-module.exports = defs;
+export default defs;
diff --git a/lib/deriveConstants.js b/lib/deriveConstants.js
index 38faac0..6459436 100644
--- a/lib/deriveConstants.js
+++ b/lib/deriveConstants.js
@@ -1,13 +1,8 @@
-// ellipoid pj_set_ell.c
-var SIXTH = 0.1666666666666666667;
-/* 1/6 */
-var RA4 = 0.04722222222222222222;
-/* 17/360 */
-var RA6 = 0.02215608465608465608;
-var EPSLN = 1.0e-10;
-var Ellipsoid = require('./constants/Ellipsoid');
+import {SIXTH, RA4, RA6, EPSLN} from './constants/values';
+import Ellipsoid from './constants/Ellipsoid';
+import match from './match';
-exports.eccentricity = function(a, b, rf, R_A) {
+export function eccentricity(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
@@ -25,12 +20,13 @@ exports.eccentricity = function(a, b, rf, R_A) {
e: e,
ep2: ep2
};
-};
-exports.sphere = function (a, b, rf, ellps, sphere) {
+}
+var wgs84 = match(Ellipsoid, 'WGS84');
+export function sphere(a, b, rf, ellps, sphere) {
if (!a) { // do we have an ellipsoid?
- var ellipse = Ellipsoid[ellps];
+ var ellipse = match(Ellipsoid, ellps);
if (!ellipse) {
- ellipse = Ellipsoid.WGS84;
+ ellipse = wgs84;
}
a = ellipse.a;
b = ellipse.b;
@@ -50,4 +46,4 @@ exports.sphere = function (a, b, rf, ellps, sphere) {
rf: rf,
sphere: sphere
};
-};
+}
diff --git a/lib/extend.js b/lib/extend.js
index a247691..bcd759f 100644
--- a/lib/extend.js
+++ b/lib/extend.js
@@ -1,4 +1,4 @@
-module.exports = function(destination, source) {
+export default function(destination, source) {
destination = destination || {};
var value, property;
if (!source) {
@@ -11,4 +11,4 @@ module.exports = function(destination, source) {
}
}
return destination;
-};
+}
diff --git a/lib/global.js b/lib/global.js
index 85f750e..476a131 100644
--- a/lib/global.js
+++ b/lib/global.js
@@ -1,4 +1,4 @@
-module.exports = function(defs) {
+export default function(defs) {
defs('EPSG:4326', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");
defs('EPSG:4269', "+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees");
defs('EPSG:3857', "+title=WGS 84 / Pseudo-Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs");
@@ -8,4 +8,4 @@ module.exports = function(defs) {
defs.GOOGLE = defs['EPSG:3857'];
defs['EPSG:900913'] = defs['EPSG:3857'];
defs['EPSG:102113'] = defs['EPSG:3857'];
-};
+}
diff --git a/lib/includedProjections.js b/lib/includedProjections.js
index 98fa1a9..d826b8a 100644
--- a/lib/includedProjections.js
+++ b/lib/includedProjections.js
@@ -1,29 +1,55 @@
+import tmerc from "./projections/tmerc";
+import utm from "./projections/utm";
+import sterea from "./projections/sterea";
+import stere from "./projections/stere";
+import somerc from "./projections/somerc";
+import omerc from "./projections/omerc";
+import lcc from "./projections/lcc";
+import krovak from "./projections/krovak";
+import cass from "./projections/cass";
+import laea from "./projections/laea";
+import aea from "./projections/aea";
+import gnom from "./projections/gnom";
+import cea from "./projections/cea";
+import eqc from "./projections/eqc";
+import poly from "./projections/poly";
+import nzmg from "./projections/nzmg";
+import mill from "./projections/mill";
+import sinu from "./projections/sinu";
+import moll from "./projections/moll";
+import eqdc from "./projections/eqdc";
+import vandg from "./projections/vandg";
+import aegd from "./projections/aeqd";
+import etmerc from './projections/etmerc';
+
var projs = [
- require('./projections/tmerc'),
- require('./projections/utm'),
- require('./projections/sterea'),
- require('./projections/stere'),
- require('./projections/somerc'),
- require('./projections/omerc'),
- require('./projections/lcc'),
- require('./projections/krovak'),
- require('./projections/cass'),
- require('./projections/laea'),
- require('./projections/aea'),
- require('./projections/gnom'),
- require('./projections/cea'),
- require('./projections/eqc'),
- require('./projections/poly'),
- require('./projections/nzmg'),
- require('./projections/mill'),
- require('./projections/sinu'),
- require('./projections/moll'),
- require('./projections/eqdc'),
- require('./projections/vandg'),
- require('./projections/aeqd')
+ tmerc,
+ utm,
+ sterea,
+ stere,
+ somerc,
+ omerc,
+ lcc,
+ krovak,
+ cass,
+ laea,
+ aea,
+ gnom,
+ cea,
+ eqc,
+ poly,
+ nzmg,
+ mill,
+ sinu,
+ moll,
+ eqdc,
+ vandg,
+ aegd,
+ etmerc
];
-module.exports = function(proj4){
+
+export default function(proj4){
projs.forEach(function(proj){
proj4.Proj.projections.add(proj);
});
-};
\ No newline at end of file
+}
diff --git a/lib/index.js b/lib/index.js
index a912bc0..217ec3b 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,12 +1,21 @@
-var proj4 = require('./core');
+import proj4 from './core';
+import Proj from "./Proj";
+import Point from "./Point";
+import common from "./common/toPoint";
+import defs from "./defs";
+import transform from "./transform";
+import mgrs from "mgrs";
+import version from "./version";
+import includedProjections from "../projs";
+
proj4.defaultDatum = 'WGS84'; //default datum
-proj4.Proj = require('./Proj');
+proj4.Proj = Proj;
proj4.WGS84 = new proj4.Proj('WGS84');
-proj4.Point = require('./Point');
-proj4.toPoint = require('./common/toPoint');
-proj4.defs = require('./defs');
-proj4.transform = require('./transform');
-proj4.mgrs = require('mgrs');
-proj4.version = require('./version');
-require('./includedProjections')(proj4);
-module.exports = proj4;
+proj4.Point = Point;
+proj4.toPoint = common;
+proj4.defs = defs;
+proj4.transform = transform;
+proj4.mgrs = mgrs;
+proj4.version = version;
+includedProjections(proj4);
+export default proj4;
diff --git a/lib/match.js b/lib/match.js
new file mode 100644
index 0000000..595e166
--- /dev/null
+++ b/lib/match.js
@@ -0,0 +1,17 @@
+var ignoredChar = /[\s_\-\/\(\)]/g;
+export default function match(obj, key) {
+ if (obj[key]) {
+ return obj[key];
+ }
+ var keys = Object.keys(obj);
+ var lkey = key.toLowerCase().replace(ignoredChar, '');
+ var i = -1;
+ var testkey, processedKey;
+ while (++i < keys.length) {
+ testkey = keys[i];
+ processedKey = testkey.toLowerCase().replace(ignoredChar, '');
+ if (processedKey === lkey) {
+ return obj[testkey];
+ }
+ }
+}
diff --git a/lib/parseCode.js b/lib/parseCode.js
index 87386d9..e8fc333 100644
--- a/lib/parseCode.js
+++ b/lib/parseCode.js
@@ -1,14 +1,13 @@
-var defs = require('./defs');
-var wkt = require('./wkt');
-var projStr = require('./projString');
+import defs from './defs';
+import wkt from 'wkt-parser';
+import projStr from './projString';
function testObj(code){
return typeof code === 'string';
}
function testDef(code){
return code in defs;
}
-var codeWords = ['GEOGCS','GEOCCS','PROJCS','LOCAL_CS'];
-
+ var codeWords = ['PROJECTEDCRS', 'PROJCRS', 'GEOGCS','GEOCCS','PROJCS','LOCAL_CS', 'GEODCRS', 'GEODETICCRS', 'GEODETICDATUM', 'ENGCRS', 'ENGINEERINGCRS'];
function testWKT(code){
return codeWords.some(function (word) {
return code.indexOf(word) > -1;
@@ -34,4 +33,4 @@ function parse(code){
}
}
-module.exports = parse;
+export default parse;
diff --git a/lib/projString.js b/lib/projString.js
index 7affc89..eb58116 100644
--- a/lib/projString.js
+++ b/lib/projString.js
@@ -1,8 +1,9 @@
-var D2R = 0.01745329251994329577;
-var PrimeMeridian = require('./constants/PrimeMeridian');
-var units = require('./constants/units');
+import {D2R} from './constants/values';
+import PrimeMeridian from './constants/PrimeMeridian';
+import units from './constants/units';
+import match from './match';
-module.exports = function(defData) {
+export default function(defData) {
var self = {};
var paramObj = defData.split('+').map(function(v) {
return v.trim();
@@ -85,15 +86,17 @@ module.exports = function(defData) {
},
units: function(v) {
self.units = v;
- if (units[v]) {
- self.to_meter = units[v].to_meter;
+ var unit = match(units, v);
+ if (unit) {
+ self.to_meter = unit.to_meter;
}
},
from_greenwich: function(v) {
self.from_greenwich = v * D2R;
},
pm: function(v) {
- self.from_greenwich = (PrimeMeridian[v] ? PrimeMeridian[v] : parseFloat(v)) * D2R;
+ var pm = match(PrimeMeridian, v);
+ self.from_greenwich = (pm ? pm : parseFloat(v)) * D2R;
},
nadgrids: function(v) {
if (v === '@null') {
@@ -129,4 +132,4 @@ module.exports = function(defData) {
self.datumCode = self.datumCode.toLowerCase();
}
return self;
-};
+}
diff --git a/lib/projections.js b/lib/projections.js
index 4e6e458..6667b44 100644
--- a/lib/projections.js
+++ b/lib/projections.js
@@ -1,7 +1,6 @@
-var projs = [
- require('./projections/merc'),
- require('./projections/longlat')
-];
+import merc from "./projections/merc";
+import longlat from "./projections/longlat";
+var projs = [merc, longlat];
var names = {};
var projStore = [];
@@ -18,9 +17,9 @@ function add(proj, i) {
return this;
}
-exports.add = add;
+export {add};
-exports.get = function(name) {
+export function get(name) {
if (!name) {
return false;
}
@@ -28,7 +27,13 @@ exports.get = function(name) {
if (typeof names[n] !== 'undefined' && projStore[names[n]]) {
return projStore[names[n]];
}
-};
-exports.start = function() {
+}
+
+export function start() {
projs.forEach(add);
+}
+export default {
+ start: start,
+ add: add,
+ get: get
};
diff --git a/lib/projections/aea.js b/lib/projections/aea.js
index dd21192..44cb0fe 100644
--- a/lib/projections/aea.js
+++ b/lib/projections/aea.js
@@ -1,9 +1,10 @@
-var EPSLN = 1.0e-10;
-var msfnz = require('../common/msfnz');
-var qsfnz = require('../common/qsfnz');
-var adjust_lon = require('../common/adjust_lon');
-var asinz = require('../common/asinz');
-exports.init = function() {
+import msfnz from '../common/msfnz';
+import qsfnz from '../common/qsfnz';
+import adjust_lon from '../common/adjust_lon';
+import asinz from '../common/asinz';
+import {EPSLN} from '../constants/values';
+
+export function init() {
if (Math.abs(this.lat1 + this.lat2) < EPSLN) {
return;
@@ -38,11 +39,11 @@ exports.init = function() {
}
this.c = this.ms1 * this.ms1 + this.ns0 * this.qs1;
this.rh = this.a * Math.sqrt(this.c - this.ns0 * this.qs0) / this.ns0;
-};
+}
/* Albers Conical Equal Area forward equations--mapping lat,long to x,y
-------------------------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
@@ -59,10 +60,9 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
+}
-
-exports.inverse = function(p) {
+export function inverse(p) {
var rh1, qs, con, theta, lon, lat;
p.x -= this.x0;
@@ -92,12 +92,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
-};
+}
/* Function to compute phi1, the latitude for the inverse of the
Albers Conical Equal-Area projection.
-------------------------------------------*/
-exports.phi1z = function(eccent, qs) {
+export function phi1z(eccent, qs) {
var sinphi, cosphi, con, com, dphi;
var phi = asinz(0.5 * qs);
if (eccent < EPSLN) {
@@ -117,5 +117,13 @@ exports.phi1z = function(eccent, qs) {
}
}
return null;
+}
+
+export var names = ["Albers_Conic_Equal_Area", "Albers", "aea"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names,
+ phi1z: phi1z
};
-exports.names = ["Albers_Conic_Equal_Area", "Albers", "aea"];
diff --git a/lib/projections/aeqd.js b/lib/projections/aeqd.js
index 52aca72..c52c5f6 100644
--- a/lib/projections/aeqd.js
+++ b/lib/projections/aeqd.js
@@ -1,20 +1,23 @@
-var adjust_lon = require('../common/adjust_lon');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var mlfn = require('../common/mlfn');
-var e0fn = require('../common/e0fn');
-var e1fn = require('../common/e1fn');
-var e2fn = require('../common/e2fn');
-var e3fn = require('../common/e3fn');
-var gN = require('../common/gN');
-var asinz = require('../common/asinz');
-var imlfn = require('../common/imlfn');
-exports.init = function() {
+import adjust_lon from '../common/adjust_lon';
+import {HALF_PI, EPSLN} from '../constants/values';
+
+import mlfn from '../common/mlfn';
+import e0fn from '../common/e0fn';
+import e1fn from '../common/e1fn';
+import e2fn from '../common/e2fn';
+import e3fn from '../common/e3fn';
+import gN from '../common/gN';
+import asinz from '../common/asinz';
+import imlfn from '../common/imlfn';
+
+
+
+export function init() {
this.sin_p12 = Math.sin(this.lat0);
this.cos_p12 = Math.cos(this.lat0);
-};
+}
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
var sinphi = Math.sin(p.y);
@@ -97,9 +100,9 @@ exports.forward = function(p) {
}
-};
+}
-exports.inverse = function(p) {
+export function inverse(p) {
p.x -= this.x0;
p.y -= this.y0;
var rh, z, sinz, cosz, lon, lat, con, e0, e1, e2, e3, Mlp, M, N1, psi, Az, cosAz, tmp, A, B, D, Ee, F;
@@ -193,5 +196,12 @@ exports.inverse = function(p) {
}
}
+}
+
+export var names = ["Azimuthal_Equidistant", "aeqd"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Azimuthal_Equidistant", "aeqd"];
diff --git a/lib/projections/cass.js b/lib/projections/cass.js
index 422222e..74f4d38 100644
--- a/lib/projections/cass.js
+++ b/lib/projections/cass.js
@@ -1,15 +1,15 @@
-var mlfn = require('../common/mlfn');
-var e0fn = require('../common/e0fn');
-var e1fn = require('../common/e1fn');
-var e2fn = require('../common/e2fn');
-var e3fn = require('../common/e3fn');
-var gN = require('../common/gN');
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-var imlfn = require('../common/imlfn');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-exports.init = function() {
+import mlfn from '../common/mlfn';
+import e0fn from '../common/e0fn';
+import e1fn from '../common/e1fn';
+import e2fn from '../common/e2fn';
+import e3fn from '../common/e3fn';
+import gN from '../common/gN';
+import adjust_lon from '../common/adjust_lon';
+import adjust_lat from '../common/adjust_lat';
+import imlfn from '../common/imlfn';
+import {HALF_PI, EPSLN} from '../constants/values';
+
+export function init() {
if (!this.sphere) {
this.e0 = e0fn(this.es);
this.e1 = e1fn(this.es);
@@ -17,13 +17,11 @@ exports.init = function() {
this.e3 = e3fn(this.es);
this.ml0 = this.a * mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
}
-};
-
-
+}
/* Cassini forward equations--mapping lat,long to x,y
-----------------------------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
/* Forward equations
-----------------*/
@@ -56,11 +54,11 @@ exports.forward = function(p) {
p.x = x + this.x0;
p.y = y + this.y0;
return p;
-};
+}
/* Inverse equations
-----------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
p.x -= this.x0;
p.y -= this.y0;
var x = p.x / this.a;
@@ -99,5 +97,12 @@ exports.inverse = function(p) {
p.y = adjust_lat(phi);
return p;
+}
+
+export var names = ["Cassini", "Cassini_Soldner", "cass"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Cassini", "Cassini_Soldner", "cass"];
\ No newline at end of file
diff --git a/lib/projections/cea.js b/lib/projections/cea.js
index a85d99b..68fc2ad 100644
--- a/lib/projections/cea.js
+++ b/lib/projections/cea.js
@@ -1,24 +1,24 @@
-var adjust_lon = require('../common/adjust_lon');
-var qsfnz = require('../common/qsfnz');
-var msfnz = require('../common/msfnz');
-var iqsfnz = require('../common/iqsfnz');
+import adjust_lon from '../common/adjust_lon';
+import qsfnz from '../common/qsfnz';
+import msfnz from '../common/msfnz';
+import iqsfnz from '../common/iqsfnz';
+
/*
- reference:
+ reference:
"Cartographic Projection Procedures for the UNIX Environment-
A User's Manual" by Gerald I. Evenden,
USGS Open File Report 90-284and Release 4 Interim Reports (2003)
*/
-exports.init = function() {
+export function init() {
//no-op
if (!this.sphere) {
this.k0 = msfnz(this.e, Math.sin(this.lat_ts), Math.cos(this.lat_ts));
}
-};
-
+}
/* Cylindrical Equal Area forward equations--mapping lat,long to x,y
------------------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
var x, y;
@@ -38,11 +38,11 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
+}
/* Cylindrical Equal Area inverse equations--mapping x,y to lat/long
------------------------------------------------------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
p.x -= this.x0;
p.y -= this.y0;
var lon, lat;
@@ -59,5 +59,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["cea"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["cea"];
diff --git a/lib/projections/eqc.js b/lib/projections/eqc.js
index 575f2b4..4451328 100644
--- a/lib/projections/eqc.js
+++ b/lib/projections/eqc.js
@@ -1,6 +1,7 @@
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-exports.init = function() {
+import adjust_lon from '../common/adjust_lon';
+import adjust_lat from '../common/adjust_lat';
+
+export function init() {
this.x0 = this.x0 || 0;
this.y0 = this.y0 || 0;
@@ -10,12 +11,11 @@ exports.init = function() {
this.title = this.title || "Equidistant Cylindrical (Plate Carre)";
this.rc = Math.cos(this.lat_ts);
-};
-
+}
// forward equations--mapping lat,long to x,y
// -----------------------------------------------------------------
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
@@ -25,11 +25,11 @@ exports.forward = function(p) {
p.x = this.x0 + (this.a * dlon * this.rc);
p.y = this.y0 + (this.a * dlat);
return p;
-};
+}
// inverse equations--mapping x,y to lat/long
// -----------------------------------------------------------------
-exports.inverse = function(p) {
+export function inverse(p) {
var x = p.x;
var y = p.y;
@@ -37,5 +37,12 @@ exports.inverse = function(p) {
p.x = adjust_lon(this.long0 + ((x - this.x0) / (this.a * this.rc)));
p.y = adjust_lat(this.lat0 + ((y - this.y0) / (this.a)));
return p;
+}
+
+export var names = ["Equirectangular", "Equidistant_Cylindrical", "eqc"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Equirectangular", "Equidistant_Cylindrical", "eqc"];
diff --git a/lib/projections/eqdc.js b/lib/projections/eqdc.js
index 215a22c..fcf03e1 100644
--- a/lib/projections/eqdc.js
+++ b/lib/projections/eqdc.js
@@ -1,14 +1,15 @@
-var e0fn = require('../common/e0fn');
-var e1fn = require('../common/e1fn');
-var e2fn = require('../common/e2fn');
-var e3fn = require('../common/e3fn');
-var msfnz = require('../common/msfnz');
-var mlfn = require('../common/mlfn');
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-var imlfn = require('../common/imlfn');
-var EPSLN = 1.0e-10;
-exports.init = function() {
+import e0fn from '../common/e0fn';
+import e1fn from '../common/e1fn';
+import e2fn from '../common/e2fn';
+import e3fn from '../common/e3fn';
+import msfnz from '../common/msfnz';
+import mlfn from '../common/mlfn';
+import adjust_lon from '../common/adjust_lon';
+import adjust_lat from '../common/adjust_lat';
+import imlfn from '../common/imlfn';
+import {EPSLN} from '../constants/values';
+
+export function init() {
/* Place parameters in static storage for common use
-------------------------------------------------*/
@@ -44,12 +45,11 @@ exports.init = function() {
this.g = this.ml1 + this.ms1 / this.ns;
this.ml0 = mlfn(this.e0, this.e1, this.e2, this.e3, this.lat0);
this.rh = this.a * (this.g - this.ml0);
-};
-
+}
/* Equidistant Conic forward equations--mapping lat,long to x,y
-----------------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
var rh1;
@@ -69,11 +69,11 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
+}
/* Inverse equations
-----------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
p.x -= this.x0;
p.y = this.rh - p.y + this.y0;
var con, rh1, lat, lon;
@@ -106,5 +106,12 @@ exports.inverse = function(p) {
return p;
}
+}
+
+export var names = ["Equidistant_Conic", "eqdc"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Equidistant_Conic", "eqdc"];
diff --git a/lib/projections/equi.js b/lib/projections/equi.js
index c1edfdc..f91a522 100644
--- a/lib/projections/equi.js
+++ b/lib/projections/equi.js
@@ -1,17 +1,16 @@
-var adjust_lon = require('../common/adjust_lon');
-exports.init = function() {
+import adjust_lon from '../common/adjust_lon';
+
+export function init() {
this.x0 = this.x0 || 0;
this.y0 = this.y0 || 0;
this.lat0 = this.lat0 || 0;
this.long0 = this.long0 || 0;
///this.t2;
-};
-
-
+}
/* Equirectangular forward equations--mapping lat,long to x,y
---------------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
@@ -25,13 +24,11 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
-
-
+}
/* Equirectangular inverse equations--mapping x,y to lat/long
---------------------------------------------------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
p.x -= this.x0;
p.y -= this.y0;
@@ -40,5 +37,12 @@ exports.inverse = function(p) {
var lon = adjust_lon(this.long0 + p.x / (this.a * Math.cos(this.lat0)));
p.x = lon;
p.y = lat;
+}
+
+export var names = ["equi"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["equi"];
diff --git a/lib/projections/etmerc.js b/lib/projections/etmerc.js
new file mode 100644
index 0000000..15f99ae
--- /dev/null
+++ b/lib/projections/etmerc.js
@@ -0,0 +1,166 @@
+// Heavily based on this etmerc projection implementation
+// https://github.com/mbloch/mapshaper-proj/blob/master/src/projections/etmerc.js
+
+import sinh from '../common/sinh';
+import hypot from '../common/hypot';
+import asinhy from '../common/asinhy';
+import gatg from '../common/gatg';
+import clens from '../common/clens';
+import clens_cmplx from '../common/clens_cmplx';
+import adjust_lon from '../common/adjust_lon';
+
+export function init() {
+ if (this.es === undefined || this.es <= 0) {
+ throw new Error('incorrect elliptical usage');
+ }
+
+ 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;
+
+ this.cgb = [];
+ this.cbg = [];
+ this.utg = [];
+ this.gtu = [];
+
+ var f = this.es / (1 + Math.sqrt(1 - this.es));
+ var n = f / (2 - f);
+ var np = n;
+
+ this.cgb[0] = n * (2 + n * (-2 / 3 + n * (-2 + n * (116 / 45 + n * (26 / 45 + n * (-2854 / 675 ))))));
+ this.cbg[0] = n * (-2 + n * ( 2 / 3 + n * ( 4 / 3 + n * (-82 / 45 + n * (32 / 45 + n * (4642 / 4725))))));
+
+ np = np * n;
+ this.cgb[1] = np * (7 / 3 + n * (-8 / 5 + n * (-227 / 45 + n * (2704 / 315 + n * (2323 / 945)))));
+ this.cbg[1] = np * (5 / 3 + n * (-16 / 15 + n * ( -13 / 9 + n * (904 / 315 + n * (-1522 / 945)))));
+
+ np = np * n;
+ this.cgb[2] = np * (56 / 15 + n * (-136 / 35 + n * (-1262 / 105 + n * (73814 / 2835))));
+ this.cbg[2] = np * (-26 / 15 + n * (34 / 21 + n * (8 / 5 + n * (-12686 / 2835))));
+
+ np = np * n;
+ this.cgb[3] = np * (4279 / 630 + n * (-332 / 35 + n * (-399572 / 14175)));
+ this.cbg[3] = np * (1237 / 630 + n * (-12 / 5 + n * ( -24832 / 14175)));
+
+ np = np * n;
+ this.cgb[4] = np * (4174 / 315 + n * (-144838 / 6237));
+ this.cbg[4] = np * (-734 / 315 + n * (109598 / 31185));
+
+ np = np * n;
+ this.cgb[5] = np * (601676 / 22275);
+ this.cbg[5] = np * (444337 / 155925);
+
+ np = Math.pow(n, 2);
+ this.Qn = this.k0 / (1 + n) * (1 + np * (1 / 4 + np * (1 / 64 + np / 256)));
+
+ this.utg[0] = n * (-0.5 + n * ( 2 / 3 + n * (-37 / 96 + n * ( 1 / 360 + n * (81 / 512 + n * (-96199 / 604800))))));
+ this.gtu[0] = n * (0.5 + n * (-2 / 3 + n * (5 / 16 + n * (41 / 180 + n * (-127 / 288 + n * (7891 / 37800))))));
+
+ this.utg[1] = np * (-1 / 48 + n * (-1 / 15 + n * (437 / 1440 + n * (-46 / 105 + n * (1118711 / 3870720)))));
+ this.gtu[1] = np * (13 / 48 + n * (-3 / 5 + n * (557 / 1440 + n * (281 / 630 + n * (-1983433 / 1935360)))));
+
+ np = np * n;
+ this.utg[2] = np * (-17 / 480 + n * (37 / 840 + n * (209 / 4480 + n * (-5569 / 90720 ))));
+ this.gtu[2] = np * (61 / 240 + n * (-103 / 140 + n * (15061 / 26880 + n * (167603 / 181440))));
+
+ np = np * n;
+ this.utg[3] = np * (-4397 / 161280 + n * (11 / 504 + n * (830251 / 7257600)));
+ this.gtu[3] = np * (49561 / 161280 + n * (-179 / 168 + n * (6601661 / 7257600)));
+
+ np = np * n;
+ this.utg[4] = np * (-4583 / 161280 + n * (108847 / 3991680));
+ this.gtu[4] = np * (34729 / 80640 + n * (-3418889 / 1995840));
+
+ np = np * n;
+ this.utg[5] = np * (-20648693 / 638668800);
+ this.gtu[5] = np * (212378941 / 319334400);
+
+ var Z = gatg(this.cbg, this.lat0);
+ this.Zb = -this.Qn * (Z + clens(this.gtu, 2 * Z));
+}
+
+export function forward(p) {
+ var Ce = adjust_lon(p.x - this.long0);
+ var Cn = p.y;
+
+ Cn = gatg(this.cbg, Cn);
+
+ var sin_Cn = Math.sin(Cn);
+ var cos_Cn = Math.cos(Cn);
+ var sin_Ce = Math.sin(Ce);
+ var cos_Ce = Math.cos(Ce);
+
+ Cn = Math.atan2(sin_Cn, cos_Ce * cos_Cn);
+ Ce = Math.atan2(sin_Ce * cos_Cn, hypot(sin_Cn, cos_Cn * cos_Ce));
+ Ce = asinhy(Math.tan(Ce));
+
+ var tmp = clens_cmplx(this.gtu, 2 * Cn, 2 * Ce);
+
+ Cn = Cn + tmp[0];
+ Ce = Ce + tmp[1];
+
+ var x;
+ var y;
+
+ if (Math.abs(Ce) <= 2.623395162778) {
+ x = this.a * (this.Qn * Ce) + this.x0;
+ y = this.a * (this.Qn * Cn + this.Zb) + this.y0;
+ }
+ else {
+ x = Infinity;
+ y = Infinity;
+ }
+
+ p.x = x;
+ p.y = y;
+
+ return p;
+}
+
+export function inverse(p) {
+ var Ce = (p.x - this.x0) * (1 / this.a);
+ var Cn = (p.y - this.y0) * (1 / this.a);
+
+ Cn = (Cn - this.Zb) / this.Qn;
+ Ce = Ce / this.Qn;
+
+ var lon;
+ var lat;
+
+ if (Math.abs(Ce) <= 2.623395162778) {
+ var tmp = clens_cmplx(this.utg, 2 * Cn, 2 * Ce);
+
+ Cn = Cn + tmp[0];
+ Ce = Ce + tmp[1];
+ Ce = Math.atan(sinh(Ce));
+
+ var sin_Cn = Math.sin(Cn);
+ var cos_Cn = Math.cos(Cn);
+ var sin_Ce = Math.sin(Ce);
+ var cos_Ce = Math.cos(Ce);
+
+ Cn = Math.atan2(sin_Cn * cos_Ce, hypot(sin_Ce, cos_Ce * cos_Cn));
+ Ce = Math.atan2(sin_Ce, cos_Ce * cos_Cn);
+
+ lon = adjust_lon(Ce + this.long0);
+ lat = gatg(this.cgb, Cn);
+ }
+ else {
+ lon = Infinity;
+ lat = Infinity;
+ }
+
+ p.x = lon;
+ p.y = lat;
+
+ return p;
+}
+
+export var names = ["Extended_Transverse_Mercator", "Extended Transverse Mercator", "etmerc"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
+};
diff --git a/lib/projections/gauss.js b/lib/projections/gauss.js
index 3ed498f..df23797 100644
--- a/lib/projections/gauss.js
+++ b/lib/projections/gauss.js
@@ -1,8 +1,8 @@
-var FORTPI = Math.PI/4;
-var srat = require('../common/srat');
-var HALF_PI = Math.PI/2;
+import srat from '../common/srat';
var MAX_ITER = 20;
-exports.init = function() {
+import {HALF_PI, FORTPI} from '../constants/values';
+
+export function init() {
var sphi = Math.sin(this.lat0);
var cphi = Math.cos(this.lat0);
cphi *= cphi;
@@ -11,18 +11,18 @@ exports.init = function() {
this.phic0 = Math.asin(sphi / this.C);
this.ratexp = 0.5 * this.C * this.e;
this.K = Math.tan(0.5 * this.phic0 + FORTPI) / (Math.pow(Math.tan(0.5 * this.lat0 + FORTPI), this.C) * srat(this.e * sphi, this.ratexp));
-};
+}
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
p.y = 2 * Math.atan(this.K * Math.pow(Math.tan(0.5 * lat + FORTPI), this.C) * srat(this.e * Math.sin(lat), this.ratexp)) - HALF_PI;
p.x = this.C * lon;
return p;
-};
+}
-exports.inverse = function(p) {
+export function inverse(p) {
var DEL_TOL = 1e-14;
var lon = p.x / this.C;
var lat = p.y;
@@ -41,5 +41,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["gauss"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["gauss"];
diff --git a/lib/projections/gnom.js b/lib/projections/gnom.js
index 9d0deba..066cff8 100644
--- a/lib/projections/gnom.js
+++ b/lib/projections/gnom.js
@@ -1,6 +1,6 @@
-var adjust_lon = require('../common/adjust_lon');
-var EPSLN = 1.0e-10;
-var asinz = require('../common/asinz');
+import adjust_lon from '../common/adjust_lon';
+import asinz from '../common/asinz';
+import {EPSLN} from '../constants/values';
/*
reference:
@@ -8,7 +8,7 @@ var asinz = require('../common/asinz');
http://mathworld.wolfram.com/GnomonicProjection.html
Accessed: 12th November 2009
*/
-exports.init = function() {
+export function init() {
/* Place parameters in static storage for common use
-------------------------------------------------*/
@@ -17,12 +17,11 @@ exports.init = function() {
// Approximation for projecting points to the horizon (infinity)
this.infinity_dist = 1000 * this.a;
this.rc = 1;
-};
-
+}
/* Gnomonic forward equations--mapping lat,long to x,y
---------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var sinphi, cosphi; /* sin and cos value */
var dlon; /* delta longitude value */
var coslon; /* cos of longitude */
@@ -48,10 +47,10 @@ exports.forward = function(p) {
else {
// Point is in the opposing hemisphere and is unprojectable
- // We still need to return a reasonable point, so we project
- // to infinity, on a bearing
+ // We still need to return a reasonable point, so we project
+ // to infinity, on a bearing
// equivalent to the northern hemisphere equivalent
- // This is a reasonable approximation for short shapes and lines that
+ // This is a reasonable approximation for short shapes and lines that
// straddle the horizon.
x = this.x0 + this.infinity_dist * cosphi * Math.sin(dlon);
@@ -61,10 +60,9 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
-
+}
-exports.inverse = function(p) {
+export function inverse(p) {
var rh; /* Rho */
var sinc, cosc;
var c;
@@ -95,5 +93,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["gnom"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["gnom"];
diff --git a/lib/projections/gstmerc.js b/lib/projections/gstmerc.js
index 6424a79..34d95c1 100644
--- a/lib/projections/gstmerc.js
+++ b/lib/projections/gstmerc.js
@@ -1,8 +1,9 @@
-var latiso = require('../common/latiso');
-var sinh = require('../common/sinh');
-var cosh = require('../common/cosh');
-var invlatiso = require('../common/invlatiso');
-exports.init = function() {
+import latiso from '../common/latiso';
+import sinh from '../common/sinh';
+import cosh from '../common/cosh';
+import invlatiso from '../common/invlatiso';
+
+export function init() {
// array of: a, b, lon0, lat0, k0, x0, y0
var temp = this.b / this.a;
@@ -20,12 +21,11 @@ exports.init = function() {
if (!this.title) {
this.title = "Gauss Schreiber transverse mercator";
}
-};
-
+}
// forward equations--mapping lat,long to x,y
// -----------------------------------------------------------------
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
@@ -37,11 +37,11 @@ exports.forward = function(p) {
p.x = this.xs + (this.n2 * Ls1);
p.y = this.ys + (this.n2 * Math.atan(sinh(Ls) / Math.cos(L)));
return p;
-};
+}
// inverse equations--mapping x,y to lat/long
// -----------------------------------------------------------------
-exports.inverse = function(p) {
+export function inverse(p) {
var x = p.x;
var y = p.y;
@@ -52,5 +52,12 @@ exports.inverse = function(p) {
p.x = this.lc + L / this.rs;
p.y = invlatiso(this.e, (LC - this.cp) / this.rs);
return p;
+}
+
+export var names = ["gstmerg"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["gstmerg"];
diff --git a/lib/projections/krovak.js b/lib/projections/krovak.js
index 3c64e33..620cf7d 100644
--- a/lib/projections/krovak.js
+++ b/lib/projections/krovak.js
@@ -1,5 +1,6 @@
-var adjust_lon = require('../common/adjust_lon');
-exports.init = function() {
+import adjust_lon from '../common/adjust_lon';
+
+export function init() {
this.a = 6377397.155;
this.es = 0.006674372230614;
this.e = Math.sqrt(this.es);
@@ -29,12 +30,12 @@ exports.init = function() {
this.n = Math.sin(this.s0);
this.ro0 = this.k1 * this.n0 / Math.tan(this.s0);
this.ad = this.s90 - this.uq;
-};
+}
/* ellipsoid */
/* calculate xy from lat/lon */
/* Constants, identical to inverse transform function */
-exports.forward = function(p) {
+export function forward(p) {
var gfi, u, deltav, s, d, eps, ro;
var lon = p.x;
var lat = p.y;
@@ -55,10 +56,10 @@ exports.forward = function(p) {
p.x *= -1;
}
return (p);
-};
+}
/* calculate lat/lon from xy */
-exports.inverse = function(p) {
+export function inverse(p) {
var u, deltav, s, d, eps, ro, fi1;
var ok;
@@ -94,5 +95,12 @@ exports.inverse = function(p) {
}
return (p);
+}
+
+export var names = ["Krovak", "krovak"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Krovak", "krovak"];
diff --git a/lib/projections/laea.js b/lib/projections/laea.js
index 22bf1e7..c51270c 100644
--- a/lib/projections/laea.js
+++ b/lib/projections/laea.js
@@ -1,23 +1,24 @@
-var HALF_PI = Math.PI/2;
-var FORTPI = Math.PI/4;
-var EPSLN = 1.0e-10;
-var qsfnz = require('../common/qsfnz');
-var adjust_lon = require('../common/adjust_lon');
+
+import {HALF_PI, EPSLN, FORTPI} from '../constants/values';
+
+import qsfnz from '../common/qsfnz';
+import adjust_lon from '../common/adjust_lon';
+
/*
reference
"New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
*/
-exports.S_POLE = 1;
-exports.N_POLE = 2;
-exports.EQUIT = 3;
-exports.OBLIQ = 4;
+export var S_POLE = 1;
+export var N_POLE = 2;
+export var EQUIT = 3;
+export var OBLIQ = 4;
/* Initialize the Lambert Azimuthal Equal Area projection
------------------------------------------------------*/
-exports.init = function() {
+export function init() {
var t = Math.abs(this.lat0);
if (Math.abs(t - HALF_PI) < EPSLN) {
this.mode = this.lat0 < 0 ? this.S_POLE : this.N_POLE;
@@ -33,7 +34,7 @@ exports.init = function() {
this.qp = qsfnz(this.e, 1);
this.mmf = 0.5 / (1 - this.es);
- this.apa = this.authset(this.es);
+ this.apa = authset(this.es);
switch (this.mode) {
case this.N_POLE:
this.dd = 1;
@@ -64,11 +65,11 @@ exports.init = function() {
this.cosph0 = Math.cos(this.lat0);
}
}
-};
+}
/* Lambert Azimuthal Equal Area forward equations--mapping lat,long to x,y
-----------------------------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
/* Forward equations
-----------------*/
@@ -77,7 +78,6 @@ exports.forward = function(p) {
var phi = p.y;
lam = adjust_lon(lam - this.long0);
-
if (this.sphere) {
sinphi = Math.sin(phi);
cosphi = Math.cos(phi);
@@ -163,17 +163,16 @@ exports.forward = function(p) {
p.x = this.a * x + this.x0;
p.y = this.a * y + this.y0;
return p;
-};
+}
/* Inverse equations
-----------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
p.x -= this.x0;
p.y -= this.y0;
var x = p.x / this.a;
var y = p.y / this.a;
var lam, phi, cCe, sCe, q, rho, ab;
-
if (this.sphere) {
var cosz = 0,
rh, sinz = 0;
@@ -250,39 +249,50 @@ exports.inverse = function(p) {
}
}
lam = Math.atan2(x, y);
- phi = this.authlat(Math.asin(ab), this.apa);
+ phi = authlat(Math.asin(ab), this.apa);
}
-
p.x = adjust_lon(this.long0 + lam);
p.y = phi;
return p;
-};
+}
/* determine latitude from authalic latitude */
-exports.P00 = 0.33333333333333333333;
-exports.P01 = 0.17222222222222222222;
-exports.P02 = 0.10257936507936507936;
-exports.P10 = 0.06388888888888888888;
-exports.P11 = 0.06640211640211640211;
-exports.P20 = 0.01641501294219154443;
+var P00 = 0.33333333333333333333;
-exports.authset = function(es) {
+var P01 = 0.17222222222222222222;
+var P02 = 0.10257936507936507936;
+var P10 = 0.06388888888888888888;
+var P11 = 0.06640211640211640211;
+var P20 = 0.01641501294219154443;
+
+function authset(es) {
var t;
var APA = [];
- APA[0] = es * this.P00;
+ APA[0] = es * P00;
t = es * es;
- APA[0] += t * this.P01;
- APA[1] = t * this.P10;
+ APA[0] += t * P01;
+ APA[1] = t * P10;
t *= es;
- APA[0] += t * this.P02;
- APA[1] += t * this.P11;
- APA[2] = t * this.P20;
+ APA[0] += t * P02;
+ APA[1] += t * P11;
+ APA[2] = t * P20;
return APA;
-};
+}
-exports.authlat = function(beta, APA) {
+function authlat(beta, APA) {
var t = beta + beta;
return (beta + APA[0] * Math.sin(t) + APA[1] * Math.sin(t + t) + APA[2] * Math.sin(t + t + t));
+}
+
+export var names = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names,
+ S_POLE: S_POLE,
+ N_POLE: N_POLE,
+ EQUIT: EQUIT,
+ OBLIQ: OBLIQ
};
-exports.names = ["Lambert Azimuthal Equal Area", "Lambert_Azimuthal_Equal_Area", "laea"];
diff --git a/lib/projections/lcc.js b/lib/projections/lcc.js
index 4fb5cfc..2870c17 100644
--- a/lib/projections/lcc.js
+++ b/lib/projections/lcc.js
@@ -1,11 +1,10 @@
-var EPSLN = 1.0e-10;
-var msfnz = require('../common/msfnz');
-var tsfnz = require('../common/tsfnz');
-var HALF_PI = Math.PI/2;
-var sign = require('../common/sign');
-var adjust_lon = require('../common/adjust_lon');
-var phi2z = require('../common/phi2z');
-exports.init = function() {
+import msfnz from '../common/msfnz';
+import tsfnz from '../common/tsfnz';
+import sign from '../common/sign';
+import adjust_lon from '../common/adjust_lon';
+import phi2z from '../common/phi2z';
+import {HALF_PI, EPSLN} from '../constants/values';
+export function init() {
// array of: r_maj,r_min,lat1,lat2,c_lon,c_lat,false_east,false_north
//double c_lat; /* center latitude */
@@ -59,12 +58,11 @@ exports.init = function() {
if (!this.title) {
this.title = "Lambert Conformal Conic";
}
-};
-
+}
// Lambert Conformal conic forward equations--mapping lat,long to x,y
// -----------------------------------------------------------------
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
@@ -92,11 +90,11 @@ exports.forward = function(p) {
p.y = this.k0 * (this.rh - rh1 * Math.cos(theta)) + this.y0;
return p;
-};
+}
// Lambert Conformal Conic inverse equations--mapping x,y to lat/long
// -----------------------------------------------------------------
-exports.inverse = function(p) {
+export function inverse(p) {
var rh1, con, ts;
var lat, lon;
@@ -130,6 +128,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["Lambert Tangential Conformal Conic Projection", "Lambert_Conformal_Conic", "Lambert_Conformal_Conic_2SP", "lcc"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-
-exports.names = ["Lambert Tangential Conformal Conic Projection", "Lambert_Conformal_Conic", "Lambert_Conformal_Conic_2SP", "lcc"];
diff --git a/lib/projections/longlat.js b/lib/projections/longlat.js
index 08fe077..7e66e7d 100644
--- a/lib/projections/longlat.js
+++ b/lib/projections/longlat.js
@@ -1,10 +1,16 @@
-exports.init = function() {
+export function init() {
//no-op for longlat
-};
+}
function identity(pt) {
return pt;
}
-exports.forward = identity;
-exports.inverse = identity;
-exports.names = ["longlat", "identity"];
+export {identity as forward};
+export {identity as inverse};
+export var names = ["longlat", "identity"];
+export default {
+ init: init,
+ forward: identity,
+ inverse: identity,
+ names: names
+};
diff --git a/lib/projections/merc.js b/lib/projections/merc.js
index e17d62a..31ca6c0 100644
--- a/lib/projections/merc.js
+++ b/lib/projections/merc.js
@@ -1,12 +1,10 @@
-var msfnz = require('../common/msfnz');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var R2D = 57.29577951308232088;
-var adjust_lon = require('../common/adjust_lon');
-var FORTPI = Math.PI/4;
-var tsfnz = require('../common/tsfnz');
-var phi2z = require('../common/phi2z');
-exports.init = function() {
+import msfnz from '../common/msfnz';
+
+import adjust_lon from '../common/adjust_lon';
+import tsfnz from '../common/tsfnz';
+import phi2z from '../common/phi2z';
+import {FORTPI, R2D, EPSLN, HALF_PI} from '../constants/values';
+export function init() {
var con = this.b / this.a;
this.es = 1 - con * con;
if(!('x0' in this)){
@@ -34,12 +32,12 @@ exports.init = function() {
}
}
}
-};
+}
/* Mercator forward equations--mapping lat,long to x,y
--------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
// convert to radians
@@ -66,12 +64,11 @@ exports.forward = function(p) {
p.y = y;
return p;
}
-};
-
+}
/* Mercator inverse equations--mapping x,y to lat/long
--------------------------------------------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
var x = p.x - this.x0;
var y = p.y - this.y0;
@@ -92,6 +89,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
-};
+}
-exports.names = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"];
+export var names = ["Mercator", "Popular Visualisation Pseudo Mercator", "Mercator_1SP", "Mercator_Auxiliary_Sphere", "merc"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
+};
diff --git a/lib/projections/mill.js b/lib/projections/mill.js
index 5858d36..3d6ff0d 100644
--- a/lib/projections/mill.js
+++ b/lib/projections/mill.js
@@ -1,4 +1,5 @@
-var adjust_lon = require('../common/adjust_lon');
+import adjust_lon from '../common/adjust_lon';
+
/*
reference
"New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
@@ -8,14 +9,13 @@ var adjust_lon = require('../common/adjust_lon');
/* Initialize the Miller Cylindrical projection
-------------------------------------------*/
-exports.init = function() {
+export function init() {
//no-op
-};
-
+}
/* Miller Cylindrical forward equations--mapping lat,long to x,y
------------------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
/* Forward equations
@@ -27,11 +27,11 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
+}
/* Miller Cylindrical inverse equations--mapping x,y to lat/long
------------------------------------------------------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
p.x -= this.x0;
p.y -= this.y0;
@@ -41,5 +41,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["Miller_Cylindrical", "mill"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Miller_Cylindrical", "mill"];
diff --git a/lib/projections/moll.js b/lib/projections/moll.js
index 48fbfd7..68f1e63 100644
--- a/lib/projections/moll.js
+++ b/lib/projections/moll.js
@@ -1,10 +1,9 @@
-var adjust_lon = require('../common/adjust_lon');
-var EPSLN = 1.0e-10;
-exports.init = function() {};
-
+import adjust_lon from '../common/adjust_lon';
+export function init() {}
+import {EPSLN} from '../constants/values';
/* Mollweide forward equations--mapping lat,long to x,y
----------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
/* Forward equations
-----------------*/
@@ -38,9 +37,9 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
+}
-exports.inverse = function(p) {
+export function inverse(p) {
var theta;
var arg;
@@ -73,5 +72,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["Mollweide", "moll"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Mollweide", "moll"];
diff --git a/lib/projections/nzmg.js b/lib/projections/nzmg.js
index 58597bf..be0741d 100644
--- a/lib/projections/nzmg.js
+++ b/lib/projections/nzmg.js
@@ -1,4 +1,5 @@
-var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
+import {SEC_TO_RAD} from '../constants/values';
+
/*
reference
Department of Land and Survey Technical Circular 1973/32
@@ -13,9 +14,9 @@ var SEC_TO_RAD = 4.84813681109535993589914102357e-6;
* 1 -> m accuracy -- suitable for most mapping applications
* 2 -> mm accuracy
*/
-exports.iterations = 1;
+export var iterations = 1;
-exports.init = function() {
+export function init() {
this.A = [];
this.A[1] = 0.6399175073;
this.A[2] = -0.1358797613;
@@ -68,13 +69,13 @@ exports.init = function() {
this.D[7] = 0.01220;
this.D[8] = 0.00394;
this.D[9] = -0.0013;
-};
+}
/**
New Zealand Map Grid Forward - long/lat to x/y
long/lat in radians
*/
-exports.forward = function(p) {
+export function forward(p) {
var n;
var lon = p.x;
var lat = p.y;
@@ -120,13 +121,12 @@ exports.forward = function(p) {
p.y = (z_re * this.a) + this.y0;
return p;
-};
-
+}
/**
New Zealand Map Grid Inverse - x/y to long/lat
*/
-exports.inverse = function(p) {
+export function inverse(p) {
var n;
var x = p.x;
var y = p.y;
@@ -215,5 +215,12 @@ exports.inverse = function(p) {
p.y = lat;
return p;
+}
+
+export var names = ["New_Zealand_Map_Grid", "nzmg"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["New_Zealand_Map_Grid", "nzmg"];
\ No newline at end of file
diff --git a/lib/projections/omerc.js b/lib/projections/omerc.js
index cdeb70e..3aa9c44 100644
--- a/lib/projections/omerc.js
+++ b/lib/projections/omerc.js
@@ -1,13 +1,11 @@
-var tsfnz = require('../common/tsfnz');
-var adjust_lon = require('../common/adjust_lon');
-var phi2z = require('../common/phi2z');
-var HALF_PI = Math.PI/2;
-var FORTPI = Math.PI/4;
-var EPSLN = 1.0e-10;
+import tsfnz from '../common/tsfnz';
+import adjust_lon from '../common/adjust_lon';
+import phi2z from '../common/phi2z';
+import {EPSLN, HALF_PI, FORTPI} from '../constants/values';
/* Initialize the Oblique Mercator projection
------------------------------------------*/
-exports.init = function() {
+export function init() {
this.no_off = this.no_off || false;
this.no_rot = this.no_rot || false;
@@ -78,12 +76,11 @@ exports.init = function() {
}
}
-};
-
+}
/* Oblique Mercator forward equations--mapping lat,long to x,y
----------------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
var dlon = adjust_lon(lon - this.long0);
@@ -131,9 +128,9 @@ exports.forward = function(p) {
p.y = this.y0 + us * Math.cos(this.alpha) - vs * Math.sin(this.alpha);
}
return p;
-};
+}
-exports.inverse = function(p) {
+export function inverse(p) {
var us, vs;
if (this.no_rot) {
vs = p.y - this.y0;
@@ -163,6 +160,12 @@ exports.inverse = function(p) {
p.x = adjust_lon(this.long0 - Math.atan2(sp * Math.cos(this.gamma0) - vp * Math.sin(this.gamma0), Math.cos(this.bl * us / this.al)) / this.bl);
}
return p;
-};
+}
-exports.names = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "omerc"];
\ No newline at end of file
+export var names = ["Hotine_Oblique_Mercator", "Hotine Oblique Mercator", "Hotine_Oblique_Mercator_Azimuth_Natural_Origin", "Hotine_Oblique_Mercator_Azimuth_Center", "omerc"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
+};
diff --git a/lib/projections/ortho.js b/lib/projections/ortho.js
index 99f6c65..ed9f32e 100644
--- a/lib/projections/ortho.js
+++ b/lib/projections/ortho.js
@@ -1,20 +1,19 @@
-var adjust_lon = require('../common/adjust_lon');
-var EPSLN = 1.0e-10;
-var asinz = require('../common/asinz');
-var HALF_PI = Math.PI/2;
-exports.init = function() {
+import adjust_lon from '../common/adjust_lon';
+import asinz from '../common/asinz';
+import {EPSLN, HALF_PI} from '../constants/values';
+
+export function init() {
//double temp; /* temporary variable */
/* Place parameters in static storage for common use
-------------------------------------------------*/
this.sin_p14 = Math.sin(this.lat0);
this.cos_p14 = Math.cos(this.lat0);
-};
-
+}
/* Orthographic forward equations--mapping lat,long to x,y
---------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var sinphi, cosphi; /* sin and cos value */
var dlon; /* delta longitude value */
var coslon; /* cos of longitude */
@@ -39,10 +38,9 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
-
+}
-exports.inverse = function(p) {
+export function inverse(p) {
var rh; /* height above ellipsoid */
var z; /* angle */
var sinz, cosz; /* sin of z and cos of z */
@@ -82,5 +80,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["ortho"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["ortho"];
diff --git a/lib/projections/poly.js b/lib/projections/poly.js
index e690725..be6f77b 100644
--- a/lib/projections/poly.js
+++ b/lib/projections/poly.js
@@ -1,14 +1,16 @@
-var e0fn = require('../common/e0fn');
-var e1fn = require('../common/e1fn');
-var e2fn = require('../common/e2fn');
-var e3fn = require('../common/e3fn');
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-var mlfn = require('../common/mlfn');
-var EPSLN = 1.0e-10;
-var gN = require('../common/gN');
+import e0fn from '../common/e0fn';
+import e1fn from '../common/e1fn';
+import e2fn from '../common/e2fn';
+import e3fn from '../common/e3fn';
+import adjust_lon from '../common/adjust_lon';
+import adjust_lat from '../common/adjust_lat';
+import mlfn from '../common/mlfn';
+import {EPSLN} from '../constants/values';
+
+import gN from '../common/gN';
var MAX_ITER = 20;
-exports.init = function() {
+
+export function init() {
/* Place parameters in static storage for common use
-------------------------------------------------*/
this.temp = this.b / this.a;
@@ -19,12 +21,11 @@ exports.init = function() {
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); //si que des zeros le calcul ne se fait pas
-};
-
+}
/* Polyconic forward equations--mapping lat,long to x,y
---------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
var x, y, el;
@@ -55,12 +56,11 @@ exports.forward = function(p) {
p.x = x + this.x0;
p.y = y + this.y0;
return p;
-};
-
+}
/* Inverse equations
-----------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
var lon, lat, x, y, i;
var al, bl;
var phi, dphi;
@@ -124,5 +124,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["Polyconic", "poly"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Polyconic", "poly"];
\ No newline at end of file
diff --git a/lib/projections/sinu.js b/lib/projections/sinu.js
index c0ded88..7ff5763 100644
--- a/lib/projections/sinu.js
+++ b/lib/projections/sinu.js
@@ -1,13 +1,15 @@
-var adjust_lon = require('../common/adjust_lon');
-var adjust_lat = require('../common/adjust_lat');
-var pj_enfn = require('../common/pj_enfn');
+import adjust_lon from '../common/adjust_lon';
+import adjust_lat from '../common/adjust_lat';
+import pj_enfn from '../common/pj_enfn';
var MAX_ITER = 20;
-var pj_mlfn = require('../common/pj_mlfn');
-var pj_inv_mlfn = require('../common/pj_inv_mlfn');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var asinz = require('../common/asinz');
-exports.init = function() {
+import pj_mlfn from '../common/pj_mlfn';
+import pj_inv_mlfn from '../common/pj_inv_mlfn';
+import {EPSLN, HALF_PI} from '../constants/values';
+
+import asinz from '../common/asinz';
+
+
+export function init() {
/* Place parameters in static storage for common use
-------------------------------------------------*/
@@ -23,11 +25,11 @@ exports.init = function() {
this.C_x = this.C_y / (this.m + 1);
}
-};
+}
/* Sinusoidal forward equations--mapping lat,long to x,y
-----------------------------------------------------*/
-exports.forward = function(p) {
+export function forward(p) {
var x, y;
var lon = p.x;
var lat = p.y;
@@ -64,9 +66,9 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
+}
-exports.inverse = function(p) {
+export function inverse(p) {
var lat, temp, lon, s;
p.x -= this.x0;
@@ -102,5 +104,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["Sinusoidal", "sinu"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Sinusoidal", "sinu"];
\ No newline at end of file
diff --git a/lib/projections/somerc.js b/lib/projections/somerc.js
index 80d8961..18cdccb 100644
--- a/lib/projections/somerc.js
+++ b/lib/projections/somerc.js
@@ -5,7 +5,8 @@
des systèmes de référence.
http://www.swisstopo.admin.ch/internet/swisstopo/fr/home/topics/survey/sys/refsys/switzerland.parsysrelated1.31216.downloadList.77004.DownloadFile.tmp/swissprojectionfr.pdf
*/
-exports.init = function() {
+
+export function init() {
var phy0 = this.lat0;
this.lambda0 = this.long0;
var sinPhy0 = Math.sin(phy0);
@@ -21,10 +22,9 @@ exports.init = function() {
var k2 = Math.log(Math.tan(Math.PI / 4 + phy0 / 2));
var k3 = Math.log((1 + e * sinPhy0) / (1 - e * sinPhy0));
this.K = k1 - this.alpha * k2 + this.alpha * e / 2 * k3;
-};
-
+}
-exports.forward = function(p) {
+export function forward(p) {
var Sa1 = Math.log(Math.tan(Math.PI / 4 - p.y / 2));
var Sa2 = this.e / 2 * Math.log((1 + this.e * Math.sin(p.y)) / (1 - this.e * Math.sin(p.y)));
var S = -this.alpha * (Sa1 + Sa2) + this.K;
@@ -43,9 +43,9 @@ exports.forward = function(p) {
p.y = this.R / 2 * Math.log((1 + Math.sin(rotB)) / (1 - Math.sin(rotB))) + this.y0;
p.x = this.R * rotI + this.x0;
return p;
-};
+}
-exports.inverse = function(p) {
+export function inverse(p) {
var Y = p.x - this.x0;
var X = p.y - this.y0;
@@ -75,6 +75,12 @@ exports.inverse = function(p) {
p.x = lambda;
p.y = phy;
return p;
-};
+}
-exports.names = ["somerc"];
+export var names = ["somerc"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
+};
diff --git a/lib/projections/stere.js b/lib/projections/stere.js
index 52aeb92..8028cab 100644
--- a/lib/projections/stere.js
+++ b/lib/projections/stere.js
@@ -1,16 +1,17 @@
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var sign = require('../common/sign');
-var msfnz = require('../common/msfnz');
-var tsfnz = require('../common/tsfnz');
-var phi2z = require('../common/phi2z');
-var adjust_lon = require('../common/adjust_lon');
-exports.ssfn_ = function(phit, sinphi, eccen) {
+import {EPSLN, HALF_PI} from '../constants/values';
+
+import sign from '../common/sign';
+import msfnz from '../common/msfnz';
+import tsfnz from '../common/tsfnz';
+import phi2z from '../common/phi2z';
+import adjust_lon from '../common/adjust_lon';
+
+export function ssfn_(phit, sinphi, eccen) {
sinphi *= eccen;
return (Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen));
-};
+}
-exports.init = function() {
+export function init() {
this.coslat0 = Math.cos(this.lat0);
this.sinlat0 = Math.sin(this.lat0);
if (this.sphere) {
@@ -40,10 +41,10 @@ exports.init = function() {
this.cosX0 = Math.cos(this.X0);
this.sinX0 = Math.sin(this.X0);
}
-};
+}
// Stereographic forward equations--mapping lat,long to x,y
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
var sinlat = Math.sin(lat);
@@ -93,11 +94,10 @@ exports.forward = function(p) {
}
//trace(p.toString());
return p;
-};
-
+}
//* Stereographic inverse equations--mapping x,y to lat/long
-exports.inverse = function(p) {
+export function inverse(p) {
p.x -= this.x0;
p.y -= this.y0;
var lon, lat, ts, ce, Chi;
@@ -162,5 +162,13 @@ exports.inverse = function(p) {
//trace(p.toString());
return p;
+}
+
+export var names = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names,
+ ssfn_: ssfn_
};
-exports.names = ["stere", "Stereographic_South_Pole", "Polar Stereographic (variant B)"];
diff --git a/lib/projections/sterea.js b/lib/projections/sterea.js
index 4343e5e..fd20f4e 100644
--- a/lib/projections/sterea.js
+++ b/lib/projections/sterea.js
@@ -1,6 +1,7 @@
-var gauss = require('./gauss');
-var adjust_lon = require('../common/adjust_lon');
-exports.init = function() {
+import gauss from './gauss';
+import adjust_lon from '../common/adjust_lon';
+
+export function init() {
gauss.init.apply(this);
if (!this.rc) {
return;
@@ -11,9 +12,9 @@ exports.init = function() {
if (!this.title) {
this.title = "Oblique Stereographic Alternative";
}
-};
+}
-exports.forward = function(p) {
+export function forward(p) {
var sinc, cosc, cosl, k;
p.x = adjust_lon(p.x - this.long0);
gauss.forward.apply(this, [p]);
@@ -26,9 +27,9 @@ exports.forward = function(p) {
p.x = this.a * p.x + this.x0;
p.y = this.a * p.y + this.y0;
return p;
-};
+}
-exports.inverse = function(p) {
+export function inverse(p) {
var sinc, cosc, lon, lat, rho;
p.x = (p.x - this.x0) / this.a;
p.y = (p.y - this.y0) / this.a;
@@ -52,6 +53,12 @@ exports.inverse = function(p) {
gauss.inverse.apply(this, [p]);
p.x = adjust_lon(p.x + this.long0);
return p;
-};
+}
-exports.names = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea","Oblique Stereographic Alternative"];
+export var names = ["Stereographic_North_Pole", "Oblique_Stereographic", "Polar_Stereographic", "sterea","Oblique Stereographic Alternative"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
+};
diff --git a/lib/projections/tmerc.js b/lib/projections/tmerc.js
index 2eb3617..ea91928 100644
--- a/lib/projections/tmerc.js
+++ b/lib/projections/tmerc.js
@@ -1,15 +1,15 @@
// 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 EPSLN = 1.0e-10;
-var sign = require('../common/sign');
-
-exports.init = function() {
+import pj_enfn from '../common/pj_enfn';
+import pj_mlfn from '../common/pj_mlfn';
+import pj_inv_mlfn from '../common/pj_inv_mlfn';
+import adjust_lon from '../common/adjust_lon';
+
+import {EPSLN, HALF_PI} from '../constants/values';
+import sign from '../common/sign';
+
+export function init() {
this.x0 = this.x0 !== undefined ? this.x0 : 0;
this.y0 = this.y0 !== undefined ? this.y0 : 0;
this.long0 = this.long0 !== undefined ? this.long0 : 0;
@@ -19,13 +19,13 @@ exports.init = function() {
this.en = pj_enfn(this.es);
this.ml0 = pj_mlfn(this.lat0, Math.sin(this.lat0), Math.cos(this.lat0), this.en);
}
-};
+}
/**
Transverse Mercator Forward - long/lat to x/y
long/lat in radians
*/
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
@@ -95,12 +95,12 @@ exports.forward = function(p) {
p.y = y;
return p;
-};
+}
/**
Transverse Mercator Inverse - x/y to long/lat
*/
-exports.inverse = function(p) {
+export function inverse(p) {
var con, phi;
var lat, lon;
var x = (p.x - this.x0) * (1 / this.a);
@@ -162,6 +162,12 @@ exports.inverse = function(p) {
p.y = lat;
return p;
+}
+
+export var names = ["Transverse_Mercator", "Transverse Mercator", "tmerc"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-
-exports.names = ["Transverse_Mercator", "Transverse Mercator", "tmerc"];
diff --git a/lib/projections/utm.js b/lib/projections/utm.js
index 385cabb..a1318e3 100644
--- a/lib/projections/utm.js
+++ b/lib/projections/utm.js
@@ -1,9 +1,9 @@
-var adjust_zone = require('../common/adjust_zone');
-var tmerc = require('./tmerc');
+import adjust_zone from '../common/adjust_zone';
+import etmerc from './etmerc';
+export var dependsOn = 'etmerc';
-exports.dependsOn = 'tmerc';
-exports.init = function() {
+export function init() {
var zone = adjust_zone(this.zone, this.long0);
if (zone === undefined) {
throw new Error('unknown utm zone');
@@ -15,9 +15,14 @@ exports.init = function() {
this.y0 = this.utmSouth ? 10000000 : 0;
this.k0 = 0.9996;
- tmerc.init.apply(this);
- this.forward = tmerc.forward;
- this.inverse = tmerc.inverse;
-};
+ etmerc.init.apply(this);
+ this.forward = etmerc.forward;
+ this.inverse = etmerc.inverse;
+}
-exports.names = ["Universal Transverse Mercator System", "utm"];
+export var names = ["Universal Transverse Mercator System", "utm"];
+export default {
+ init: init,
+ names: names,
+ dependsOn: dependsOn
+};
diff --git a/lib/projections/vandg.js b/lib/projections/vandg.js
index a4babbe..1f1b503 100644
--- a/lib/projections/vandg.js
+++ b/lib/projections/vandg.js
@@ -1,15 +1,17 @@
-var adjust_lon = require('../common/adjust_lon');
-var HALF_PI = Math.PI/2;
-var EPSLN = 1.0e-10;
-var asinz = require('../common/asinz');
+import adjust_lon from '../common/adjust_lon';
+
+import {HALF_PI, EPSLN} from '../constants/values';
+
+import asinz from '../common/asinz';
+
/* Initialize the Van Der Grinten projection
----------------------------------------*/
-exports.init = function() {
+export function init() {
//this.R = 6370997; //Radius of earth
this.R = this.a;
-};
+}
-exports.forward = function(p) {
+export function forward(p) {
var lon = p.x;
var lat = p.y;
@@ -62,11 +64,11 @@ exports.forward = function(p) {
p.x = x;
p.y = y;
return p;
-};
+}
/* Van Der Grinten inverse equations--mapping x,y to lat/long
---------------------------------------------------------*/
-exports.inverse = function(p) {
+export function inverse(p) {
var lon, lat;
var xx, yy, xys, c1, c2, c3;
var a1;
@@ -116,5 +118,12 @@ exports.inverse = function(p) {
p.x = lon;
p.y = lat;
return p;
+}
+
+export var names = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
+export default {
+ init: init,
+ forward: forward,
+ inverse: inverse,
+ names: names
};
-exports.names = ["Van_der_Grinten_I", "VanDerGrinten", "vandg"];
\ No newline at end of file
diff --git a/lib/transform.js b/lib/transform.js
index aed86b9..f86d112 100644
--- a/lib/transform.js
+++ b/lib/transform.js
@@ -1,15 +1,13 @@
-var D2R = 0.01745329251994329577;
-var R2D = 57.29577951308232088;
-var PJD_3PARAM = 1;
-var PJD_7PARAM = 2;
-var datum_transform = require('./datum_transform');
-var adjust_axis = require('./adjust_axis');
-var proj = require('./Proj');
-var toPoint = require('./common/toPoint');
+import {D2R, R2D, PJD_3PARAM, PJD_7PARAM} from './constants/values';
+import datum_transform from './datum_transform';
+import adjust_axis from './adjust_axis';
+import proj from './Proj';
+import toPoint from './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) {
+
+export default function transform(source, dest, point) {
var wgs84;
if (Array.isArray(point)) {
point = toPoint(point);
@@ -52,7 +50,7 @@ module.exports = function transform(source, dest, point) {
// Adjust for the prime meridian if necessary
if (dest.from_greenwich) {
point = {
- x: point.x - dest.grom_greenwich,
+ x: point.x - dest.from_greenwich,
y: point.y
};
}
@@ -79,4 +77,4 @@ module.exports = function transform(source, dest, point) {
}
return point;
-};
+}
diff --git a/lib/version-browser.js b/lib/version-browser.js
deleted file mode 100644
index 57cfb36..0000000
--- a/lib/version-browser.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = '2.3.17';
diff --git a/lib/version.js b/lib/version.js
index 81f6e78..1fe4978 100644
--- a/lib/version.js
+++ b/lib/version.js
@@ -1 +1 @@
-module.exports = require('../package.json').version;
+export {version as default} from '../package.json';
diff --git a/lib/wkt.js b/lib/wkt.js
deleted file mode 100644
index 8e8803b..0000000
--- a/lib/wkt.js
+++ /dev/null
@@ -1,223 +0,0 @@
-var D2R = 0.01745329251994329577;
-var extend = require('./extend');
-
-function mapit(obj, key, v) {
- obj[key] = v.map(function(aa) {
- var o = {};
- sExpr(aa, o);
- return o;
- }).reduce(function(a, b) {
- return extend(a, b);
- }, {});
-}
-
-function sExpr(v, obj) {
- var key;
- if (!Array.isArray(v)) {
- obj[v] = true;
- return;
- }
- else {
- key = v.shift();
- if (key === 'PARAMETER') {
- key = v.shift();
- }
- if (v.length === 1) {
- if (Array.isArray(v[0])) {
- obj[key] = {};
- sExpr(v[0], obj[key]);
- }
- else {
- obj[key] = v[0];
- }
- }
- else if (!v.length) {
- obj[key] = true;
- }
- else if (key === 'TOWGS84') {
- obj[key] = v;
- }
- else {
- obj[key] = {};
- if (['UNIT', 'PRIMEM', 'VERT_DATUM'].indexOf(key) > -1) {
- obj[key] = {
- name: v[0].toLowerCase(),
- convert: v[1]
- };
- if (v.length === 3) {
- obj[key].auth = v[2];
- }
- }
- else if (key === 'SPHEROID') {
- obj[key] = {
- name: v[0],
- a: v[1],
- rf: v[2]
- };
- if (v.length === 4) {
- obj[key].auth = v[3];
- }
- }
- else if (['GEOGCS', 'GEOCCS', 'DATUM', 'VERT_CS', 'COMPD_CS', 'LOCAL_CS', 'FITTED_CS', 'LOCAL_DATUM'].indexOf(key) > -1) {
- v[0] = ['name', v[0]];
- mapit(obj, key, v);
- }
- else if (v.every(function(aa) {
- return Array.isArray(aa);
- })) {
- mapit(obj, key, v);
- }
- else {
- sExpr(v, obj[key]);
- }
- }
- }
-}
-
-function rename(obj, params) {
- var outName = params[0];
- var inName = params[1];
- if (!(outName in obj) && (inName in obj)) {
- obj[outName] = obj[inName];
- if (params.length === 3) {
- obj[outName] = params[2](obj[outName]);
- }
- }
-}
-
-function d2r(input) {
- return input * D2R;
-}
-
-function cleanWKT(wkt) {
- if (wkt.type === 'GEOGCS') {
- wkt.projName = 'longlat';
- }
- else if (wkt.type === 'LOCAL_CS') {
- wkt.projName = 'identity';
- wkt.local = true;
- }
- else {
- if (typeof wkt.PROJECTION === "object") {
- wkt.projName = Object.keys(wkt.PROJECTION)[0];
- }
- else {
- wkt.projName = wkt.PROJECTION;
- }
- }
- if (wkt.UNIT) {
- wkt.units = wkt.UNIT.name.toLowerCase();
- if (wkt.units === 'metre') {
- wkt.units = 'meter';
- }
- if (wkt.UNIT.convert) {
- if (wkt.type === 'GEOGCS') {
- if (wkt.DATUM && wkt.DATUM.SPHEROID) {
- wkt.to_meter = parseFloat(wkt.UNIT.convert, 10)*wkt.DATUM.SPHEROID.a;
- }
- } else {
- wkt.to_meter = parseFloat(wkt.UNIT.convert, 10);
- }
- }
- }
-
- if (wkt.GEOGCS) {
- //if(wkt.GEOGCS.PRIMEM&&wkt.GEOGCS.PRIMEM.convert){
- // wkt.from_greenwich=wkt.GEOGCS.PRIMEM.convert*D2R;
- //}
- if (wkt.GEOGCS.DATUM) {
- wkt.datumCode = wkt.GEOGCS.DATUM.name.toLowerCase();
- }
- else {
- wkt.datumCode = wkt.GEOGCS.name.toLowerCase();
- }
- if (wkt.datumCode.slice(0, 2) === 'd_') {
- wkt.datumCode = wkt.datumCode.slice(2);
- }
- if (wkt.datumCode === 'new_zealand_geodetic_datum_1949' || wkt.datumCode === 'new_zealand_1949') {
- wkt.datumCode = 'nzgd49';
- }
- if (wkt.datumCode === "wgs_1984") {
- if (wkt.PROJECTION === 'Mercator_Auxiliary_Sphere') {
- wkt.sphere = true;
- }
- wkt.datumCode = 'wgs84';
- }
- if (wkt.datumCode.slice(-6) === '_ferro') {
- wkt.datumCode = wkt.datumCode.slice(0, - 6);
- }
- if (wkt.datumCode.slice(-8) === '_jakarta') {
- wkt.datumCode = wkt.datumCode.slice(0, - 8);
- }
- if (~wkt.datumCode.indexOf('belge')) {
- wkt.datumCode = "rnb72";
- }
- if (wkt.GEOGCS.DATUM && wkt.GEOGCS.DATUM.SPHEROID) {
- wkt.ellps = wkt.GEOGCS.DATUM.SPHEROID.name.replace('_19', '').replace(/[Cc]larke\_18/, 'clrk');
- if (wkt.ellps.toLowerCase().slice(0, 13) === "international") {
- wkt.ellps = 'intl';
- }
-
- wkt.a = wkt.GEOGCS.DATUM.SPHEROID.a;
- wkt.rf = parseFloat(wkt.GEOGCS.DATUM.SPHEROID.rf, 10);
- }
- if (~wkt.datumCode.indexOf('osgb_1936')) {
- wkt.datumCode = "osgb36";
- }
- }
- if (wkt.b && !isFinite(wkt.b)) {
- wkt.b = wkt.a;
- }
-
- function toMeter(input) {
- var ratio = wkt.to_meter || 1;
- return parseFloat(input, 10) * ratio;
- }
- var renamer = function(a) {
- return rename(wkt, a);
- };
- var list = [
- ['standard_parallel_1', 'Standard_Parallel_1'],
- ['standard_parallel_2', 'Standard_Parallel_2'],
- ['false_easting', 'False_Easting'],
- ['false_northing', 'False_Northing'],
- ['central_meridian', 'Central_Meridian'],
- ['latitude_of_origin', 'Latitude_Of_Origin'],
- ['latitude_of_origin', 'Central_Parallel'],
- ['scale_factor', 'Scale_Factor'],
- ['k0', 'scale_factor'],
- ['latitude_of_center', 'Latitude_of_center'],
- ['lat0', 'latitude_of_center', d2r],
- ['longitude_of_center', 'Longitude_Of_Center'],
- ['longc', 'longitude_of_center', d2r],
- ['x0', 'false_easting', toMeter],
- ['y0', 'false_northing', toMeter],
- ['long0', 'central_meridian', d2r],
- ['lat0', 'latitude_of_origin', d2r],
- ['lat0', 'standard_parallel_1', d2r],
- ['lat1', 'standard_parallel_1', d2r],
- ['lat2', 'standard_parallel_2', d2r],
- ['alpha', 'azimuth', d2r],
- ['srsCode', 'name']
- ];
- list.forEach(renamer);
- if (!wkt.long0 && wkt.longc && (wkt.projName === 'Albers_Conic_Equal_Area' || wkt.projName === "Lambert_Azimuthal_Equal_Area")) {
- wkt.long0 = wkt.longc;
- }
- if (!wkt.lat_ts && wkt.lat1 && (wkt.projName === 'Stereographic_South_Pole' || wkt.projName === 'Polar Stereographic (variant B)')) {
- wkt.lat0 = d2r(wkt.lat1 > 0 ? 90 : -90);
- wkt.lat_ts = wkt.lat1;
- }
-}
-module.exports = function(wkt, self) {
- var lisp = JSON.parse(("," + wkt).replace(/\s*\,\s*([A-Z_0-9]+?)(\[)/g, ',["$1",').slice(1).replace(/\s*\,\s*([A-Z_0-9]+?)\]/g, ',"$1"]').replace(/,\["VERTCS".+/,''));
- var type = lisp.shift();
- var name = lisp.shift();
- lisp.unshift(['name', name]);
- lisp.unshift(['type', type]);
- lisp.unshift('output');
- var obj = {};
- sExpr(lisp, obj);
- cleanWKT(obj.output);
- return extend(self, obj.output);
-};
diff --git a/package.json b/package.json
index 8559ede..9dfbdfa 100644
--- a/package.json
+++ b/package.json
@@ -1,14 +1,17 @@
{
"name": "proj4",
- "version": "2.3.17-alpha",
+ "version": "2.3.18-alpha",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",
- "main": "lib/index.js",
+ "main": "dist/proj4-src.js",
+ "module": "lib/index.js",
"directories": {
"test": "test",
"doc": "docs"
},
"scripts": {
- "test": "./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"
+ "build": "grunt",
+ "build:tmerc": "grunt build:tmerc",
+ "test": "npm run build && istanbul test _mocha test/test.js"
},
"repository": {
"type": "git",
@@ -20,21 +23,21 @@
"grunt-cli": "~0.1.13",
"grunt": "~0.4.2",
"grunt-contrib-connect": "~0.6.0",
- "grunt-contrib-jshint": "~0.8.0",
+ "grunt-contrib-jshint": "~1.1.0",
"chai": "~1.8.1",
"mocha": "~1.17.1",
"grunt-mocha-phantomjs": "~0.4.0",
- "browserify": "~12.0.1",
- "grunt-browserify": "~4.0.1",
+ "rollup": "^0.41.4",
+ "rollup-plugin-json": "^2.0.1",
+ "rollup-plugin-node-resolve": "^2.0.0",
+ "grunt-rollup": "^1.0.1",
"grunt-contrib-uglify": "~0.11.1",
"curl": "git://github.com/cujojs/curl.git",
"istanbul": "~0.2.4",
"tin": "~0.4.0"
},
- "browser": {
- "./lib/version.js": "./lib/version-browser.js"
- },
"dependencies": {
- "mgrs": "~0.0.2"
+ "mgrs": "1.0.0",
+ "wkt-parser": "^1.1.2"
}
}
diff --git a/publish.sh b/publish.sh
index 93d042f..3ecf38b 100755
--- a/publish.sh
+++ b/publish.sh
@@ -5,8 +5,6 @@ VERSION=$(npm ls --json=true proj4js | grep version | awk '{ print $2}'| sed -e
# Build
git checkout -b build
-echo "module.exports = '$VERSION';" > ./lib/version-browser.js
-git add ./lib/version-browser.js -f
node_modules/.bin/grunt
git add dist -f
git commit -m "build $VERSION"
diff --git a/test/amd.html b/test/amd.html
index d80f9ab..477a1d7 100644
--- a/test/amd.html
+++ b/test/amd.html
@@ -30,8 +30,8 @@
},packages: [
{
name: 'proj4',
- location: '../lib',
- main: 'index.js',
+ location: '../dist',
+ main: 'proj4-src.js',
config: { moduleLoader: '../node_modules/curl-amd/src/curl/loader/cjsm11' } /* <-- hey! */
},
{
diff --git a/test/test.js b/test/test.js
index 0d8fa5b..7b13c1c 100644
--- a/test/test.js
+++ b/test/test.js
@@ -9,7 +9,7 @@ function startTests(chai, proj4, testPoints) {
var assert = chai.assert;
proj4.defs([
["EPSG:102018", "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"],
- ["testmerc", "+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere +datum=none"],
+ ["testmerc", "+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere"],
["testmerc2", "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs"]
]);
proj4.defs('esriOnline', 'PROJCS["WGS_1984_Web_Mercator_Auxiliary_Sphere",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator_Auxiliary_Sphere"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",0.0],PARAMETER["Auxiliary_Sphere_Type",0.0],UNIT["Meter",1.0]]');
@@ -26,14 +26,14 @@ function startTests(chai, proj4, testPoints) {
var rt90 = '+lon_0=15.808277777799999 +lat_0=0.0 +k=1.0 +x_0=1500000.0 +y_0=0.0 +proj=tmerc +ellps=bessel +units=m +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +no_defs';
var rslt = proj4(sweref99tm, rt90).forward([319180, 6399862]);
assert.closeTo(rslt[0], 1271137.9275601401, 0.000001);
- assert.closeTo(rslt[1], 6404230.291448903, 0.000001);
+ assert.closeTo(rslt[1], 6404230.291459564, 0.000001);
});
it('should work with a proj object', function() {
var sweref99tm = proj4('+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
var rt90 = proj4('+lon_0=15.808277777799999 +lat_0=0.0 +k=1.0 +x_0=1500000.0 +y_0=0.0 +proj=tmerc +ellps=bessel +units=m +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +no_defs');
var rslt = proj4(sweref99tm, rt90).forward([319180, 6399862]);
assert.closeTo(rslt[0], 1271137.9275601401, 0.000001);
- assert.closeTo(rslt[1], 6404230.291448903, 0.000001);
+ assert.closeTo(rslt[1], 6404230.291459564, 0.000001);
});
});
@@ -168,7 +168,7 @@ function startTests(chai, proj4, testPoints) {
});
describe('defs', function() {
assert.equal(proj4.defs('testmerc'), proj4.defs['testmerc']);
- proj4.defs('foo', '+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere +datum=none');
+ proj4.defs('foo', '+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere');
assert.typeOf(proj4.defs['foo'], 'object');
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
assert.strictEqual(proj4.defs['urn:x-ogc:def:crs:EPSG:4326'], proj4.defs['EPSG:4326']);
@@ -254,6 +254,6 @@ function startTests(chai, proj4, testPoints) {
}
if(typeof process !== 'undefined'&&process.toString() === '[object process]'){
(function(){
- startTests(require('chai'), require('../lib'), require('./testData'));
+ startTests(require('chai'), require('../dist/proj4-src'), require('./testData'));
})();
}
diff --git a/test/testData.js b/test/testData.js
index 2fd4ce0..cb7d287 100644
--- a/test/testData.js
+++ b/test/testData.js
@@ -29,7 +29,7 @@ var testPoints = [
xy: [ 231394.84,902621.11],
ll: [-71.11881762742996,42.37346263960867]
},
- {code:'["PROJCS","NAD83 / Massachusetts Mainland", GEOGCS["NAD83", DATUM["North American Datum 1983", SPHEROID["GRS 1980", 6378137.0, 298.257222101, AUTHORITY["EPSG","7019"]], TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], AUTHORITY["EPSG","6269"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4269"]], PROJECTION["Lambert_Conformal_Conic_2SP", AUTHORITY["EPSG" [...]
+ {code:'PROJCS["NAD83 / Massachusetts Mainland", GEOGCS["NAD83", DATUM["North American Datum 1983", SPHEROID["GRS 1980", 6378137.0, 298.257222101, AUTHORITY["EPSG","7019"]], TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], AUTHORITY["EPSG","6269"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4269"]], PROJECTION["Lambert_Conformal_Conic_2SP", AUTHORITY["EPSG","9 [...]
xy: [ 231394.84,902621.11],
ll: [-71.11881762742996,42.37346263960867]
},
@@ -263,10 +263,11 @@ var testPoints = [
code:'esriOnline',
ll:[-74,41],
xy:[-8237642.318702244, 5012341.663847514]
- },{
- code:"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +datum=none +no_defs",
- xy: [ 736106.55, 5893331.11 ],
- ll: [11.0, 53.0]
+ },
+ {
+ code: '+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs',
+ xy: [736106.55, 5893331.11],
+ ll: [11.0, 53.0]
},
{
code:'PROJCS["Belge 1972 / Belgian Lambert 72",GEOGCS["Belge 1972",DATUM["Reseau_National_Belge_1972",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[106.869,-52.2978,103.724,-0.33657,0.456955,-1.84218,1],AUTHORITY["EPSG","6313"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4313"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["st [...]
@@ -316,14 +317,24 @@ var testPoints = [
xy: [222650.79679577847, 110642.2294119271]
},
{
- code: '+proj=tmerc +a=6400000 +lat_1=0.5 +lat_2=2 +n=0.5 +datum=none',
+ code: '+proj=tmerc +a=6400000 +lat_1=0.5 +lat_2=2 +n=0.5',
ll: [2, 1],
xy: [223413.46640632232, 111769.14504059685]
},
{
+ code: '+proj=etmerc +zone=30 +ellps=GRS80 +lat_1=0.5 +lat_2=2 +n=0.5',
+ ll: [2, 1],
+ xy: [222650.7967975856, 110642.2294119332]
+ },
+ {
+ code: '+proj=etmerc +k=0.998 +lon_0=-20 +datum=WGS84 +x_0=10000 +y_0=20000',
+ ll: [2, 1],
+ xy: [2516532.477709202, 139083.35793371277]
+ },
+ {
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]
+ xy: [1057002.405491298, 110955.14117594929]
},
{
code: '+proj=utm +lon_0=-3 +ellps=GRS80 +lat_1=0.5 +lat_2=2 +n=0.5',
@@ -334,59 +345,54 @@ var testPoints = [
{
code: '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs',
ll: [2, 1],
- xy: [-959006.3439168662, 113457.31706492987],
- acc: {
- ll: 5
- }
+ xy: [-959006.4926646841, 113457.31956265299]
},
{
code: '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs',
ll: [31, 70],
- xy: [1104629.4280255223, 7845845.076400871],
- acc: {
- ll: 4
- }
+ xy: [1104629.4356366363, 7845845.077685604]
},
// 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
- }
+ xy: [8089746.634775677, 301230.8618526573]
},
{
code: '+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs',
ll: [59.121778, 1.508527],
- xy: [6958363.797581035, 260155.3254079497],
- acc: {
- ll: 0
- }
+ xy: [6969865.865375574, 261237.08330733588]
},
{
code: '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs',
ll: [59.121778, 1.508527],
- xy: [5980907.454031456, 232674.60895515585],
- acc: {
- ll: 1
- }
+ xy: [5984417.050333044, 232959.75386279594]
},
{
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
- }
+ xy: [7421462.108989433, 3922366.25143021]
},
{
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
- }
+ xy: [6548241.281523044, 3478520.1422119136]
+ },
+ // these test cases are for the margin zones 1 and 60
+ {
+ code: '+proj=utm +zone=1 +datum=WGS84 +units=m +no_defs',
+ ll: [-177, 60],
+ xy: [500000, 6651411.190362714]
+ },
+ {
+ code: '+proj=utm +zone=60 +datum=WGS84 +units=m +no_defs',
+ ll: [177, 60],
+ xy: [500000.0000000014, 6651411.190362714]
+ },
+ {
+ code: '+proj=lcc +lat_1=46.8 +lat_0=46.8 +lon_0=0 +k_0=0.99987742 +x_0=600000 +y_0=2200000 +a=6378249.2 +b=6356515 +towgs84=-168,-60,320,0,0,0,0 +pm=paris +units=m +no_defs',
+ ll: [1.4477496, 46.8692953],
+ xy: [532247.285, 2208091.8723]
}
];
if(typeof module !== 'undefined'){
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/proj4js.git
More information about the Pkg-grass-devel
mailing list