|
var Canvas = require('canvas'), |
|
moment = require('moment'), |
|
fs = require('fs'); |
|
|
|
var sqlite3 = require('sqlite3').verbose(); |
|
var db = new sqlite3.Database('changesets_precise.sqlite'); |
|
|
|
var block = 1; |
|
var w = 360 * 4, h = 180 * 4; |
|
var c = new Canvas(w, h); |
|
var ctx = c.getContext('2d'); |
|
|
|
ctx.fillStyle = '#e9e9e9'; |
|
ctx.fillRect(0, 0, w, h); |
|
|
|
function x(lon) { |
|
return (lon + 180) / 360 * w; |
|
} |
|
|
|
function y(lat) { |
|
return (90 - lat) / 180 * h; |
|
} |
|
|
|
var drawn = {}; |
|
|
|
var gap = (60 * 60 * 24 * 73); |
|
var n = 0; |
|
|
|
var colors = ['#FF00C3', '#0091FF']; |
|
var col = 0; |
|
ctx.globalCompositeOperation = 'multiply'; |
|
ctx.fillStyle = colors[col]; |
|
ctx.fillText('OpenStreetMap', w - 100, h - 20); |
|
db.get('SELECT min(closed_at) as m FROM osm_changeset LIMIT 1;', function(err, min) { |
|
db.get('SELECT max(closed_at) as m FROM osm_changeset LIMIT 1;', function(err, max) { |
|
var start = min.m; |
|
var end = min.m + gap; |
|
ctx.fillText(moment(new Date(min.m * 1000)).format('L'), 10, h - 20); |
|
ctx.fillText(moment(new Date(max.m * 1000)).format('L'), 400, h - 20); |
|
|
|
function run() { |
|
drawn = {}; |
|
ctx.globalAlpha = 0.2; |
|
ctx.fillRect( |
|
70, |
|
h - 26, |
|
~~((((start - min.m) / (max.m - min.m)) * 290)), |
|
5); |
|
ctx.globalAlpha = 1; |
|
db.each("SELECT lon, lat FROM osm_changeset WHERE closed_at BETWEEN " + start + " AND " + end + ";", function(err, row) { |
|
var xp = Math.floor(x(row.lon)); |
|
var yp = Math.floor(y(row.lat)); |
|
var k = xp + ' ' + yp; |
|
if (drawn[k]) return; |
|
ctx.fillRect( |
|
xp, |
|
yp, |
|
block, block); |
|
drawn[k] = true; |
|
}, function() { |
|
var k = '' + n; |
|
if (k.length == 1) k = '0' + k; |
|
fs.writeFileSync('changesets_' + k + '.png', c.toBuffer()); |
|
if (start > max.m) return; |
|
start += gap; |
|
end += gap; |
|
n++; |
|
col++; |
|
if (col > 1) col = 0; |
|
ctx.fillStyle = colors[col]; |
|
run(); |
|
}); |
|
} |
|
|
|
run(); |
|
}); |
|
}); |
Hi,
I'm working at replicating this and I am able to ingest the latest changeset downloaded here, http://planet.openstreetmap.org/planet/, into a sqlite database following https://github.com/tmcw/sometimemachine instructions. I can then run this script and it creates the multiple .png images but the only thing that changes between is the timestamp at the bottom, there is no population on the map. I've used a sqlite manager to go into the database and confirm that the data does exist with id's, user ids, lat, long, etc but the data doesn't seem to be populated in the images.
The database is 1.3GB in size, did you ever have this issue running through this?
Thanks