Skip to content

Instantly share code, notes, and snippets.

@dianashk
Created January 20, 2016 01:00
Show Gist options
  • Save dianashk/1f437bf738f09c38769e to your computer and use it in GitHub Desktop.
Save dianashk/1f437bf738f09c38769e to your computer and use it in GitHub Desktop.
var fs = require('fs');
var _ = require('lodash');
var data = JSON.parse(fs.readFileSync(process.argv[2]));
var results = [];
Object.keys(data).forEach(function (key) {
var item = data[key];
item.data.source = 'osm';
switch (item._type) {
case 'osmway':
item._type = 'way';
item.data.layer = 'way';
break;
case 'osmnode':
item._type = 'node';
item.data.layer = 'node';
break;
case 'osmaddress':
item._type = 'address';
item.data.layer = 'address';
break;
}
var id = item._id;
id = _.replace(id, 'poi-address-osmway', 'osm-way-poi-address');
id = _.replace(id, 'poi-address-osmnode', 'osm-node-poi-address');
id = _.replace(id, 'address-osmnode', 'osm-node-address');
id = _.replace(id, 'address-osmway', 'osm-way-address');
if (!isNaN(parseInt(id))) {
id = 'osm-' + item._type + '-' + id;
}
item._id = id;
//var id = _.replace(item._id, 'poi-address-osmway', 'osm-way-poi-address');
//id = _.replace(item._id, 'poi-address-osmnode', 'osm-node-poi-address');
var idParts = item._id.split('-');
var sourceId = idParts.filter(function (part) { return !isNaN(part); });
item.data.source_id = sourceId[0];
// delete item.parent;
item.data.parent = {
"country": [],
"country_abbr": [],
"country_id": [],
"region": [],
"region_abbr": [],
"region_id": [],
"county": [],
"county_abbr": [],
"county_id": [],
"locality": [],
"locality_abbr": [],
"locality_id": [],
"localadmin": [],
"localadmin_abbr": [],
"localadmin_id": [],
"neighbourhood": [],
"neighbourhood_abbr": [],
"neighbourhood_id": []
};
results.push(item);
});
fs.writeFileSync(process.argv[2], JSON.stringify(results, null, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment