Created
August 7, 2013 19:37
-
-
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.
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
// 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