-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuburb_boundary_loader.js
32 lines (30 loc) · 1.2 KB
/
suburb_boundary_loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var lazy = require("lazy"),
fs = require("fs"),
mongo = require('mongoskin'),
db = mongo.db('mongodb://heroku:[email protected]:10020/app1717097?auto_reconnect=true');
db.bind('prices');
new lazy(fs.createReadStream('vic_suburb.txt')).lines.forEach(function(line) {
var lineStr = line.toString();
var suburb = lineStr.split(':')[0];
var boundary = lineStr.split(':')[1];
var searchKey = {suburb:suburb, state:'VIC'};
db.prices.findOne(searchKey, function(err, updated_suburb) {
if (updated_suburb) {
var points = boundary.split(',');
var latLongs = [];
for (var i = 0; i < points.length; i++) {
var latLong = points[i].replace(/^\s+|\s+$/g, '').split(' ');
var lat = latLong[1] * 1;
var long = latLong[0] * 1;
latLongs.push([lat, long]);
}
db.prices.update(searchKey, {$set: {boundary:latLongs}}, function(err) {
if (err) {
console.log('update error', err);
} else {
console.log(suburb);
}
});
}
});
});