var lineReader = require('line-reader');
lineReader.eachLine('./geonames-data/US/US.txt', function(line, last) {
var city = line.split('\t').structure();
if (city.is) { // if this is a city.
// Delete un-needed object properties so we don't add useless info to DB.
delete city.is;
delete city.type;
// Do something with the city object.
console.log(JSON.stringify(city, true, 3) + '\n');
}
});
Array.prototype.structure = function() {
// from geonames readme: - P.PPL populated place a city, town, village, or other agglomeration of buildings where people live and work
return {
_id: Number(this[0]),
name: this[1],
state: this[10],
country: this[8],
coordinates: [this[4], this[5]],
timezone: this[17],
is: ((this[6] == "P") ? true : false), // if object type is city.
type: ((this[6] == "P") ? "city" : "other") // todo: add a parse function to parse other geonames db types
}
}