Sunday, May 9, 2010

From TileCache to WMTS

I love TileCache ! We have created billions of tiles with it (http://map.geo.admin.ch/,http://plan.epfl.ch/, http://map.veloland.ch/, http://coppet.geocommunes.ch/ etc, etc...). The only issue with TileCache is that it's not an official standard.
The OGC has just released, on 2010.04.06, the first version of the WMTS (Web Map Tile Service) implementation standard. And the very good thing is that one part of the standard proposes a RESTFul implementation. I can already hear some comments like 'all this time for that', but now that it exists, it's probably a good idea to use it. I still think that the service oriented architecture (KVP and more fantastic SOAP (have a look at the wmts:BinaryContent XML tag...)) is a non sense, so this article will only focus on the resource oriented architecture. The standard contains a nice sentence: "The RESTful pattern provides the ability to set up conformant WMTS servers simply", so let's have a look if it's possible to use a TileCache tile sets and serve it as RESTFull WMTS .

Layer
The notion of layer is the same in TileCache and WMTS.

Tile Matrix Set
The notion of Tile Matrix Set doesn't exist in TileCache. A Tile Matrix Set is a collection of tile matrices defined at different scales. For one layer, you can define several Tile Matrix Sets, typically if you want to create tiles in various coordinate systems.

Tile Matrix
A tile matrix is a collection of tiles for a fixed scale. The tile organization is not the same in TileCache and in WMTS.
For TileCache, the first tile (0,0) is on the bottom left:



For WMTS, the first tile (0,0) is on the top left:



But, it's quite easy to name the same tile in both coordinate systems. The following conversion functions can be used:
* WMTS.i = TILECACHE.x
* WMTS.j = HeightNumberOfTiles - TILECACHE.y

The notion of scale in TileCache is simply an integer indexing the tile pyramid (from 0 to n). WMTS offers more freedom for the scale and the identifier can be chosen freely. But it's still possible to convert from WMTS to TileCache:
* WMTS.z (or Tile Matrix identifier) = TILECACHE.scale

Style
In WMTS, the style has been defined as mandatory. Not very clever from my point of view. This should be an optional value. But let's add "default" everywhere... And I still don't understand why the style is defined on the layer level.

Redirection from TileCache to WMTS
A TileCache url:

- http://myTileServer/myLayer/15/000/000/000/000/000/002.jpeg

Can be easily redirected to a WMTS url:

- http://myTileServer/myLayer/default/myTileMatrixSet/15/0/0.jpeg

And, in order to use and see the WMTS tiles, OpenLayers, offers, for example, a very convenient class XYZ:

- new OpenLayers.Layer.XYZ("myLayer",
"http://myTileServer/myLayer/default/myTileMatrixSet/${z}/${y}/${x}.jpeg")

3 comments:

Xavier Mérour said...

Hello,

Thanks for this straighforward and clear explanation.

One question : I tried to find if the WMTS specification offers a way for the client to ask for different WMTS ressources with different tile spaces(thus with same scale sets and same CRS of course).

i.e. : a client would like to ask tiles through WMTS interfaces to two differents WMTS servers with differents tile spaces. Is it possible ?

This is a problem right now with Tilecache which leads to limited interoperability.

Thanks for your answer,

Cédric@camptocamp said...

Interesting question.
If I interpret it correctly, you would like to use in a viewer two tile matrix sets with various tile size and extent.
Usually, for simplicity reasons, when we use TileCache, we try to have the same tile size (256x256 pixels) and the same max extent for all tiled layers.
But, after looking at the OpenLayers code, this should be possible to define, per layer, a specific tile size and a specific extent. So this means that the only constraints on the client side are the resolutions and the coordinate system. Tile size and extent can be chosen freely.
I'm not aware of sites using that, but OpenLayers code should support that (it's probably not tested a lot...)

Xavier Mérour said...

OK, thanks for your answer.

Regarding performance issues, it is certainly better to use same tile size and extents on client side.

But good to know that is is possible.

So, to correct my first comment, there is problen on server side (Tilecache). Sorry...