Skip to content

Instantly share code, notes, and snippets.

@justincy
Created February 27, 2014 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justincy/9252184 to your computer and use it in GitHub Desktop.
Save justincy/9252184 to your computer and use it in GitHub Desktop.
Mapshaper infinite loop bug
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.
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