forked from labexp/data_scripts_lascallesdelasmujeres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (49 loc) · 1.56 KB
/
index.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 path = require('path');
const fs = require('fs');
let tilereduce = require('tile-reduce');
const args = require('yargs').argv;
let ciudad = 'ciudad';
const opts = {
bbox: [-84.12, 9.9, -84.02, 9.96], //San jose
log: true,
zoom: 12,
sources: [
{
name: 'osm',
mbtiles: path.join(__dirname, 'data/latest.planet.mbtiles')
//raw: true
}
],
maxWorkers: 4,
map: __dirname+'/map.js'
};
for (let j = 0; j < args.length; j++) {
console.log(j + ' -> ' + (args[j]));
}
if (args.area) opts.bbox = JSON.parse(args.area);
if (args.ciudad) ciudad = args.ciudad;
let num = 0;
const finalGeojson = {
"type": "FeatureCollection",
"features": []
};
tilereduce = tilereduce(opts)
.on('start', function () {
console.log('starting');
})
.on('map', function (tile, workerId) {
console.log('about to process ' + JSON.stringify(tile) +' on worker '+workerId);
})
.on('reduce', function(result, tile){
num++;
finalGeojson.features = finalGeojson.features.concat(result.features) ;
})
.on('end', function(error){
fs.writeFile( path.join(__dirname, `data/${ciudad}/${ciudad}_streets.geojson`), JSON.stringify(finalGeojson), function(err) {});
console.log(`${num} tiles has been processed.`);
fs.copyFileSync(path.join(__dirname, `data/list.csv`), path.join(__dirname, `data/${ciudad}/list.csv`));
fs.unlinkSync(path.join(__dirname, `data/list.csv`));
console.log('list.csv was copied to folder destination.');
console.log('--------------------- END RESULTS -----------------------');
});