Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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