forked from mapbox/osm-tag-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·72 lines (67 loc) · 1.84 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
66
67
68
69
70
71
72
#!/usr/bin/env node
'use strict';
var help = require('./util/help.js');
var tileReduce = require('@mapbox/tile-reduce');
var path = require('path');
var argv = require('minimist')(process.argv.slice(2));
var gsm = require('geojson-stream-merge');
var fs = require('fs');
var tmpDir = 'tmp-osm-tag-stats/';
var cleanArguments = require('./util/cleanArguments')(argv, tmpDir);
var count = cleanArguments.argv.count,
geojson = cleanArguments.argv.geojson,
users = cleanArguments.argv.users,
dates = cleanArguments.argv.dates,
mbtilesPath = cleanArguments.argv.mbtiles,
tmpGeojson = cleanArguments.tmpGeojson,
tagFilter = cleanArguments.argv.filter,
bbox = cleanArguments.argv.bbox,
maxWorkers = cleanArguments.argv.maxWorkers,
tiles = cleanArguments.argv.tiles,
osmID = new Set(),
tmpFd;
if ((!geojson && !count) || !mbtilesPath || argv.help) {
help();
}
/**
A tile reduce script to filter OSM features and export them to GeoJSON.
*/
tileReduce({
zoom: 12,
map: path.join(__dirname, 'map.js'),
sources: [{name: 'osm', mbtiles: mbtilesPath}],
maxWorkers: maxWorkers,
bbox: bbox,
tiles: tiles,
mapOptions: {
'count': count,
'tmpGeojson': tmpGeojson,
'dates': dates,
'users': users,
'tagFilter': tagFilter
}
})
.on('start', function () {
if (tmpGeojson) {
tmpFd = fs.openSync(tmpGeojson, 'w');
}
})
.on('reduce', function (id) {
if (count && id) {
id.forEach(function (idElement) {
osmID.add(idElement);
});
}
})
.on('end', function () {
if (count) {
console.log('Features total: %d', osmID.size);
}
if (geojson) {
gsm(tmpGeojson, geojson, function () {
fs.closeSync(tmpFd);
fs.unlinkSync(tmpGeojson);
fs.rmdirSync(tmpDir);
});
}
});