-
Notifications
You must be signed in to change notification settings - Fork 32
/
rasterize-labels
executable file
·54 lines (46 loc) · 1.46 KB
/
rasterize-labels
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
#!/usr/bin/env node
var path = require('path')
var Vector = require('tilelive-vector')
var tilelive = require('tilelive')
require('mbtiles').registerProtocols(tilelive)
var queue = require('queue-async')
var argv = require('minimist')(process.argv.slice(2))
var style = require('./lib/style')
var readSample = require('./lib/read-sample')
var writeTile = require('./lib/write-tile')
var input = argv._[0] // usually an osm qa tiles mbtiles file
var layers = require(path.resolve(argv._[1])) // json file defining classes
var output = argv._[2] // output dir
var labelRatio = argv._[3]
init(input, style(layers), function (err, vector) {
if (err) { throw err }
var q = queue(5) // TODO: abstract magic number
readSample(argv)
.on('data', function (tile) {
q.defer(function (done) {
//skip images which are blank if the label ratio > 0
//helps with case where images with a label_ratio>0 are sparse
if(labelRatio > 0){
writeTile(output, vector, tile, done, true, '.png')
}else{
writeTile(output, vector, tile, done, false, '.png')
}
})
})
.on('end', function () {
q.awaitAll(function (err) { if (err) { throw err } })
})
})
function init (source, style, cb) {
if (!/^.+:\/\//.test(source)) {
source = 'mbtiles://' + path.resolve(source)
} else {
tilelive.auto(source)
}
console.log('Reading from source', source)
/* eslint-disable no-new */
new Vector({
xml: style,
source: source
}, cb)
}