-
Notifications
You must be signed in to change notification settings - Fork 165
/
shp2geojson.test.js
33 lines (30 loc) · 1.08 KB
/
shp2geojson.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
"use strict";
var test = require('tape');
var mapnik = require('../');
var fs = require('fs');
var path = require('path');
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'shape.input'));
test('should convert shapefile', (assert) => {
if (process.versions.node.split('.')[1] !== '6') {
var ds = new mapnik.Datasource({type:'shape',file:'test/data/world_merc.shp'});
var featureset = ds.featureset();
var geojson = {
"type": "FeatureCollection",
"features": [
]
};
var feat = featureset.next();
while (feat) {
geojson.features.push(JSON.parse(feat.toJSON()));
feat = featureset.next();
}
var actual = './test/tmp/world_merc.converted.geojson';
var expected = './test/data/world_merc.converted.geojson';
if (!fs.existsSync(expected) || process.env.UPDATE ) {
fs.writeFileSync(expected,JSON.stringify(geojson,null,2));
}
fs.writeFileSync(actual,JSON.stringify(geojson,null,2));
assert.ok(Math.abs(fs.readFileSync(actual).length-fs.readFileSync(expected).length) < 3000);
}
assert.end();
});