geobuf-to-grid
Version:
Convert a GeoBuf to a regular grid.
34 lines (22 loc) • 779 B
JavaScript
/** Print summary statistics on a grid */
import fs from 'fs'
let nodeBuf = fs.readFileSync(process.argv[2])
let off = 0
let zoom = nodeBuf.readInt32LE((off++) * 4)
let west = nodeBuf.readInt32LE((off++) * 4)
let north = nodeBuf.readInt32LE((off++) * 4)
let width = nodeBuf.readInt32LE((off++) * 4)
let height = nodeBuf.readInt32LE((off++) * 4)
console.log(`${width} x ${height} grid at zoom ${zoom}, upper-left ${west}, ${north}`)
let sum = 0
let current = 0
let min = Infinity
let max = -Infinity
while (off < nodeBuf.length / 4) {
current += nodeBuf.readInt32LE((off++) * 4)
sum += current
min = Math.min(min, current)
max = Math.max(max, current)
}
console.log(`Total ${sum}, average ${sum / (width * height)}, min ${min}, max ${max}`)