Created
August 19, 2011 21:17
-
-
Save pvorb/1158030 to your computer and use it in GitHub Desktop.
Split germany.osm into 20 handy chunks with Osmosis and Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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