Skip to content

Instantly share code, notes, and snippets.

@jamesbursa
Last active February 5, 2016 03:43
Show Gist options
  • Save jamesbursa/2026d7338b7a3d227732 to your computer and use it in GitHub Desktop.
Save jamesbursa/2026d7338b7a3d227732 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/node
"use strict";
var path = require("path");
var TileReduce = require("tile-reduce");
var opts = {
zoom: 15,
sources: [
{
name: "dc",
mbtiles: path.join(__dirname, "dc.mbtiles"),
layers: ["dc"],
},
],
map: path.join(__dirname, "tilereduce_test_map.js"),
tiles: [[9378, 12535, 15]],
};
TileReduce(opts);
"use strict";
var turf = require("turf");
var util = require("util");
function map(data, tile, writeData, done, args) {
var feature = data.dc.dc.features[0];
var square = turf.bboxPolygon([-76.965, 38, -76, 38.895]);
console.info("map tile %s", JSON.stringify(tile));
console.info("---------------------------------------------------------------");
console.info("feature = %s;", util.inspect(feature, { depth: 4 }));
console.info("square = %s;", util.inspect(square, { depth: 4 }));
try {
var intersect = turf.intersect(square, feature);
console.info("intersect = %s;", util.inspect(intersect, { depth: 4 }));
} catch (ex) {
console.info("*** turf.intersect exception: %s", ex);
}
console.info("---------------------------------------------------------------");
console.info("converting to MultiPolygon");
feature.geometry.type = "MultiPolygon";
var coords = [];
for (var ring of feature.geometry.coordinates) {
coords.push([ring]);
}
feature.geometry.coordinates = coords;
console.info("feature = %s;", util.inspect(feature, { depth: 5 }));
try {
var intersect = turf.intersect(square, feature);
console.info("intersect = %s;", util.inspect(intersect, { depth: 5 }));
} catch (ex) {
console.info("*** turf.intersect exception: %s", ex);
}
console.info("---------------------------------------------------------------");
done(null, null);
}
module.exports = map;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment