proj4 2.16.2 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/bower.json +1 -1
- package/component.json +1 -1
- package/dist/proj4-src.js +62 -3
- package/dist/proj4.js +1 -1
- package/lib/nadgrid.js +62 -2
- package/package.json +2 -5
- package/scripts/readme.md +0 -10
- package/scripts/updateDatums.mjs +0 -119
- package/scripts/updateEllipsoids.mjs +0 -70
- package/test/BETA2007.gsb +0 -0
- package/test/ntv2_0_downsampled.gsb +0 -0
- package/test/ntv2_0_downsampled_no_error_columns.gsb +0 -0
- package/test/opt.html +0 -28
- package/test/puppeteer-tests.mjs +0 -110
- package/test/test-ci.mjs +0 -10
- package/test/test.js +0 -639
- package/test/testData.js +0 -2386
package/test/test.js
DELETED
|
@@ -1,639 +0,0 @@
|
|
|
1
|
-
// You can do this in the grunt config for each mocha task, see the `options` config
|
|
2
|
-
|
|
3
|
-
// Start the main app logic.
|
|
4
|
-
|
|
5
|
-
function startTests(chai, proj4, testPoints) {
|
|
6
|
-
var assert = chai.assert;
|
|
7
|
-
proj4.defs([
|
|
8
|
-
['EPSG:102018', '+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'],
|
|
9
|
-
['testmerc', '+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere'],
|
|
10
|
-
['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']
|
|
11
|
-
]);
|
|
12
|
-
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]]');
|
|
13
|
-
|
|
14
|
-
describe('parse', function () {
|
|
15
|
-
it('should parse units', function () {
|
|
16
|
-
assert.equal(proj4.defs('testmerc2').units, 'm');
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('proj2proj', function () {
|
|
21
|
-
it('should work transforming from one projection to another', function () {
|
|
22
|
-
var sweref99tm = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
|
|
23
|
-
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';
|
|
24
|
-
var rslt = proj4(sweref99tm, rt90).forward([319180, 6399862]);
|
|
25
|
-
assert.closeTo(rslt[0], 1271137.927561178, 0.000001);
|
|
26
|
-
assert.closeTo(rslt[1], 6404230.291456626, 0.000001);
|
|
27
|
-
});
|
|
28
|
-
it('should work with a proj object', function () {
|
|
29
|
-
var sweref99tm = proj4('+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
|
|
30
|
-
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');
|
|
31
|
-
var rslt = proj4(sweref99tm, rt90).forward([319180, 6399862]);
|
|
32
|
-
assert.closeTo(rslt[0], 1271137.927561178, 0.000001);
|
|
33
|
-
assert.closeTo(rslt[1], 6404230.291456626, 0.000001);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('proj4', function () {
|
|
38
|
-
describe('core', function () {
|
|
39
|
-
testPoints.forEach(function (testPoint) {
|
|
40
|
-
describe(typeof testPoint.code === 'object' ? testPoint.code.name : testPoint.code, function () {
|
|
41
|
-
var xyAcc = 2,
|
|
42
|
-
llAcc = 6;
|
|
43
|
-
if ('acc' in testPoint) {
|
|
44
|
-
if ('xy' in testPoint.acc) {
|
|
45
|
-
xyAcc = testPoint.acc.xy;
|
|
46
|
-
}
|
|
47
|
-
if ('ll' in testPoint.acc) {
|
|
48
|
-
llAcc = testPoint.acc.ll;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
var xyEPSLN = Math.pow(10, -1 * xyAcc);
|
|
52
|
-
var llEPSLN = Math.pow(10, -1 * llAcc);
|
|
53
|
-
describe('traditional', function () {
|
|
54
|
-
it('should work with forwards', function () {
|
|
55
|
-
var proj = new proj4.Proj(testPoint.code);
|
|
56
|
-
var xy = proj4.transform(proj4.WGS84, proj, proj4.toPoint(testPoint.ll));
|
|
57
|
-
assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close');
|
|
58
|
-
assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close');
|
|
59
|
-
});
|
|
60
|
-
it('should work with backwards', function () {
|
|
61
|
-
var proj = new proj4.Proj(testPoint.code);
|
|
62
|
-
var ll = proj4.transform(proj, proj4.WGS84, proj4.toPoint(testPoint.xy));
|
|
63
|
-
assert.closeTo(ll.x, testPoint.ll[0], llEPSLN, 'lng is close');
|
|
64
|
-
assert.closeTo(ll.y, testPoint.ll[1], llEPSLN, 'lat is close');
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe('new method 2 param', function () {
|
|
68
|
-
it('shortcut method should work with an array', function () {
|
|
69
|
-
var xy = proj4(testPoint.code, testPoint.ll);
|
|
70
|
-
assert.closeTo(xy[0], testPoint.xy[0], xyEPSLN, 'x is close');
|
|
71
|
-
assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close');
|
|
72
|
-
});
|
|
73
|
-
it('shortcut method should work with an object', function () {
|
|
74
|
-
var pt = {
|
|
75
|
-
x: testPoint.ll[0],
|
|
76
|
-
y: testPoint.ll[1]
|
|
77
|
-
};
|
|
78
|
-
var xy = proj4(testPoint.code, pt);
|
|
79
|
-
assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close');
|
|
80
|
-
assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close');
|
|
81
|
-
});
|
|
82
|
-
it('shortcut method should work with a point object', function () {
|
|
83
|
-
var pt = proj4.toPoint(testPoint.ll);
|
|
84
|
-
var xy = proj4(testPoint.code, pt);
|
|
85
|
-
assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close');
|
|
86
|
-
assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close');
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe('new method 3 param', function () {
|
|
90
|
-
it('shortcut method should work with an array', function () {
|
|
91
|
-
var xy = proj4(proj4.WGS84, testPoint.code, testPoint.ll);
|
|
92
|
-
assert.closeTo(xy[0], testPoint.xy[0], xyEPSLN, 'x is close');
|
|
93
|
-
assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close');
|
|
94
|
-
});
|
|
95
|
-
it('shortcut method should work with an object', function () {
|
|
96
|
-
var pt = {
|
|
97
|
-
x: testPoint.ll[0],
|
|
98
|
-
y: testPoint.ll[1]
|
|
99
|
-
};
|
|
100
|
-
var xy = proj4(proj4.WGS84, testPoint.code, pt);
|
|
101
|
-
assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close');
|
|
102
|
-
assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close');
|
|
103
|
-
});
|
|
104
|
-
it('shortcut method should work with a point object', function () {
|
|
105
|
-
var pt = proj4.toPoint(testPoint.ll);
|
|
106
|
-
var xy = proj4(proj4.WGS84, testPoint.code, pt);
|
|
107
|
-
assert.closeTo(xy.x, testPoint.xy[0], xyEPSLN, 'x is close');
|
|
108
|
-
assert.closeTo(xy.y, testPoint.xy[1], xyEPSLN, 'y is close');
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
describe('new method 3 param other way', function () {
|
|
112
|
-
it('shortcut method should work with an array', function () {
|
|
113
|
-
var ll = proj4(testPoint.code, proj4.WGS84, testPoint.xy);
|
|
114
|
-
assert.closeTo(ll[0], testPoint.ll[0], llEPSLN, 'x is close');
|
|
115
|
-
assert.closeTo(ll[1], testPoint.ll[1], llEPSLN, 'y is close');
|
|
116
|
-
});
|
|
117
|
-
it('shortcut method should work with an object', function () {
|
|
118
|
-
var pt = {
|
|
119
|
-
x: testPoint.xy[0],
|
|
120
|
-
y: testPoint.xy[1]
|
|
121
|
-
};
|
|
122
|
-
// in case of geocentric proj we need Z value.
|
|
123
|
-
if (typeof testPoint.xy[2] === 'number') {
|
|
124
|
-
pt.z = testPoint.xy[2];
|
|
125
|
-
}
|
|
126
|
-
var ll = proj4(testPoint.code, proj4.WGS84, pt);
|
|
127
|
-
assert.closeTo(ll.x, testPoint.ll[0], llEPSLN, 'x is close');
|
|
128
|
-
assert.closeTo(ll.y, testPoint.ll[1], llEPSLN, 'y is close');
|
|
129
|
-
});
|
|
130
|
-
it('shortcut method should work with a point object', function () {
|
|
131
|
-
var pt = proj4.toPoint(testPoint.xy);
|
|
132
|
-
var ll = proj4(testPoint.code, proj4.WGS84, pt);
|
|
133
|
-
assert.closeTo(ll.x, testPoint.ll[0], llEPSLN, 'x is close');
|
|
134
|
-
assert.closeTo(ll.y, testPoint.ll[1], llEPSLN, 'y is close');
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
describe('1 param', function () {
|
|
138
|
-
it('forwards', function () {
|
|
139
|
-
var xy = proj4(testPoint.code).forward(testPoint.ll);
|
|
140
|
-
assert.closeTo(xy[0], testPoint.xy[0], xyEPSLN, 'x is close');
|
|
141
|
-
assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close');
|
|
142
|
-
});
|
|
143
|
-
it('inverse', function () {
|
|
144
|
-
var ll = proj4(testPoint.code).inverse(testPoint.xy);
|
|
145
|
-
assert.closeTo(ll[0], testPoint.ll[0], llEPSLN, 'x is close');
|
|
146
|
-
assert.closeTo(ll[1], testPoint.ll[1], llEPSLN, 'y is close');
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
describe('proj object', function () {
|
|
150
|
-
it('should work with a 2 element array', function () {
|
|
151
|
-
const ll = [testPoint.ll[0], testPoint.ll[1]];
|
|
152
|
-
Object.freeze(ll);
|
|
153
|
-
var xy = proj4(new proj4.Proj(testPoint.code), ll);
|
|
154
|
-
assert.closeTo(xy[0], testPoint.xy[0], xyEPSLN, 'x is close');
|
|
155
|
-
assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close');
|
|
156
|
-
});
|
|
157
|
-
it('should work with a 3 element array', function () {
|
|
158
|
-
const llz = [testPoint.ll[0], testPoint.ll[1], 0];
|
|
159
|
-
Object.freeze(llz);
|
|
160
|
-
var xy = proj4(new proj4.Proj(testPoint.code), llz);
|
|
161
|
-
assert.closeTo(xy[0], testPoint.xy[0], xyEPSLN, 'x is close');
|
|
162
|
-
assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close');
|
|
163
|
-
});
|
|
164
|
-
it('should work on element', function () {
|
|
165
|
-
var xy = proj4(new proj4.Proj(testPoint.code)).forward(testPoint.ll);
|
|
166
|
-
assert.closeTo(xy[0], testPoint.xy[0], xyEPSLN, 'x is close');
|
|
167
|
-
assert.closeTo(xy[1], testPoint.xy[1], xyEPSLN, 'y is close');
|
|
168
|
-
});
|
|
169
|
-
it('should work 3 element point object', function () {
|
|
170
|
-
var pt = proj4.toPoint(testPoint.xy);
|
|
171
|
-
var ll = proj4(new proj4.Proj(testPoint.code), proj4.WGS84, pt);
|
|
172
|
-
assert.closeTo(ll.x, testPoint.ll[0], llEPSLN, 'x is close');
|
|
173
|
-
assert.closeTo(ll.y, testPoint.ll[1], llEPSLN, 'y is close');
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
describe('proj coord object', function () {
|
|
177
|
-
it('should not be modified', function () {
|
|
178
|
-
var expected = { x: 100000, y: 100000 };
|
|
179
|
-
var inpxy = { x: expected.x, y: expected.y };
|
|
180
|
-
proj4('EPSG:3857', proj4.WGS84, inpxy);
|
|
181
|
-
|
|
182
|
-
assert.deepEqual(inpxy, expected, 'input is unmodified');
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
describe('points', function () {
|
|
189
|
-
it('should not create a z if none was provided', function () {
|
|
190
|
-
const result = proj4(
|
|
191
|
-
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]',
|
|
192
|
-
'PROJCS["OSGB 1936 / British National Grid",GEOGCS["OSGB 1936",DATUM["OSGB_1936",SPHEROID["Airy 1830",6377563.396,299.3249646,AUTHORITY["EPSG","7001"]],AUTHORITY["EPSG","6277"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4277"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",49],PARAMETER["central_meridian",-2],PARAMETER["scale_factor",0.9996012717],PARAMETER["false_easting",400000],PARAMETER["false_northing",-100000],AUTHORITY["EPSG","27700"],AXIS["Easting",EAST],AXIS["Northing",NORTH]]',
|
|
193
|
-
{ x: -0.12793738, y: 51.507747 });
|
|
194
|
-
assert.closeTo(result.x, 530018.229301635, 1e-6);
|
|
195
|
-
assert.closeTo(result.y, 180418.4380560551, 1e-6);
|
|
196
|
-
assert.equal(result.z, undefined);
|
|
197
|
-
});
|
|
198
|
-
it('should return null for transform of [0, 0] for EPSG:3413 -> EPSG:3857', function () {
|
|
199
|
-
var point = proj4.transform(
|
|
200
|
-
proj4.Proj('+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs'),
|
|
201
|
-
proj4.Proj('EPSG:3857'),
|
|
202
|
-
[0, 0]
|
|
203
|
-
);
|
|
204
|
-
assert.strictEqual(point, null);
|
|
205
|
-
});
|
|
206
|
-
it('should ignore stuff it does not know', function () {
|
|
207
|
-
var sweref99tm = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
|
|
208
|
-
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';
|
|
209
|
-
var rslt = proj4(sweref99tm, rt90).forward({
|
|
210
|
-
x: 319180,
|
|
211
|
-
y: 6399862,
|
|
212
|
-
z: 0,
|
|
213
|
-
m: 1000,
|
|
214
|
-
method: function () {
|
|
215
|
-
return 'correct answer';
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
assert.closeTo(rslt.x, 1271137.927561178, 0.000001);
|
|
219
|
-
assert.closeTo(rslt.y, 6404230.291456626, 0.000001);
|
|
220
|
-
assert.equal(rslt.z, 0);
|
|
221
|
-
assert.equal(rslt.m, 1000);
|
|
222
|
-
assert.equal(rslt.method(), 'correct answer');
|
|
223
|
-
});
|
|
224
|
-
it('should be able to compute X Y Z M in geocenteric coordinates', function () {
|
|
225
|
-
var epsg4978 = '+proj=geocent +datum=WGS84 +units=m +no_defs';
|
|
226
|
-
var rslt = proj4(epsg4978).forward({
|
|
227
|
-
x: -7.76166,
|
|
228
|
-
y: 39.19685,
|
|
229
|
-
z: 0,
|
|
230
|
-
m: 1000,
|
|
231
|
-
method: function () {
|
|
232
|
-
return 'correct answer';
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
assert.closeTo(rslt.x, 4904199.584207411, 0.000001);
|
|
236
|
-
assert.closeTo(rslt.y, -668448.8153664203, 0.000001);
|
|
237
|
-
assert.closeTo(rslt.z, 4009276.930771821, 0.000001);
|
|
238
|
-
assert.equal(rslt.m, 1000);
|
|
239
|
-
assert.equal(rslt.method(), 'correct answer');
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
describe('points array', function () {
|
|
243
|
-
it('should ignore stuff it does not know', function () {
|
|
244
|
-
var sweref99tm = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
|
|
245
|
-
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';
|
|
246
|
-
var rslt = proj4(sweref99tm, rt90).forward([
|
|
247
|
-
319180,
|
|
248
|
-
6399862,
|
|
249
|
-
0,
|
|
250
|
-
1000
|
|
251
|
-
]);
|
|
252
|
-
assert.closeTo(rslt[0], 1271137.927561178, 0.000001);
|
|
253
|
-
assert.closeTo(rslt[1], 6404230.291456626, 0.000001);
|
|
254
|
-
assert.equal(rslt[2], 0);
|
|
255
|
-
assert.equal(rslt[3], 1000);
|
|
256
|
-
});
|
|
257
|
-
it('should be able to compute X Y Z M in geocenteric coordinates', function () {
|
|
258
|
-
var epsg4978 = '+proj=geocent +datum=WGS84 +units=m +no_defs';
|
|
259
|
-
var rslt = proj4(epsg4978).forward([
|
|
260
|
-
-7.76166,
|
|
261
|
-
39.19685,
|
|
262
|
-
0,
|
|
263
|
-
1000
|
|
264
|
-
]);
|
|
265
|
-
assert.closeTo(rslt[0], 4904199.584207411, 0.000001);
|
|
266
|
-
assert.closeTo(rslt[1], -668448.8153664203, 0.000001);
|
|
267
|
-
assert.closeTo(rslt[2], 4009276.930771821, 0.000001);
|
|
268
|
-
assert.equal(rslt[3], 1000);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('should use [x,y] axis order', function () {
|
|
273
|
-
var enu = '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","9802"]], PARAMETER["central_meridian", -71.5], PARAMETER["latitude_of_origin", 41.0], PARAMETER["standard_parallel_1", 42.68333333333334], PARAMETER["false_easting", 200000.0], PARAMETER["false_northing", 750000.0], PARAMETER["scale_factor", 1.0], PARAMETER["standard_parallel_2", 41.71666666666667], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","26986"]]';
|
|
274
|
-
var neu = 'PROJCS["NAD83 / Massachusetts Mainland NE", 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 latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4269"]], PROJECTION["Lambert_Conformal_Conic_2SP", AUTHORITY["EPSG","9802"]], PARAMETER["central_meridian", -71.5], PARAMETER["latitude_of_origin", 41.0], PARAMETER["standard_parallel_1", 42.68333333333334], PARAMETER["false_easting", 200000.0], PARAMETER["false_northing", 750000.0], PARAMETER["scale_factor", 1.0], PARAMETER["standard_parallel_2", 41.71666666666667], UNIT["m", 1.0], AXIS["Northing", NORTH], AXIS["Easting", EAST], AUTHORITY["EPSG","26986"]]';
|
|
275
|
-
var rslt = proj4(enu, neu).forward({
|
|
276
|
-
x: 10.2,
|
|
277
|
-
y: 43.4
|
|
278
|
-
});
|
|
279
|
-
assert.closeTo(rslt.x, 10.2, 0.000001);
|
|
280
|
-
assert.closeTo(rslt.y, 43.4, 0.000001);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it('should use correct axis order with proj4.transform()', function () {
|
|
284
|
-
var enu = '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","9802"]], PARAMETER["central_meridian", -71.5], PARAMETER["latitude_of_origin", 41.0], PARAMETER["standard_parallel_1", 42.68333333333334], PARAMETER["false_easting", 200000.0], PARAMETER["false_northing", 750000.0], PARAMETER["scale_factor", 1.0], PARAMETER["standard_parallel_2", 41.71666666666667], UNIT["m", 1.0], AXIS["Easting", EAST], AXIS["Northing", NORTH], AUTHORITY["EPSG","26986"]]';
|
|
285
|
-
var neu = 'PROJCS["NAD83 / Massachusetts Mainland NE", 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 latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4269"]], PROJECTION["Lambert_Conformal_Conic_2SP", AUTHORITY["EPSG","9802"]], PARAMETER["central_meridian", -71.5], PARAMETER["latitude_of_origin", 41.0], PARAMETER["standard_parallel_1", 42.68333333333334], PARAMETER["false_easting", 200000.0], PARAMETER["false_northing", 750000.0], PARAMETER["scale_factor", 1.0], PARAMETER["standard_parallel_2", 41.71666666666667], UNIT["m", 1.0], AXIS["Northing", NORTH], AXIS["Easting", EAST], AUTHORITY["EPSG","26986"]]';
|
|
286
|
-
var rslt = proj4(enu, neu).forward({
|
|
287
|
-
x: 10.2,
|
|
288
|
-
y: 43.4
|
|
289
|
-
}, true);
|
|
290
|
-
assert.closeTo(rslt.x, 43.4, 0.000001);
|
|
291
|
-
assert.closeTo(rslt.y, 10.2, 0.000001);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('axes should be invertable with proj4.transform()', function () {
|
|
295
|
-
var enu = '+proj=longlat +axis=enu';
|
|
296
|
-
var esu = '+proj=longlat +axis=esu';
|
|
297
|
-
var wnu = '+proj=longlat +axis=wnu';
|
|
298
|
-
var result = proj4(enu, esu).forward({ x: 40, y: 50 }, true);
|
|
299
|
-
assert.closeTo(result.x, 40, 0.000001);
|
|
300
|
-
assert.closeTo(result.y, -50, 0.000001);
|
|
301
|
-
var result = proj4(enu, wnu).forward({ x: 40, y: 50 }, true);
|
|
302
|
-
assert.closeTo(result.x, -40, 0.000001);
|
|
303
|
-
assert.closeTo(result.y, 50, 0.000001);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
describe('defs', function () {
|
|
307
|
-
assert.equal(proj4.defs('testmerc'), proj4.defs['testmerc']);
|
|
308
|
-
proj4.defs('foo', '+proj=merc +lon_0=5.937 +lat_ts=45.027 +ellps=sphere');
|
|
309
|
-
assert.typeOf(proj4.defs['foo'], 'object');
|
|
310
|
-
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
|
|
311
|
-
assert.strictEqual(proj4.defs['urn:x-ogc:def:crs:EPSG:4326'], proj4.defs['EPSG:4326']);
|
|
312
|
-
|
|
313
|
-
describe('wkt', function () {
|
|
314
|
-
it('should provide the correct conversion factor for WKT GEOGCS projections', function () {
|
|
315
|
-
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"]]');
|
|
316
|
-
assert.equal(proj4.defs['EPSG:4269'].to_meter, 6378137 * 0.01745329251994328);
|
|
317
|
-
|
|
318
|
-
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"]]');
|
|
319
|
-
assert.equal(proj4.defs['EPSG:4279'].to_meter, 6377563.396 * 0.01745329251994328);
|
|
320
|
-
});
|
|
321
|
-
it('should parse wkt and proj4 of the same crs and result in the same params', function () {
|
|
322
|
-
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"]]';
|
|
323
|
-
var s2 = '+proj=longlat +ellps=clrk80 +towgs84=-180.624,-225.516,173.919,-0.81,-1.898,8.336,16.7101 +no_defs';
|
|
324
|
-
var crs1 = proj4(s1);
|
|
325
|
-
var crs2 = proj4(s2);
|
|
326
|
-
assert.equal(crs1.oProj.a, crs2.oProj.a);
|
|
327
|
-
// proj4 has different ellipsoid parameters that EPSG: http://epsg.io/4134
|
|
328
|
-
// assert.equal(crs1.oProj.b, crs2.oProj.b);
|
|
329
|
-
});
|
|
330
|
-
it('should handled defined points correctly', function () {
|
|
331
|
-
var prj = '+proj=utm +zone=31';
|
|
332
|
-
var proj = proj4(prj);
|
|
333
|
-
var res = proj.forward([3, 0]);
|
|
334
|
-
assert.deepEqual(res, [500000, 0]);
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
describe('errors', function () {
|
|
339
|
-
it('should throw an error for an unknown ref', function () {
|
|
340
|
-
assert.throws(function () {
|
|
341
|
-
new proj4.Proj('fake one');
|
|
342
|
-
}, 'fake one', 'should work');
|
|
343
|
-
});
|
|
344
|
-
it('should throw when passed null', function () {
|
|
345
|
-
assert.throws(function () {
|
|
346
|
-
proj4('+proj=utm +zone=31', [null, 0]);
|
|
347
|
-
}, 'coordinates must be finite numbers', 'should work');
|
|
348
|
-
});
|
|
349
|
-
it('should throw when passed NaN', function () {
|
|
350
|
-
assert.throws(function () {
|
|
351
|
-
proj4('+proj=utm +zone=31', [0, NaN]);
|
|
352
|
-
}, 'coordinates must be finite numbers', 'should work');
|
|
353
|
-
});
|
|
354
|
-
it('should throw when passed Infinity', function () {
|
|
355
|
-
assert.throws(function () {
|
|
356
|
-
proj4('+proj=utm +zone=31', [Infinity, 0]);
|
|
357
|
-
}, 'coordinates must be finite numbers', 'should work');
|
|
358
|
-
});
|
|
359
|
-
it('should throw when passed -Infinity', function () {
|
|
360
|
-
assert.throws(function () {
|
|
361
|
-
proj4('+proj=utm +zone=31', [-Infinity, 0]);
|
|
362
|
-
}, 'coordinates must be finite numbers', 'should work');
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
describe('utility', function () {
|
|
366
|
-
it('should have MGRS available in the proj4.util namespace', function () {
|
|
367
|
-
assert.typeOf(proj4.mgrs, 'object', 'MGRS available in the proj4.util namespace');
|
|
368
|
-
});
|
|
369
|
-
it('should have fromMGRS method added to proj4.Point prototype', function () {
|
|
370
|
-
assert.typeOf(proj4.Point.fromMGRS, 'function', 'fromMGRS method added to proj4.Point prototype');
|
|
371
|
-
});
|
|
372
|
-
it('should have toMGRS method added to proj4.Point prototype', function () {
|
|
373
|
-
assert.typeOf(proj4.Point.prototype.toMGRS, 'function', 'toMGRS method added to proj4.Point prototype');
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
describe('First MGRS set', function () {
|
|
377
|
-
var mgrs = '33UXP04';
|
|
378
|
-
var point = proj4.Point.fromMGRS(mgrs);
|
|
379
|
-
it('Longitude of point from MGRS correct.', function () {
|
|
380
|
-
assert.equal(point.x.toPrecision(7), '16.41450', 'Longitude of point from MGRS correct.');
|
|
381
|
-
});
|
|
382
|
-
it('Latitude of point from MGRS correct.', function () {
|
|
383
|
-
assert.equal(point.y.toPrecision(7), '48.24949', 'Latitude of point from MGRS correct.');
|
|
384
|
-
});
|
|
385
|
-
it('MGRS reference with highest accuracy correct.', function () {
|
|
386
|
-
assert.equal(point.toMGRS(), '33UXP0500444998', 'MGRS reference with highest accuracy correct.');
|
|
387
|
-
});
|
|
388
|
-
it('MGRS reference with 1-digit accuracy correct.', function () {
|
|
389
|
-
assert.equal(point.toMGRS(1), mgrs, 'MGRS reference with 1-digit accuracy correct.');
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
describe('Second MGRS set', function () {
|
|
393
|
-
var mgrs = '24XWT783908'; // near UTM zone border, so there are two ways to reference this
|
|
394
|
-
var point = proj4.Point.fromMGRS(mgrs);
|
|
395
|
-
it('Longitude of point from MGRS correct.', function () {
|
|
396
|
-
assert.equal(point.x.toPrecision(7), '-32.66433', 'Longitude of point from MGRS correct.');
|
|
397
|
-
});
|
|
398
|
-
it('Latitude of point from MGRS correct.', function () {
|
|
399
|
-
assert.equal(point.y.toPrecision(7), '83.62778', 'Latitude of point from MGRS correct.');
|
|
400
|
-
});
|
|
401
|
-
it('MGRS reference with 3-digit accuracy correct.', function () {
|
|
402
|
-
assert.equal(point.toMGRS(3), '25XEN041865', 'MGRS reference with 3-digit accuracy correct.');
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
describe('Defs and Datum definition', function () {
|
|
406
|
-
proj4.defs('EPSG:5514', '+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +pm=greenwich +units=m +no_defs +towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56');
|
|
407
|
-
var point = proj4.transform(proj4.Proj('WGS84'), proj4.Proj('EPSG:5514'),
|
|
408
|
-
proj4.toPoint([12.806988, 49.452262]));
|
|
409
|
-
it('Longitude of point from WGS84 correct.', function () {
|
|
410
|
-
assert.equal(point.x.toPrecision(8), '-868208.61', 'Longitude of point from WGS84 correct.');
|
|
411
|
-
});
|
|
412
|
-
it('Latitude of point from WGS84 correct.', function () {
|
|
413
|
-
assert.equal(point.y.toPrecision(9), '-1095793.64', 'Latitude of point from WGS84 correct.');
|
|
414
|
-
});
|
|
415
|
-
var point2 = proj4.transform(proj4.Proj('WGS84'), proj4.Proj('EPSG:5514'),
|
|
416
|
-
proj4.toPoint([12.806988, 49.452262]));
|
|
417
|
-
it('Longitude of point from WGS84 with second call for EPSG:5514 correct.', function () {
|
|
418
|
-
assert.equal(point2.x.toPrecision(8), '-868208.61', 'Longitude of point from WGS84 correct.');
|
|
419
|
-
});
|
|
420
|
-
it('Latitude of point from WGS84 with second call for EPSG:5514 correct.', function () {
|
|
421
|
-
assert.equal(point2.y.toPrecision(9), '-1095793.64', 'Latitude of point from WGS84 correct.');
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
describe('Nadgrids BETA2007', function () {
|
|
427
|
-
var tests = [
|
|
428
|
-
['EPSG:31466', 'EPSG:4326', 2559552, 5670982, 6.850861772, 51.170707759, 0.0000001, 0.01],
|
|
429
|
-
['EPSG:31466', 'EPSG:3857', 2559552, 5670982, 762634.443931574, 6651545.680265270, 0.01, 0.01],
|
|
430
|
-
['EPSG:31466', 'EPSG:25832', 2559552, 5670982, 349757.381712518, 5671004.065049540, 0.01, 0.01]
|
|
431
|
-
];
|
|
432
|
-
|
|
433
|
-
function initializeNadgrid(buffer) {
|
|
434
|
-
proj4.nadgrid('BETA2007.gsb', buffer);
|
|
435
|
-
proj4.defs('EPSG:31466', '+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +nadgrids=BETA2007.gsb +units=m +no_defs +type=crs');
|
|
436
|
-
proj4.defs('EPSG:25832', '+proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs');
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
before(function (done) {
|
|
440
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
|
441
|
-
const xhr = new XMLHttpRequest();
|
|
442
|
-
xhr.open('GET', 'BETA2007.gsb', true);
|
|
443
|
-
xhr.responseType = 'arraybuffer';
|
|
444
|
-
xhr.addEventListener('load', function () {
|
|
445
|
-
initializeNadgrid(xhr.response);
|
|
446
|
-
done();
|
|
447
|
-
});
|
|
448
|
-
xhr.addEventListener('error', done);
|
|
449
|
-
xhr.send();
|
|
450
|
-
} else if (typeof require === 'function') {
|
|
451
|
-
const fs = require('fs');
|
|
452
|
-
const path = require('path');
|
|
453
|
-
fs.readFile(path.join(__dirname, 'BETA2007.gsb'), function (err, data) {
|
|
454
|
-
if (err) {
|
|
455
|
-
done(err);
|
|
456
|
-
} else {
|
|
457
|
-
initializeNadgrid(data.buffer);
|
|
458
|
-
done();
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
tests.forEach(function (test) {
|
|
465
|
-
var fromProj = test[0];
|
|
466
|
-
var toProj = test[1];
|
|
467
|
-
var fromX = test[2];
|
|
468
|
-
var fromY = test[3];
|
|
469
|
-
var toX = test[4];
|
|
470
|
-
var toY = test[5];
|
|
471
|
-
var fromPrecision = test[6];
|
|
472
|
-
var toPrecision = test[7];
|
|
473
|
-
it('should transform ' + fromProj + ' to ' + toProj, function () {
|
|
474
|
-
var transformed = proj4(fromProj, toProj, [fromX, fromY]);
|
|
475
|
-
assert.approximately(transformed[0], toX, fromPrecision);
|
|
476
|
-
assert.approximately(transformed[1], toY, fromPrecision);
|
|
477
|
-
});
|
|
478
|
-
it('should transform ' + toProj + ' to ' + fromProj, function () {
|
|
479
|
-
var transformed = proj4(toProj, fromProj, [toX, toY]);
|
|
480
|
-
assert.approximately(transformed[0], fromX, toPrecision);
|
|
481
|
-
assert.approximately(transformed[1], fromY, toPrecision);
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
describe('Nadgrids ntv2', function () {
|
|
487
|
-
var tests = [
|
|
488
|
-
[-44.382211538462, 40.3768, -44.380749, 40.377457], // just inside the lower limit
|
|
489
|
-
[-87.617788, 59.623262, -87.617659, 59.623441], // just inside the upper limit
|
|
490
|
-
[-44.5, 40.5, -44.498553, 40.500632], // inside the first square
|
|
491
|
-
[-60, 50, -59.999192, 50.000058], // a general point towards the middle of the grid
|
|
492
|
-
[0, 0, 0, 0] // fall back to null
|
|
493
|
-
];
|
|
494
|
-
|
|
495
|
-
var converter;
|
|
496
|
-
|
|
497
|
-
function initializeNadgrid(buffer) {
|
|
498
|
-
proj4.nadgrid('ntv2', buffer);
|
|
499
|
-
proj4.defs('ntv2_from', '+proj=longlat +ellps=clrk66 +nadgrids=@ignorable,ntv2,null');
|
|
500
|
-
proj4.defs('ntv2_to', '+proj=longlat +datum=WGS84 +no_defs');
|
|
501
|
-
converter = proj4('ntv2_from', 'ntv2_to');
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
before(function (done) {
|
|
505
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
|
506
|
-
const xhr = new XMLHttpRequest();
|
|
507
|
-
xhr.open('GET', 'ntv2_0_downsampled.gsb', true);
|
|
508
|
-
xhr.responseType = 'arraybuffer';
|
|
509
|
-
xhr.addEventListener('load', function () {
|
|
510
|
-
initializeNadgrid(xhr.response);
|
|
511
|
-
done();
|
|
512
|
-
});
|
|
513
|
-
xhr.addEventListener('error', done);
|
|
514
|
-
xhr.send();
|
|
515
|
-
} else if (typeof require === 'function') {
|
|
516
|
-
const fs = require('fs');
|
|
517
|
-
const path = require('path');
|
|
518
|
-
fs.readFile(path.join(__dirname, 'ntv2_0_downsampled.gsb'), function (err, data) {
|
|
519
|
-
if (err) {
|
|
520
|
-
done(err);
|
|
521
|
-
} else {
|
|
522
|
-
initializeNadgrid(data.buffer);
|
|
523
|
-
done();
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
tests.forEach(function (test) {
|
|
530
|
-
var fromLng = test[0];
|
|
531
|
-
var fromLat = test[1];
|
|
532
|
-
var toLng = test[2];
|
|
533
|
-
var toLat = test[3];
|
|
534
|
-
it('should interpolate ' + [fromLng, fromLat] + ' to ' + [toLng, toLat], function () {
|
|
535
|
-
var actual = converter.forward([fromLng, fromLat]);
|
|
536
|
-
assert.approximately(actual[0], toLng, 0.000001);
|
|
537
|
-
assert.approximately(actual[1], toLat, 0.000001);
|
|
538
|
-
});
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
var inverseTests = [
|
|
542
|
-
[-44.5, 40.5, -44.498553, 40.500632],
|
|
543
|
-
[-60, 50, -59.999192, 50.000058]
|
|
544
|
-
];
|
|
545
|
-
|
|
546
|
-
inverseTests.forEach(function (test) {
|
|
547
|
-
var fromLng = test[0];
|
|
548
|
-
var fromLat = test[1];
|
|
549
|
-
var toLng = test[2];
|
|
550
|
-
var toLat = test[3];
|
|
551
|
-
it('should inverse interpolate ' + [toLng, toLat] + ' to ' + [fromLng, fromLat], function () {
|
|
552
|
-
var actual = converter.inverse([toLng, toLat]);
|
|
553
|
-
assert.approximately(actual[0], fromLng, 0.000001);
|
|
554
|
-
assert.approximately(actual[1], fromLat, 0.000001);
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
describe('Nadgrids ntv2 no error columns', function () {
|
|
560
|
-
var tests = [
|
|
561
|
-
[-44.382211538462, 40.3768, -44.380749, 40.377457], // just inside the lower limit
|
|
562
|
-
[-87.617788, 59.623262, -87.617659, 59.623441], // just inside the upper limit
|
|
563
|
-
[-44.5, 40.5, -44.498553, 40.500632], // inside the first square
|
|
564
|
-
[-60, 50, -59.999192, 50.000058], // a general point towards the middle of the grid
|
|
565
|
-
[0, 0, 0, 0] // fall back to null
|
|
566
|
-
];
|
|
567
|
-
|
|
568
|
-
var converter;
|
|
569
|
-
|
|
570
|
-
function initializeNadgrid(buffer) {
|
|
571
|
-
proj4.nadgrid('ntv2', buffer, { includeErrorFields: false });
|
|
572
|
-
proj4.defs('ntv2_from', '+proj=longlat +ellps=clrk66 +nadgrids=@ntv2,null');
|
|
573
|
-
proj4.defs('ntv2_to', '+proj=longlat +datum=WGS84 +no_defs');
|
|
574
|
-
converter = proj4('ntv2_from', 'ntv2_to');
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
before(function (done) {
|
|
578
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
|
579
|
-
const xhr = new XMLHttpRequest();
|
|
580
|
-
xhr.open('GET', 'ntv2_0_downsampled_no_error_columns.gsb', true);
|
|
581
|
-
xhr.responseType = 'arraybuffer';
|
|
582
|
-
xhr.addEventListener('load', function () {
|
|
583
|
-
initializeNadgrid(xhr.response);
|
|
584
|
-
done();
|
|
585
|
-
});
|
|
586
|
-
xhr.addEventListener('error', done);
|
|
587
|
-
xhr.send();
|
|
588
|
-
} else if (typeof require === 'function') {
|
|
589
|
-
const fs = require('fs');
|
|
590
|
-
const path = require('path');
|
|
591
|
-
fs.readFile(path.join(__dirname, 'ntv2_0_downsampled_no_error_columns.gsb'), function (err, data) {
|
|
592
|
-
if (err) {
|
|
593
|
-
done(err);
|
|
594
|
-
} else {
|
|
595
|
-
initializeNadgrid(data.buffer);
|
|
596
|
-
done();
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
tests.forEach(function (test) {
|
|
603
|
-
var fromLng = test[0];
|
|
604
|
-
var fromLat = test[1];
|
|
605
|
-
var toLng = test[2];
|
|
606
|
-
var toLat = test[3];
|
|
607
|
-
it('should interpolate ' + [fromLng, fromLat] + ' to ' + [toLng, toLat], function () {
|
|
608
|
-
var actual = converter.forward([fromLng, fromLat]);
|
|
609
|
-
assert.approximately(actual[0], toLng, 0.000001);
|
|
610
|
-
assert.approximately(actual[1], toLat, 0.000001);
|
|
611
|
-
});
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
var inverseTests = [
|
|
615
|
-
[-44.5, 40.5, -44.498553, 40.500632],
|
|
616
|
-
[-60, 50, -59.999192, 50.000058]
|
|
617
|
-
];
|
|
618
|
-
|
|
619
|
-
inverseTests.forEach(function (test) {
|
|
620
|
-
var fromLng = test[0];
|
|
621
|
-
var fromLat = test[1];
|
|
622
|
-
var toLng = test[2];
|
|
623
|
-
var toLat = test[3];
|
|
624
|
-
it('should inverse interpolate ' + [toLng, toLat] + ' to ' + [fromLng, fromLat], function () {
|
|
625
|
-
var actual = converter.inverse([toLng, toLat]);
|
|
626
|
-
assert.approximately(actual[0], fromLng, 0.000001);
|
|
627
|
-
assert.approximately(actual[1], fromLat, 0.000001);
|
|
628
|
-
});
|
|
629
|
-
});
|
|
630
|
-
});
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
if (typeof module !== 'undefined') {
|
|
634
|
-
module.exports = startTests;
|
|
635
|
-
} else if (typeof define === 'function') {
|
|
636
|
-
define(function () {
|
|
637
|
-
return startTests;
|
|
638
|
-
});
|
|
639
|
-
}
|