Created
October 26, 2012 01:13
-
-
Save RandomEtc/3956433 to your computer and use it in GitHub Desktop.
Simplify GeoJSON using d3-plugins/simplify (thanks @jasondavies for preserving topology!)
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
// TODO: options parser with overrides for projection, area etc. | |
if (process.argv.length != 4) { | |
console.error("usage: node convert.js <input.json> <output.json>"); | |
process.exit(1); | |
} | |
require('d3') | |
require('./node_modules/d3-plugins/simplify/simplify.js') | |
var fs = require('fs'); | |
var simplify = d3.simplify() | |
.area(0) | |
.topology(true) | |
.projection(function(c){ return c; }); | |
console.log('reading input...'); | |
var raw = fs.readFileSync(process.argv[2],'utf8') | |
console.log('parsing input...'); | |
var data = JSON.parse(raw); | |
console.log('simplifying...') | |
var geography = simplify.project(data); | |
var simple = simplify(geography); | |
console.log('stringifying output...') | |
var out = JSON.stringify(simple); | |
console.log('writing output...') | |
fs.writeFileSync(process.argv[3], out); | |
console.log('done!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment