[Tilecache] TileCache to TMS URL format

Tyler Durden tylersticky at gmail.com
Mon Jan 11 13:35:13 EST 2010


After taking a look into the OpenLayers source I figured out:

In Python:

def tilecache_to_tms(url, path='cache', layer='base', ext='png'):
    url = url.replace(path, '', 1).strip('/')
    url = url.replace(layer,'', 1).strip('/')
    url = url.replace('.%s' % ext, '', 1).strip('/')
    tokens = [int(t) for t in url.split('/')]
    z = tokens[0]
    x = (tokens[1] * 1000000) + (tokens[2] * 1000) + tokens[3]
    y = (tokens[4] * 1000000) + (tokens[5] * 1000) + tokens[6]
    return '/%s/%s/%s/' % (z, x, y)

>>> url = '/cache/base/10/000/033/127/000/049/665.png'
>>> tilecache_to_tms(url)
'/10/33127/49665/'

Thanks anyway,
Tyler

On Mon, Jan 11, 2010 at 1:08 PM, Tyler Durden <tylersticky at gmail.com> wrote:
> Hi,
> I'm using a layer in OpenLayers that makes requests with the TileCache
> format. And I want to redirect(in my webserver) to a TMS server as
> fallback when the file(tile) does not exists in the cache.
>
> Example:
> http://myserver/cache/base/00/000/000/037/000/000/049.png
> to
> http://myserver/1.0.0/base/0/37/49.png
>
> There's a way(algorithm) for converting this URL's in Python or something else?
>
> Thanks,
> Tyler
>



More information about the Tilecache mailing list