Created
November 23, 2019 14:43
-
-
Save helderdarocha/317bb19af8095d888d8363c713270a16 to your computer and use it in GitHub Desktop.
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
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