Last active
February 5, 2016 03:43
-
-
Save jamesbursa/2026d7338b7a3d227732 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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