diff --git a/lib/Proj.js b/lib/Proj.js index 7bc65db..49e3b7f 100644 --- a/lib/Proj.js +++ b/lib/Proj.js @@ -4,7 +4,7 @@ var projections = require('./projections'); var deriveConstants = require('./deriveConstants'); var Datum = require('./constants/Datum'); var datum = require('./datum'); - +var match = require('./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; diff --git a/lib/constants/Ellipsoid.js b/lib/constants/Ellipsoid.js index 51afef8..671500b 100644 --- a/lib/constants/Ellipsoid.js +++ b/lib/constants/Ellipsoid.js @@ -212,4 +212,4 @@ exports.sphere = { a: 6370997.0, b: 6370997.0, ellipseName: "Normal Sphere (r=6370997)" -}; \ No newline at end of file +}; diff --git a/lib/deriveConstants.js b/lib/deriveConstants.js index 38faac0..56edd06 100644 --- a/lib/deriveConstants.js +++ b/lib/deriveConstants.js @@ -6,7 +6,7 @@ var RA4 = 0.04722222222222222222; var RA6 = 0.02215608465608465608; var EPSLN = 1.0e-10; var Ellipsoid = require('./constants/Ellipsoid'); - +var match = require('./match'); exports.eccentricity = function(a, b, rf, R_A) { var a2 = a * a; // used in geocentric var b2 = b * b; // used in geocentric @@ -26,11 +26,12 @@ exports.eccentricity = function(a, b, rf, R_A) { ep2: ep2 }; }; +var wms84 = match(Ellipsoid, 'WGS84'); exports.sphere = function (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 = wms84; } a = ellipse.a; b = ellipse.b; diff --git a/lib/match.js b/lib/match.js new file mode 100644 index 0000000..ccaaaef --- /dev/null +++ b/lib/match.js @@ -0,0 +1,18 @@ +module.exports = match; +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]; + } + } +} diff --git a/lib/parseCode.js b/lib/parseCode.js index 7358a73..a2b7b15 100644 --- a/lib/parseCode.js +++ b/lib/parseCode.js @@ -7,7 +7,7 @@ function testObj(code){ 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) { diff --git a/lib/projString.js b/lib/projString.js index 7affc89..5ff8fd0 100644 --- a/lib/projString.js +++ b/lib/projString.js @@ -1,7 +1,7 @@ var D2R = 0.01745329251994329577; var PrimeMeridian = require('./constants/PrimeMeridian'); var units = require('./constants/units'); - +var match = require('./match'); module.exports = function(defData) { var self = {}; var paramObj = defData.split('+').map(function(v) { @@ -85,15 +85,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') { diff --git a/package.json b/package.json index e58776a..5e092f1 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,6 @@ }, "dependencies": { "mgrs": "~0.0.2", - "wkt-parser": "^1.0.2" + "wkt-parser": "^1.0.3" } }