Skip to content

Instantly share code, notes, and snippets.

@jkutianski
Created August 7, 2013 19:37
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 jkutianski/6177718 to your computer and use it in GitHub Desktop.
Save jkutianski/6177718 to your computer and use it in GitHub Desktop.
Dirty hack to extract features from geoJSON files. Useful to split geoJSON based on equal propertires.
// Sample use: node extractFeatures.js argentina.json "properties.is_in:state.toLowerCase() === 'buenos Aires'" > buenos_aires.json
var path = require('path'),
origin = require(path.resolve(__dirname, process.argv[2])),
selector = process.argv[3],
destination = {
"type": "FeatureCollection",
"features": []
},
i=0;
origin.features.forEach(function(origin_e, origin_i) {
if (eval("origin_e." + selector)) {
destination.features[i] = origin_e;
i++;
}
});
console.log(
JSON.stringify(destination)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment