Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created May 9, 2013 17:27
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 tmcw/5549059 to your computer and use it in GitHub Desktop.
Save tmcw/5549059 to your computer and use it in GitHub Desktop.
var fs = require('fs');
fs.writeFileSync('cities.json', JSON.stringify({
type: 'FeatureCollection',
features: fs.readFileSync('cities.txt', 'utf8').split(/\n/).slice(1).map(function(l) {
return {
type: 'Feature',
properties: {
group: l.split(/\t/)[0],
name: l.split(/\t/)[7],
id: l.split(/\t/)[2],
slug: l.split(/\t/)[6]
},
geometry: {
type: 'Polygon',
coordinates: [
// top left
[+l.split(/\t/)[3], +l.split(/\t/)[2]],
// top right
[+l.split(/\t/)[5], +l.split(/\t/)[2]],
// bottom right
[+l.split(/\t/)[5], +l.split(/\t/)[4]],
// bottom left
[+l.split(/\t/)[5], +l.split(/\t/)[2]],
// top left
[+l.split(/\t/)[3], +l.split(/\t/)[2]]
]
}
};
})
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment