[maptiler] Understand how to generate Mapnik OSM conform tiles (projection problem)

1,546 views
Skip to first unread message

in...@presentec.de

unread,
Apr 26, 2010, 7:09:04 AM4/26/10
to MapTiler User Group
Hello,

I have a problem generating OSM conform tiles. MapTiler works fine,
but I do not undertstand how to generate OSM tiles with the same "tile
numbering scheme". It is very probable, that this is due to my lack of
understanding projection. I "tiled" a raster map and it shows very
nicely in the resulting OpenLayers example.

FireBug gives me:
http://tile.openstreetmap.org/11/1073/709.png

My generated tiles live are:
11/1073/1340.png and
11/1073/1341.png

I implemented a Java OSM viewer (accesses the tile server mentioned
above), which tries to replace the normal OSM tiles with the generated
tiles. This of course fails, as to the difference in the numbering
schemes (1340.png vs. 709.png). As already said, the OpenLayers
example includes the tiles nicely.

MapTiler offers a processing step "Spacial reference system". I tried
WGS84 and UTM with default settings, but I assume I have to tweak the
settings to generate tiles which fit into the default Mapnik tiling
scheme. Can you give me a hint?

Thanks,
Erik



--
You received this message because you are subscribed to the Google Groups "MapTiler User Group" group.
To post to this group, send email to mapt...@googlegroups.com.
To unsubscribe from this group, send email to maptiler+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/maptiler?hl=en.

Klokan Petr Pridal

unread,
May 4, 2010, 10:31:38 AM5/4/10
to MapTiler User Group
Erik,

MapTiler is strictly following the TMS (http://wiki.osgeo.org/wiki/
Tile_Map_Service_Specification) which has the Y axis going in the
bottom up direction.

OSM/Google numbering scheme is not possible in this moment, unless you
modify the source code of GDAL2Tiles/MapTiler.

Can't you change your viewer to support "lowerleft" x "topleft" origin
as parameter?

The conversion of y axis is trivial:

y = (Math.pow(2,zoom)-coord.y-1)

Beside the y coordinate in the name the tiles are compatible.

Best regards,

Klokan

dao...@googlemail.com

unread,
May 11, 2010, 8:03:21 AM5/11/10
to MapTiler User Group
Obviously the TMS specification is great. The only problem is that
there are very popular open source projects using other systems of
tile numbering - like OSM. So it would be very convenient to have OSM/
Google numbering included in gdal2tiles - is this a big effort?

Cheers,
Henning

dao...@googlemail.com

unread,
May 14, 2010, 4:22:39 PM5/14/10
to MapTiler User Group
I looked into the sourcecode but have no clue about Python. So here's
a short shell script that transforms MapTiler TMS output to one that
is OSM/GoogleMaps compatible.
- Use MapTiler to tile your map (chose GoogleMaps compatible
(Spherical Mercator))
- open a terminal and cd into the top directory created by MapTiler
- execute the script - you are done.

Here is the script:
*****************
for I in `find . -type f -maxdepth 3 -mindepth 2 -name *.png`
do OLDNAME=`basename $I .png`
DIRNAME=`dirname $I`
SEP1=${I#./}
SEP2=${SEP1%%/*}
NEWNAME=$((2**$SEP2-$OLDNAME-1))
mv "$I" "$DIRNAME"/"$NEWNAME.png"
done
*****************
Adjust it to your needs. E.g. Maverick on Android phones needs the
same directory/file structure, but has a .png.tile extension instead
of .png only, so use the following script instead
*****************
for I in `find . -type f -maxdepth 3 -mindepth 2 -name *.png`
do OLDNAME=`basename $I .png`
DIRNAME=`dirname $I`
SEP1=${I#./}
SEP2=${SEP1%%/*}
NEWNAME=$((2**$SEP2-$OLDNAME-1))
mv "$I" "$DIRNAME"/"$NEWNAME.png.tile"
done
*****************

Max

unread,
Jul 8, 2010, 11:13:33 AM7/8/10
to MapTiler User Group
Hej !

Is there any way to run this script on a windows machine?
I am not so much into programing, so I have no clue how to run it.

Sorry for the stupid question!

Best,
Max

Max

unread,
Jul 8, 2010, 11:39:42 AM7/8/10
to MapTiler User Group
Still I am not sure if i get this right!
What does the script do?
Is it transforming the folder stucture of the MapTiler output in a
sence, that the tiles have the same numbers as the tiles on Gmap/OSM?

With respect to Eriks example:
http://tile.openstreetmap.org/11/1073/709.png
The script renames the generated tile from 11/1073/1340.png to
11/1073/709.png?

Cheers,
Max

Max

unread,
Jul 9, 2010, 4:33:26 AM7/9/10
to MapTiler User Group
Me again!

I thought some of you could be interested in why I need tiles with
exactly the same numbering as Gmap and OSM:

I am using a freeware program for GPS tracking on my phone. The
program is called NaviComputer ( http://navicomputer.com/
http://forum.xda-developers.com/showthread.php?t=581474 ) and uses OSM
maps for offline navigation.
Therefore it comes with a tool called NaviMapper. It allows you to
save the OSM tiles of a certain region of interest in desired zoom
levels for later use on the phone.
So far, it supports no custom maps like own scanned paper maps. So I
am looking for a way to transform my scanned maps, that I can use it
in OSM. MapTiler is the first step. But now I cannot use Navimapper,
since the numbering differs from the initial OSM numbering.

I need tiles from my own maps but with exactly the same numbering as
on OSM or Gmap. The custom tile numbers must be congruent to the
original tiles!
Is there any chance to find a solution for this?

@Petr: I guess the mentioned application could be quite useful also
for your oldmaps project. Imagine walking trough a modern city with an
old map and your current position on your phone to compare.



Max

unread,
Aug 20, 2010, 8:00:58 AM8/20/10
to MapTiler User Group
No ideas?
Not interested?

Or no solution for the problem? :D

ikonor

unread,
Oct 18, 2010, 12:48:19 PM10/18/10
to MapTiler User Group
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
---------------------------------------------------------------------------------------------

Klokan Petr Přidal

unread,
Jan 16, 2013, 6:05:20 AM1/16/13
to maptiler
Hello Jiri,

to use the tiles in OpenLayers you can call OpenLayers.Layer.TMS instead and you don't need to rename the tiles. But XYZ is required for some clients and for WMTS of course.

Regarding the WMTS:

This is how to open tiles rendered with MapTiler exposed as WMTS in QGIS:

Together with NOAA we started to work on an open-source project called TileServer which provides extremely fast OpenGIS WMTS compliant service for tiles rendered with MapTiler from any ordinary web hosting. It is going to be finished and announced in summer on ICC2013 in Dresden (http://www.icc2013.org/).
If you want to participate on testing or development here is the repository: https://github.com/klokantech/tileserver-php/ and we have also a mockup of the future interface which contain step by step tutorials for how to open the WMTS and the tiles in different clients, including QGIS and ESRI ArcGIS Desktop: http://klokantech.github.com/tileserver-php/tileserver/. A demo server to try it live is at: http://tileserver.maptiler.com/ so the end point is for example http://tileserver.maptiler.com/wmts

If you would like to test this software on your own computer or participate on the development, then go ahead, we accept issue patches ;-)

Best regards,

Petr


On Wed, Jan 16, 2013 at 9:04 AM, Jiří Kadlec <jirik...@gmail.com> wrote:
Very good script. It helped me a lot. Now I can use MapTiler to create the tiles, and then change the numbering using the script. In OpenLayers the layer can be easily added with similar code like this:

OpenLayers.Layer.XYZ( "Air Photo",
    "http://myserver.com/ortophoto/tiles/1.0.0/2011/${z}/${x}/${y}.png",
    {sphericalMercator: true, isBaseLayer: false
})


where the tiles are located on http://myserver.com/ortophoto/tiles/1.0.0/2011/ The overlay_getTileURL function is no longer needed so the code works perfectly also in GeoExt map viewer application.

I'm still trying to figure out, how to make the tiles generated by MapTiler fully compatible with WMTS and how to add these tiles to QGIS.

-- Jiri


On Friday, November 30, 2012 2:10:34 PM UTC+2, mj10777 wrote:



#!/bin/bash
# Problem: gdal2tiles creates the 'mercator' tiles (for osm) with tms-numbering
# http://tile.openstreetmap.org/1/0/0.png = North america [osm]           ; South America [tms]
# http://tile.openstreetmap.org/1/0/1.png =  South america [osm]           ; North America [tms]
# http://tile.openstreetmap.org/1/1/0.png = Asia [osm]                           ; Australia/Antarctica [tms]
# http://tile.openstreetmap.org/1/1/1.png =  Australia/Antarctica [osm] ; Asia [tms]
# This script will move the tms_numbered png to osm_numbered osm
# after all the files have been renumbered, it will move/rename the osm files to png
#Sample:
# mv 0.png 1.osm
# mv 1.png 0.osm
# - after all files have been renamed:
# mv 0.osm 0.png
# mv 1.osm 1.png
# The original script overwrote existing files.
# Mark Johnson, Berlin Germany
# 2012-11-30
for I in `find . -maxdepth 3 -mindepth 2 -type f  -name *.png`

 do OLDNAME=`basename $I .png`
 DIRNAME=`dirname $I`
 SEP1=${I#./}
 SEP2=${SEP1%%/*}
 NEWNAME=$((2**$SEP2-$OLDNAME-1))
 mv "$I" "$DIRNAME"/"$NEWNAME.osm"
done
# rename .osm files to .png
for I in `find . -maxdepth 3 -mindepth 2 -type f  -name *.osm`
 do OLDNAME=`basename $I .osm`
 DIRNAME=`dirname $I`
 mv "$I" "$DIRNAME"/"$OLDNAME.png"
done
exit 0;
To view this discussion on the web visit https://groups.google.com/d/msg/maptiler/-/ma-UlGlWgq0J.

To post to this group, send email to mapt...@googlegroups.com.
To unsubscribe from this group, send email to maptiler+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/maptiler?hl=en.
Reply all
Reply to author
Forward
0 new messages