forked from developmentseed/vt-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·56 lines (50 loc) · 2.13 KB
/
cli.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
#!/usr/bin/env node
var path = require('path')
var os = require('os')
var vtGrid = require('./')
var validAggregations = Object.keys(require('geojson-polygon-aggregate'))
var argv = require('yargs')
.usage('$0 input.mbtiles output.mbtiles [--minzoom 7] [--basezoom 12] [--gridsize 1024] --aggregations \'layerName:areaWeightedMean(fieldName)\' \'layerName:count()\'')
.demand(2)
.array('aggregations')
.demand('aggregations')
.describe('aggregations', 'The aggregations to perform, either as a js module (see docs), or in the form \'layerName:aggregationFunction(fieldName)\', aggregationFunction is one of: ' + validAggregations.join(', '))
.describe('postAggregations', 'Module exporting post-aggregation functions to apply (see docs for details).')
.default('minzoom', 1)
.describe('minzoom', 'The lowest zoom level at which to build the grid.')
.default('gridsize', 1024)
.describe('gridsize', 'The number of grid squares per tile. Must be a power of 4.')
.default('basezoom', 'minzoom of data.mbtiles')
.describe('basezoom', 'The zoom level at which to start building (initial data should exist at z-basezoom in input.mbtiles).')
.default('jobs', os.cpus().length)
.describe('jobs', 'The number of concurrent processes to run')
.boolean('progress')
.describe('progress', 'Show progress bar')
.default('progress', true)
.help('h')
.argv
argv.input = normalize(argv._[0])
argv.output = normalize(argv._[1])
if (argv.aggregations.length === 1 && /\.js/.test(argv.aggregations[0])) {
argv.aggregations = argv.aggregations[0]
} else {
var aggregations = {}
argv.aggregations.forEach(function (field) {
// layer:func(inField)
var match = /([^:]+):([^\(]+)\((.*)\)/.exec(field)
var layer = match[1]
var fn = match[2]
var fieldName = match[3]
if (!aggregations[layer]) { aggregations[layer] = {} }
aggregations[layer][fieldName] = fn
if (validAggregations.indexOf(fn) < 0) {
throw new Error('Unknown aggregation function: ' + fn)
}
})
argv.aggregations = aggregations
}
vtGrid(argv)
function normalize (p) {
if (/:\/\//.test(p)) { return p }
return 'mbtiles://' + path.resolve(p)
}