-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapper.js
67 lines (59 loc) · 1.76 KB
/
mapper.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
'use strict';
const tileReduce = require('@mapbox/tile-reduce');
const path = require('path');
const iogeojson = require('./lib/io');
/**
* Map function from TileReduce. Starts the process of highway compare
*
* @param params - json object
* ex:
* {
* box: boundingboxFile,
* mbtiles: mbtilesFile,
* gtruth: groundtruthFile,
* output: outputFile
* }
*/
const mapper = function(params){
// Agregate the result of reduce within these
let result = {
gtruth: [],
osm: [],
pmissing: [],
missing: [],
update: []
};
// Read the bbox for this dataset
let boundingBox = iogeojson.readGeojson(params.bbox);
// Set and start tilereduce
tileReduce({
zoom: 12,
map: path.join(__dirname, '/reducer.js'),
sources: [
{
name: 'osmtiles',
mbtiles: path.join(__dirname, params.mbtiles),
raw: true
}
],
maxWorkers: params.threads,
geojson: boundingBox,
mapOptions: {
groundtruthFile: params.gtruth
}
})
.on('map', function (tile, workerId) {
console.log('about to process ' + JSON.stringify(tile) +' on worker '+workerId);
})
.on('reduce', function (reduceResult, tile) {
result.gtruth = result.gtruth.concat(reduceResult.gtruth);
result.osm = result.osm.concat(reduceResult.osm);
result.pmissing = result.pmissing.concat(reduceResult.pmissing);
result.missing = result.missing.concat(reduceResult.missing);
result.update = result.update.concat(reduceResult.update);
})
.on('end', function () {
iogeojson.writeResult(params.output, result);
});
};
module.exports = mapper;