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

proj4

Package Overview
Dependencies
Maintainers
2
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proj4 - npm Package Compare versions

Comparing version 2.5.0 to 2.6.0

lib/projections/geocent.js

2

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

@@ -5,0 +5,0 @@ "homepage": "https://github.com/proj4js/proj4js",

{
"name": "proj4",
"version": "2.5.0",
"version": "2.6.0",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",

@@ -5,0 +5,0 @@ "repo": "proj4js/proj4js",

var json = require('rollup-plugin-json');
var nodeResolve = require('rollup-plugin-node-resolve');
var replace = require('rollup-plugin-replace');
var pkg = require('./package.json');

@@ -30,5 +32,6 @@ var projs = [

'qsc',
'robin'
'robin',
'geocent'
];
module.exports = function(grunt) {
module.exports = function (grunt) {
grunt.initConfig({

@@ -66,2 +69,5 @@ pkg: grunt.file.readJSON('package.json'),

plugins: [
replace({
__VERSION__: pkg.version
}),
json(),

@@ -68,0 +74,0 @@ nodeResolve()

@@ -8,11 +8,17 @@ import proj from './Proj';

if (Array.isArray(coords)) {
transformedArray = transform(from, to, coords);
if (coords.length === 3) {
return [transformedArray.x, transformedArray.y, transformedArray.z];
}
else {
transformedArray = transform(from, to, coords) || {x: NaN, y: NaN};
if (coords.length > 2) {
if ((typeof from.name !== 'undefined' && from.name === 'geocent') || (typeof to.name !== 'undefined' && to.name === 'geocent')) {
if (typeof transformedArray.z === 'number') {
return [transformedArray.x, transformedArray.y, transformedArray.z].concat(coords.splice(3));
} else {
return [transformedArray.x, transformedArray.y, coords[2]].concat(coords.splice(3));
}
} else {
return [transformedArray.x, transformedArray.y].concat(coords.splice(2));
}
} else {
return [transformedArray.x, transformedArray.y];
}
}
else {
} else {
out = transform(from, to, coords);

@@ -24,4 +30,10 @@ keys = Object.keys(coords);

keys.forEach(function (key) {
if (key === 'x' || key === 'y') {
return;
if ((typeof from.name !== 'undefined' && from.name === 'geocent') || (typeof to.name !== 'undefined' && to.name === 'geocent')) {
if (key === 'x' || key === 'y' || key === 'z') {
return;
}
} else {
if (key === 'x' || key === 'y') {
return;
}
}

@@ -43,2 +55,3 @@ out[key] = coords[key];

}
function proj4(fromProj, toProj, coord) {

@@ -52,4 +65,3 @@ fromProj = checkProj(fromProj);

single = true;
}
else if (typeof toProj.x !== 'undefined' || Array.isArray(toProj)) {
} else if (typeof toProj.x !== 'undefined' || Array.isArray(toProj)) {
coord = toProj;

@@ -63,9 +75,8 @@ toProj = fromProj;

return transformer(fromProj, toProj, coord);
}
else {
} else {
obj = {
forward: function(coords) {
forward: function (coords) {
return transformer(fromProj, toProj, coords);
},
inverse: function(coords) {
inverse: function (coords) {
return transformer(toProj, fromProj, coords);

@@ -80,2 +91,2 @@ }

}
export default proj4;
export default proj4;

@@ -26,2 +26,3 @@ import tmerc from "./projections/tmerc";

import robin from './projections/robin';
import geocent from './projections/geocent';

@@ -53,9 +54,10 @@ var projs = [

qsc,
robin
robin,
geocent
];
export default function(proj4){
projs.forEach(function(proj){
export default function (proj4) {
projs.forEach(function (proj) {
proj4.Proj.projections.add(proj);
});
}
}

@@ -8,3 +8,2 @@ import proj4 from './core';

import mgrs from "mgrs";
import version from "./version";
import includedProjections from "../projs";

@@ -20,4 +19,4 @@

proj4.mgrs = mgrs;
proj4.version = version;
proj4.version = '__VERSION__';
includedProjections(proj4);
export default proj4;

@@ -57,3 +57,3 @@ import latiso from '../common/latiso';

export var names = ["gstmerg"];
export var names = ["gstmerg", "gstmerc"];
export default {

@@ -60,0 +60,0 @@ init: init,

@@ -32,10 +32,11 @@ import {D2R, R2D, PJD_3PARAM, PJD_7PARAM} from './constants/values';

x: point.x * D2R,
y: point.y * D2R
y: point.y * D2R,
z: point.z || 0
};
}
else {
} else {
if (source.to_meter) {
point = {
x: point.x * source.to_meter,
y: point.y * source.to_meter
y: point.y * source.to_meter,
z: point.z || 0
};

@@ -57,3 +58,4 @@ }

x: point.x - dest.from_greenwich,
y: point.y
y: point.y,
z: point.z || 0
};

@@ -66,3 +68,4 @@ }

x: point.x * R2D,
y: point.y * R2D
y: point.y * R2D,
z: point.z || 0
};

@@ -74,3 +77,4 @@ } else { // else project

x: point.x / dest.to_meter,
y: point.y / dest.to_meter
y: point.y / dest.to_meter,
z: point.z || 0
};

@@ -77,0 +81,0 @@ }

{
"name": "proj4",
"version": "2.5.0",
"version": "2.6.0",
"description": "Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.",

@@ -12,2 +12,3 @@ "main": "dist/proj4-src.js",

"scripts": {
"prepare": "grunt",
"build": "grunt",

@@ -38,2 +39,3 @@ "build:tmerc": "grunt build:tmerc",

"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^2.0.0",
"tin": "~0.5.0"

@@ -40,0 +42,0 @@ },

@@ -27,2 +27,3 @@ import tmerc from './lib/projections/tmerc';

import robin from './lib/projections/robin';
import geocent from './lib/projections/geocent';
export default function(proj4){

@@ -55,2 +56,3 @@ proj4.Proj.projections.add(tmerc);

proj4.Proj.projections.add(robin);
proj4.Proj.projections.add(geocent);
}

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

};
// in case of geocentric proj we need Z value.
if (typeof testPoint.xy[2] === 'number') {
pt.z = testPoint.xy[2]
}
var ll = proj4(testPoint.code, proj4.WGS84, pt);

@@ -171,23 +175,68 @@ assert.closeTo(ll.x, testPoint.ll[0], llEPSLN, 'x is close');

describe('points', function () {
it('should ignore stuff it does not know', function (){
var sweref99tm = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
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({
x: 319180,
y: 6399862,
z: 0,
m: 1000,
method: function () {
return 'correct answer';
}
});
assert.closeTo(rslt.x, 1271137.9275601401, 0.000001);
assert.closeTo(rslt.y, 6404230.291459564, 0.000001);
assert.equal(rslt.z, 0);
assert.equal(rslt.m, 1000);
assert.equal(rslt.method(), 'correct answer');
it('should ignore stuff it does not know', function () {
var sweref99tm = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
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({
x: 319180,
y: 6399862,
z: 0,
m: 1000,
method: function () {
return 'correct answer';
}
});
assert.closeTo(rslt.x, 1271137.9275601401, 0.000001);
assert.closeTo(rslt.y, 6404230.291459564, 0.000001);
assert.equal(rslt.z, 0);
assert.equal(rslt.m, 1000);
assert.equal(rslt.method(), 'correct answer');
});
it('should be able to compute X Y Z M in geocenteric coordinates', function () {
var epsg4978 = '+proj=geocent +datum=WGS84 +units=m +no_defs';
var rslt = proj4(epsg4978).forward({
x: -7.76166,
y: 39.19685,
z: 0,
m: 1000,
method: function () {
return 'correct answer';
}
});
assert.closeTo(rslt.x, 4904199.584207411, 0.000001);
assert.closeTo(rslt.y, -668448.8153664203, 0.000001);
assert.closeTo(rslt.z, 4009276.930771821, 0.000001);
assert.equal(rslt.m, 1000);
assert.equal(rslt.method(), 'correct answer');
});
});
describe('defs', function() {
describe('points array', function () {
it('should ignore stuff it does not know', function () {
var sweref99tm = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
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,
0,
1000,
]);
assert.closeTo(rslt[0], 1271137.9275601401, 0.000001);
assert.closeTo(rslt[1], 6404230.291459564, 0.000001);
assert.equal(rslt[2], 0);
assert.equal(rslt[3], 1000);
});
it('should be able to compute X Y Z M in geocenteric coordinates', function () {
var epsg4978 = '+proj=geocent +datum=WGS84 +units=m +no_defs';
var rslt = proj4(epsg4978).forward([
-7.76166,
39.19685,
0,
1000
]);
assert.closeTo(rslt[0], 4904199.584207411, 0.000001);
assert.closeTo(rslt[1], -668448.8153664203, 0.000001);
assert.closeTo(rslt[2], 4009276.930771821, 0.000001);
assert.equal(rslt[3], 1000);
});
});
describe('defs', function () {
assert.equal(proj4.defs('testmerc'), proj4.defs['testmerc']);

@@ -199,11 +248,11 @@ proj4.defs('foo', '+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere');

describe('wkt', function() {
it('should provide the correct conversion factor for WKT GEOGCS projections', function() {
describe('wkt', function () {
it('should provide the correct conversion factor for WKT GEOGCS projections', function () {
proj4.defs('EPSG:4269', 'GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]]');
assert.equal(proj4.defs['EPSG:4269'].to_meter, 6378137*0.01745329251994328);
assert.equal(proj4.defs['EPSG:4269'].to_meter, 6378137 * 0.01745329251994328);
proj4.defs('EPSG:4279', 'GEOGCS["OS(SN)80",DATUM["OS_SN_1980",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],AUTHORITY["EPSG","6279"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4279"]]');
assert.equal(proj4.defs['EPSG:4279'].to_meter, 6377563.396*0.01745329251994328);
assert.equal(proj4.defs['EPSG:4279'].to_meter, 6377563.396 * 0.01745329251994328);
});
it('should parse wkt and proj4 of the same crs and result in the same params', function() {
it('should parse wkt and proj4 of the same crs and result in the same params', function () {
var s1 = 'GEOGCS["PSD93",DATUM["PDO_Survey_Datum_1993",SPHEROID["Clarke 1880 (RGS)",6378249.145,293.465,AUTHORITY["EPSG","7012"]],TOWGS84[-180.624,-225.516,173.919,-0.81,-1.898,8.336,16.7101],AUTHORITY["EPSG","6134"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4134"]]';

@@ -210,0 +259,0 @@ var s2 = '+proj=longlat +ellps=clrk80 +towgs84=-180.624,-225.516,173.919,-0.81,-1.898,8.336,16.7101 +no_defs';

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

xy: [-12523490.49256873, 5166512.50707369],
ll: [-112.50042920000004,42.036926809999976]
ll: [-112.50042920000004, 42.036926809999976]
},

@@ -565,11 +565,29 @@ {

xy: [-12523490.49256873, 5166512.50707369],
ll: [-112.50042920000004,42.036926809999976]
ll: [-112.50042920000004, 42.036926809999976]
},
{
code: '+proj=geocent +datum=WGS84 +units=m +no_defs',
ll: [-7.56234, 38.96618, 0],
xy: [4922499, -653508, 3989398],
acc: {
ll: 0,
xy: 0
}
},
{
code: '+proj=geocent +ellps=GRS80 +units=m +no_defs',
ll: [-7.56234, 38.96618, 1],
xy: [4922499, -653508, 3989399],
acc: {
ll: 0,
xy: 0
}
}
];
if(typeof module !== 'undefined'){
if (typeof module !== 'undefined') {
module.exports = testPoints;
}else if(typeof define === 'function'){
define(function(){
} else if (typeof define === 'function') {
define(function () {
return testPoints;
});
}
}

Sorry, the diff of this file is not supported yet

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

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc