Skip to content

Instantly share code, notes, and snippets.

@pvorb
Created August 19, 2011 21:17
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 pvorb/1158030 to your computer and use it in GitHub Desktop.
Save pvorb/1158030 to your computer and use it in GitHub Desktop.
Split germany.osm into 20 handy chunks with Osmosis and Node.js
var n = 55.304138,
e = 15.380859,
s = 47.040182,
w = 4.394531;
var width = e - w,
height = n - s;
console.log("Width: " + width);
console.log("Height: " + height);
var tileWidth = width / 5,
tileHeight = height / 4;
console.log("Tile width: " + tileWidth);
console.log("Tile height: " + tileHeight);
var exec = require("child_process").exec;
var cwd = process.cwd();
var x, y;
var i = 0,
j = 0;
var proc_count = 1;
var filename = "";
// Walk horizontally
for (x = w; x < e; x += tileWidth) {
j = 0;
for (y = n; y > s; y -= tileHeight) {
filename = "germany-" + i + "-" + j++ + ".osm";
exec(cwd + "/osmosis/bin/osmosis "
+ "--read-xml enableDateParsing=no "
+ "file=" + cwd + "/germany.osm "
+ "--bounding-box "
+ "top=" + y + " "
+ "left=" + x + " "
+ "bottom=" + (y - tileHeight) + " "
+ "right=" + (x + tileWidth) + " "
+ "--write-xml "
+ "file=" + cwd + filename,
function(err, stdout, stderr) {
console.log(filename);
console.log(" stdout: " + stdout);
console.log(" stderr: " + stderr);
if (error !== null)
console.log(" exec error: " + error);
}
);
console.log("Initiated split process #" + proc_count++ + ".");
console.log(" File: " + filename + "\n");
}
i++;
}
console.log("Initialization Complete.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment