Skip to content

Instantly share code, notes, and snippets.

@donmccurdy
Created August 16, 2019 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donmccurdy/2c897d7ca4a00f35f2a4df4639cafa6b to your computer and use it in GitHub Desktop.
Save donmccurdy/2c897d7ca4a00f35f2a4df4639cafa6b to your computer and use it in GitHub Desktop.
Convert a directory of vector tiles to GeoJSON.
const fs = require('fs');
const vt2geojson = require('@mapbox/vt2geojson');
const glob = require('glob');
glob('tiles/**/*.pbf', {}, function (er, files) {
files.forEach((path) => {
const [_, z, x, y] = path.match(/^tiles\/(\d+)\/(\d+)\/(\d+)\.pbf/);
console.log(`x: ${x}`);
vt2geojson({
uri: `tiles/${z}/${x}/${y}.pbf`,
layer: 'no2',
z,
x,
y,
}, function (err, result) {
if (err) throw err;
fs.writeFileSync(`tiles/${z}/${x}/${y}.geojson`, JSON.stringify(result));
console.log(`Wrote tiles/${z}/${x}/${y}.geojson.`)
});
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment