Skip to content

Instantly share code, notes, and snippets.

@M165437 M165437/tms2osm.js
Last active Aug 29, 2015

Embed
What would you like to do?
TMS to OpenStreetMap/Google Maps tile naming – node.js script that inverts row order/y axis
/**
* 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
You can’t perform that action at this time.