Skip to content

Instantly share code, notes, and snippets.

@helderdarocha
Created November 23, 2019 14:43
Show Gist options
  • Save helderdarocha/317bb19af8095d888d8363c713270a16 to your computer and use it in GitHub Desktop.
Save helderdarocha/317bb19af8095d888d8363c713270a16 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const source = "../geo/ne_110m_admin_0_countries.json";
const target = "../geo/world.geojson";
fs.readFile(source, 'utf8', (err, json) => {
if(err) throw err;
else process(JSON.parse(json));
});
function process(data) { // filter id (iso-a3) and name of country
data.features.forEach(function(d) {
d.id = d.properties.ISO_A3;
const name = d.properties.NAME;
d.properties = {name: name};
});
writeFile(JSON.stringify(data));
}
function writeFile(data) {
fs.writeFile(target, data, (err) => {
if(err) throw err;
console.log('Done')
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment