forked from mapnik/node-mapnik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource.test.js
135 lines (121 loc) · 3.66 KB
/
datasource.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
var mapnik = require('mapnik');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
exports['test datasource creation'] = function() {
assert.throws(function() { mapnik.Datasource('foo'); });
assert.throws(function() { mapnik.Datasource({ 'foo': 1 }); });
assert.throws(function() { mapnik.Datasource({ 'type': 'foo' }); });
assert.throws(function() { mapnik.Datasource({ 'type': 'shape' }); });
assert.throws(function() { new mapnik.Datasource('foo'); },
/must provide an object, eg {type: 'shape', file : 'world.shp'}/);
assert.throws(function() { new mapnik.Datasource({ 'foo': 1 }); },
/Could not create datasource. Required parameter 'type' is missing/);
assert.throws(function() { new mapnik.Datasource({ 'type': 'foo' }); },
/Could not create datasource. No plugin found for type 'foo'/);
assert.throws(function() { new mapnik.Datasource({ 'type': 'shape' }); },
/Shape Plugin: missing <file> parameter/);
};
exports['test datasource'] = function() {
var options = {
type: 'shape',
file: './examples/data/world_merc.shp'
};
var ds = new mapnik.Datasource(options);
assert.ok(ds);
assert.deepEqual(ds.parameters(), options);
var features = ds.features();
assert.equal(features.length, 245);
assert.deepEqual(features[244], {
AREA: 1638094,
FIPS: 'RS',
ISO2: 'RU',
ISO3: 'RUS',
LAT: 61.988,
LON: 96.689,
NAME: 'Russia',
POP2005: 143953092,
REGION: 150,
SUBREGION: 151,
UN: 643,
__id__: 245
});
assert.deepEqual(ds.describe(), {
type: 'vector',
extent: [
-20037508.342789248,
-8283343.693882697,
20037508.342789244,
18365151.363070473
],
encoding: 'utf-8',
fields: {
FIPS: 'String',
ISO2: 'String',
ISO3: 'String',
UN: 'Number',
NAME: 'String',
AREA: 'Number',
POP2005: 'Number',
REGION: 'Number',
SUBREGION: 'Number',
LON: 'Number',
LAT: 'Number'
},
geometry_type: 'polygon',
has_features: true
});
};
exports['test JSON datasource'] = function() {
// same datasource but from json file (originally converted with ogr2ogr)
var options = {
type: 'ogr',
file: './examples/data/world_merc.json',
layer_by_index: 0
};
var ds = new mapnik.Datasource(options);
var ds = new mapnik.Datasource(options);
assert.ok(ds);
assert.deepEqual(ds.parameters(), options);
var features = ds.features();
assert.equal(features.length, 245);
assert.deepEqual(features[244], {
AREA: 1638094,
FIPS: 'RS',
ISO2: 'RU',
ISO3: 'RUS',
LAT: 61.988,
LON: 96.689,
NAME: 'Russia',
POP2005: 143953092,
REGION: 150,
SUBREGION: 151,
UN: 643,
__id__: 245
});
assert.deepEqual(ds.describe(), {
type: 'vector',
extent: [
-20037508.342789,
-8283343.693883,
20037508.342789,
18365151.36307
],
encoding: 'utf-8',
fields: {
FIPS: 'String',
ISO2: 'String',
ISO3: 'String',
UN: 'Number',
NAME: 'String',
AREA: 'Number',
POP2005: 'Number',
REGION: 'Number',
SUBREGION: 'Number',
LON: 'Number',
LAT: 'Number'
},
geometry_type: 'polygon',
has_features: true
});
};