Last active
August 29, 2015 13:57
-
-
Save M165437/9549734 to your computer and use it in GitHub Desktop.
TMS to OpenStreetMap/Google Maps tile naming – node.js script that inverts row order/y axis
This file contains hidden or 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
/** | |
* TMS to OSM/Google Maps tile naming – node.js script that inverts row order/y axis | |
* assumes subfolders ./tiles/{z}/{x}/{y}.png | |
*/ | |
(function() { | |
// ShellJS | |
require('shelljs/global'); | |
// Variables | |
var dirs, dir, numeric, tiles, tmp, | |
path = require('path'), | |
extImg = '.png', | |
extTmp = '.tmp'; | |
// Sort helper | |
numeric = function(a, b) { | |
var rx = /\D+/g; | |
return a.replace(rx, '') - b.replace(rx, ''); | |
}; | |
// Create directory list | |
dirs = find('./tiles').filter(function(el) { | |
return test('-d', el); | |
}); | |
// Walk directories | |
for (var i = 0; i < dirs.length; i++) { | |
dir = dirs[i]; | |
// Rename files | |
tiles = ls(dir + '/*' + extImg).sort(numeric); | |
for (var j = 0; j < tiles.length; j++) { | |
mv(tiles[j], dir + '/' + (tiles.length-1-j) + extImg + extTmp); | |
} | |
// Clean up temporaries | |
tiles = ls(dir + '/*' + extTmp).sort(numeric); | |
for (var k = 0; k < tiles.length; k++) { | |
mv(tiles[k], tiles[k].replace(extTmp, '')); | |
} | |
} | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment