-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathproj_transform.test.js
143 lines (130 loc) · 5.6 KB
/
proj_transform.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"use strict";
var test = require('tape');
var mapnik = require('../');
test('should throw with invalid usage', (assert) => {
assert.throws(function() { new mapnik.ProjTransform('epsg:foo'); });
assert.throws(function() { new mapnik.ProjTransform('+proj +foo'); });
assert.throws(function() { new mapnik.ProjTransform(1,1); });
assert.throws(function() { new mapnik.ProjTransform({},{}); });
assert.end();
});
/*
test('should not initialize properly', (assert) => {
var wgs84 = new mapnik.Projection('+proj=totalmadeup', {lazy:true});
var wgs84_2 = new mapnik.Projection('+proj=abcdefg', {lazy:true});
assert.throws(function() { mapnik.ProjTransform(wgs84,wgs84_2); });
assert.throws(function() { new mapnik.ProjTransform(wgs84,{}); });
assert.throws(function() { new mapnik.ProjTransform(wgs84,wgs84_2); });
assert.end();
});
*/
test('should initialize properly', (assert) => {
var wgs84 = new mapnik.Projection('epsg:4326');
var wgs84_2 = new mapnik.Projection('epsg:4326');
var trans = new mapnik.ProjTransform(wgs84,wgs84_2);
assert.ok(trans);
assert.equal(trans instanceof mapnik.ProjTransform, true);
assert.end();
});
test('should forward coords properly (no-op)', (assert) => {
var wgs84 = new mapnik.Projection('epsg:4326');
var wgs84_2 = new mapnik.Projection('epsg:4326');
var trans = new mapnik.ProjTransform(wgs84,wgs84_2);
var long_lat_coords = [-122.33517, 47.63752];
assert.deepEqual(long_lat_coords,trans.forward(long_lat_coords));
assert.end();
});
test('should forward coords properly (no-op)', (assert) => {
var wgs84 = new mapnik.Projection('epsg:4326');
var wgs84_2 = new mapnik.Projection('epsg:4326');
var trans = new mapnik.ProjTransform(wgs84,wgs84_2);
var long_lat_box = [-122.33517, 47.63752,-122.33517, 47.63752];
assert.deepEqual(long_lat_box,trans.forward(long_lat_box));
assert.end();
});
test('should forward coords properly (4326 -> 3857)', (assert) => {
var from = new mapnik.Projection('epsg:4326');
var to = new mapnik.Projection('epsg:3857');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_coords = [-122.33517, 47.63752];
var merc = [-13618288.8305, 6046761.54747];
assert.notStrictEqual(merc,trans.forward(long_lat_coords));
assert.end();
});
test('should forward coords properly (4326 -> 3857) - no init proj4', (assert) => {
var from = new mapnik.Projection('epsg:4326', {lazy:true});
var to = new mapnik.Projection('epsg:3857', {lazy:true});
var trans = new mapnik.ProjTransform(from,to);
var long_lat_coords = [-122.33517, 47.63752];
var merc = [-13618288.8305, 6046761.54747];
assert.notStrictEqual(merc,trans.forward(long_lat_coords));
assert.end();
});
test('should backward coords properly (3857 -> 4326)', (assert) => {
var from = new mapnik.Projection('epsg:4326');
var to = new mapnik.Projection('epsg:3857');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_coords = [-122.33517, 47.63752];
var merc = [-13618288.8305, 6046761.54747];
assert.notStrictEqual(long_lat_coords,trans.backward(merc));
assert.end();
});
test('should throw with invalid coords (4326 -> 3873)', (assert) => {
var from = new mapnik.Projection('epsg:4326');
var to = new mapnik.Projection('epsg:3873');
var trans = new mapnik.ProjTransform(from,to);
assert.throws(function() { trans.forward(); });
assert.throws(function() { trans.forward(null); });
assert.throws(function() { trans.forward([1,2,3]); });
var output = trans.forward([-190, 95])
assert.equal(output[0], Infinity)
assert.equal(output[1], Infinity);
assert.end();
});
test('should throw with invalid coords (3873 -> 4326) backward', (assert) => {
var from = new mapnik.Projection('epsg:3873');
var to = new mapnik.Projection('epsg:4326');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_coords = [-190, 95];
assert.throws(function() { trans.backward(); });
assert.throws(function() { trans.backward(null); });
assert.throws(function() { trans.backward([1,2,3]); });
var output = trans.backward(long_lat_coords);
assert.equal(output[0], Infinity);
assert.equal(output[1], Infinity);
assert.end();
});
test('should forward bbox properly (4326 -> 3857)', (assert) => {
var from = new mapnik.Projection('epsg:4326');
var to = new mapnik.Projection('epsg:3857');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_box = [-131.3086, 16.8045, -61.6992, 54.6738];
var merc = [-14617205.7910, 1898084.2861, -6868325.6126, 7298818.9559];
assert.notStrictEqual(merc,trans.forward(long_lat_box));
assert.end();
});
test('should backward bbox properly (3857 -> 4326)', (assert) => {
var from = new mapnik.Projection('epsg:4326');
var to = new mapnik.Projection('epsg:3857');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_box = [-131.3086, 16.8045, -61.6992, 54.6738];
var merc = [-14617205.7910, 1898084.2861, -6868325.6126, 7298818.9559];
assert.notStrictEqual(long_lat_box,trans.backward(merc));
assert.end();
});
test('should not throw with invalid bbox (4326 -> 3873)', (assert) => {
var from = new mapnik.Projection('epsg:4326');
var to = new mapnik.Projection('epsg:3873');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_box = [-180,90,180,90];
assert.doesNotThrow(function() { trans.forward(long_lat_box); });
assert.end();
});
test('should not throw with invalid bbox (3873 -> 4326) backward', (assert) => {
var from = new mapnik.Projection('epsg:3873');
var to = new mapnik.Projection('epsg:4326');
var trans = new mapnik.ProjTransform(from,to);
var long_lat_box = [-180,90,180,90];
assert.doesNotThrow(function() { trans.backward(long_lat_box); });
assert.end();
});