Skip to content

Instantly share code, notes, and snippets.

@davidtheclark
Last active August 15, 2016 01:07
Show Gist options
  • Save davidtheclark/3859542cba61ca8b00d3927700c99737 to your computer and use it in GitHub Desktop.
Save davidtheclark/3859542cba61ca8b00d3927700c99737 to your computer and use it in GitHub Desktop.
'use strict';
const mapnik = require('mapnik');
const VectorTile = require('vector-tile').VectorTile;
const Protobuf = require('pbf');
const fs = require('fs');
mapnik.register_default_input_plugins();
const geojson = fs.readFileSync('original-russian-triangle.geojson', 'utf8');
const LAYER = 'triangles';
function getTiledFeatureGeoJson(z, x, y) {
const mapnikTile = new mapnik.VectorTile(z, x, y);
mapnikTile.addGeoJSON(geojson, LAYER);
const tilePbf = mapnikTile.getDataSync();
const tile = new VectorTile(new Protobuf(tilePbf));
const layer = tile.layers[LAYER];
return layer.feature(0).toGeoJSON(x, y, z);
}
const featureA = getTiledFeatureGeoJson(6, 0, 15);
const featureB = getTiledFeatureGeoJson(6, 63, 15);
const result = {
type: 'FeatureCollection',
features: [featureA, featureB],
};
fs.writeFileSync('tiled-russian-triangle.geojson', JSON.stringify(result, null, 2));
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment