Created
February 27, 2014 15:22
-
-
Save justincy/9252184 to your computer and use it in GitHub Desktop.
Mapshaper infinite loop bug
This file contains hidden or 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
var fs = require('fs'), | |
mapshaper = require('mapshaper'), | |
argv = require('optimist') | |
.default('i', 500) | |
.argv; | |
if(argv._.length !== 2){ | |
console.log('Usage: node simplify.js <input.geojson> <output.geojson>'); | |
process.exit(); | |
} | |
var data = fs.readFileSync(argv._[0]), | |
geoJSON = JSON.parse(data); | |
fs.writeFileSync(argv._[1], JSON.stringify(simplfyGeometry(geoJSON, parseInt(argv.i)))); | |
function simplfyGeometry(origGeom, interval) { | |
if(origGeom.type == 'Point') return origGeom; | |
var mapGeom = mapshaper.createTopology(mapshaper.importGeoJSON(origGeom)); | |
mapshaper.simplifyPaths(mapGeom.arcs, 'vis'); | |
mapGeom.arcs.setRetainedInterval(interval); | |
mapshaper.findAndRepairIntersections(mapGeom.arcs); | |
return mapshaper.exportGeoJSONObject(mapGeom.layers[0], mapGeom.arcs).geometries[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment