I had the same problem. I wanted to use a scanned and georeferenced
map with MyTourbook which supports adding tile maps with an OSM URL
scheme.
So I wrote the following batch script for Windows. Like the shell
script above it renames the MapTiler generated tile file names to the
inverted Y number. Worked for me on Windows XP. To run the script
create a new text file, e.g. named invert-tiles.bat, in the tiles root
directory (see comments below) and double-click.
---------------------------------------------------------------------------------------------
@echo off
REM invert-tiles.bat
REM
REM Converts MapTiler generated tiles with TMS numbering scheme to
Google Maps/OSM
REM by renaming files to inverted Y (top instead of bottom origin),
e.g.:
REM from: D:\tmp\tiles\8\134\166.png
REM to: D:\tmp\tiles\8\134\89.png
REM See also:
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
REM
REM Place this script into your tiles directory and run it from there:
REM path: <your tiles dir location>\<zoom>\<x>\<y>.png
REM e.g.: D:\tmp\tiles\8\134\166.png
REM script: D:\tmp\tiles\invert-tiles.bat
setlocal enableextensions enabledelayedexpansion
REM *** CUSTOMIZE: ***
REM image file extension (e.g. jpg or png)
set EXTENSION=png
REM path of this script, e.g. D:\tmp\tiles\
set MY_PATH=%~dp0
for /r . %%I in (*.!EXTENSION!) do (
REM path and name of current tile image, e.g. D:\tmp\tiles
\8\134\166.png
set OLD_FILE=%%I
REM name of current tile image, e.g. 166.png
set Y_OLD=%%~nI
REM determine current zoom level from image path:
REM 1. remove path up to tiles dir (image path - script path), e.g.
= 8\134\166.png
set ZXY_PATH=!OLD_FILE!
call set ZXY_PATH=%%ZXY_PATH:!MY_PATH!=%%
REM 2. split remaining path at '\' and get first token as zoom,
e.g. = 8
for /f "tokens=1 delims=\" %%G in ("!ZXY_PATH!") do (
set ZOOM=%%G
)
REM calculate inverse y (166 -> 89)
set /a Y_NEW="(2<<(!ZOOM!-1))-!Y_OLD!-1"
set NEW_FILE=!Y_NEW!.!EXTENSION!
REM echo zoom: !ZOOM!, y: !Y_OLD! - !Y_NEW!, file: !OLD_FILE! - !
NEW_FILE!
echo rename !OLD_FILE! !NEW_FILE!
rename !OLD_FILE! !NEW_FILE!
)
pause
endlocal
---------------------------------------------------------------------------------------------