Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
///////////////////////////////////
proj4.defs('WGS84', epsg['4326'])
proj4.defs([
['EPSG:4326', epsg['4326']],
['EPSG:4269', epsg['4269']]
])
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'))
///////////////////////////////////
// Utils
///////////////////////////////////
// WGS84
proj4.WGS84
// Proj
proj4.Proj('WGS84')
// toPoint
proj4.toPoint([1, 2])
proj4.toPoint([1, 2, 3])
proj4.toPoint([1, 2, 3, 4])
// Point
// WARNING: Deprecated in v3
proj4.Point([1, 2, 3, 4])
transform.transformCoordinatesFlatArray3 = function (srcPrj, tgtPrj, coordinates) {
'use strict';
var i,
smatch = srcPrj.match(axisPattern),
tmatch = tgtPrj.match(axisPattern);
// if the two projections only differ in the middle axis
if (smatch && tmatch && smatch[1] === tmatch[1] && smatch[3] === tmatch[3]) {
for (i = coordinates.length - 3 + 1; i >= 0; i -= 3) {
coordinates[i] *= -1;
}
return coordinates;
}
var src = proj4.Proj(srcPrj),
tgt = proj4.Proj(tgtPrj),
projPoint, initPoint = {};
for (i = coordinates.length - 3; i >= 0; i -= 3) {
initPoint.x = +coordinates[i];
initPoint.y = +coordinates[i + 1];
initPoint.z = +(coordinates[i + 2] || 0.0);
projPoint = proj4.transform(src, tgt, initPoint);
coordinates[i] = projPoint.x;
coordinates[i + 1] = projPoint.y;
coordinates[i + 2] = projPoint.z === undefined ? initPoint.z : projPoint.z;
}
return coordinates;
};
transform.transformCoordinatesFlatArray3 = function (srcPrj, tgtPrj, coordinates) {
'use strict';
var i,
smatch = srcPrj.match(axisPattern),
tmatch = tgtPrj.match(axisPattern);
// if the two projections only differ in the middle axis
if (smatch && tmatch && smatch[1] === tmatch[1] && smatch[3] === tmatch[3]) {
for (i = coordinates.length - 3 + 1; i >= 0; i -= 3) {
coordinates[i] *= -1;
}
return coordinates;
}
var src = proj4.Proj(srcPrj),
tgt = proj4.Proj(tgtPrj),
projPoint, initPoint = {};
for (i = coordinates.length - 3; i >= 0; i -= 3) {
initPoint.x = +coordinates[i];
initPoint.y = +coordinates[i + 1];
initPoint.z = +(coordinates[i + 2] || 0.0);
projPoint = proj4.transform(src, tgt, initPoint);
coordinates[i] = projPoint.x;
coordinates[i + 1] = projPoint.y;
coordinates[i + 2] = projPoint.z === undefined ? initPoint.z : projPoint.z;
}
return coordinates;
};
throw 'Unable to parse SRS name';
}
if (!codeParts || !codeParts[1]) {
throw 'Unable to parse SRS name';
}
code = codeParts[1];
transformation = codeParts[3];
name = authority + ':' + code;
proj = this.projections[name];
if (!proj) {
try {
proj4.Proj(name);
// Known, since no exception
this._store(name, cb, context);
} catch (e) {
this._fetch(authority, code, transformation, cb, context);
}
} else {
cb.call(context || cb, name, proj);
}
},
const crss = _.mapValues(proj4.defs, def => proj4.Proj(def))
export function wgs84ToMercator(point) {
var sourceCRS = proj4.Proj('EPSG:4326');
var destCRS = proj4.Proj('EPSG:3857');
var pt = new proj4.toPoint([point[1], point[0]]);
proj4.transform(sourceCRS, destCRS, pt);
return pt;
}
export function calcBboxFromXY(point, zoomLevel) {
_poll: function(authority, code, cb, context) {
var _this = this,
name = authority + ':' + code;
try {
proj4.Proj(name);
this._store(name, cb, context);
} catch (e) {
setTimeout(function() {
_this._poll(authority, code, cb, context);
}, 100);
}
},
var dbfZipObject = dbffileArray[d];
if (dbfZipObject.name == basename + '.dbf') {
var dbfBuffer = dbfZipObject.asNodeBuffer();
dbfStream = new stream.PassThrough();
dbfStream.end(dbfBuffer);
break;
}
}
var projection;
for (var p = 0; p < prjfileArray.length; p++) {
var prjZipObject = prjfileArray[p];
if (prjZipObject.name == basename + '.prj') {
var prjBuffer = prjZipObject.asNodeBuffer();
projection = proj4.Proj(prjBuffer.toString());
break;
}
}
readers.push({
tableName: basename,
projection: projection,
reader: shp.reader({
shp: shpStream,
dbf: dbfStream,
'ignore-properties': !!dbfStream
})
});
}
return readers;
}
_store: function(name, cb, context) {
var p = proj4.Proj(name);
this.projections[name] = p;
cb.call(context || cb, name, p);
}
});