0

Using mod_tile/renderd to serve OpenStreetMap tiles, I would like to list all tiles already generated in the cache but with an z, x, y notation. Currently, I only get paths for my list of *.meta files

cd /var/lib/mod_tile/ && find `pwd` -name '*.meta' |sed -e 's/\/var\/lib\/mod_tile\/default\///g' | sed -e 's/\.meta//g'

The remaining problem is to convert meta tiles paths to the z, x, y notation.

I already tried to:

Python or Bash answers are preferred because I don't want to add more packages on the server.

2

At the end, I was able to make the conversion from the C code from meta2tile.c mentioned in my question. I didn't try to make any input validation so add a try/except if you want more control on the input

def meta_to_xyz(pattern_meta_with_zoom='6/0/0/0/50/136'):
    """
    Convert meta tiles to z x y scheme for mod_tile
    Author: Thomas Gratier based on Frederik Ramm C code from meta2tile.c from mod_tile
    License: GPL
    """
    x, y = 0, 0
    path_elements = [int(i) for i in pattern_meta_with_zoom.split('/')]
    z = path_elements.pop(0)
    for i in path_elements:
        x <<= 4
        y <<= 4
        x |= (i & 0xf0) >> 4
        y |= (i & 0x0f)
    return z, x, y
0
def meta_to_xyz(pattern_meta_with_zoom='6/0/0/0/50/136'):
    """
    Convert meta tiles to z x y scheme for mod_tile
    Author: Thomas Gratier based on Frederik Ramm C code from meta2tile.c from mod_tile
    License: GPL
    """
    x, y = 0, 0
    path_elements = [int(i) for i in pattern_meta_with_zoom.split('/')]
    z = path_elements.pop(0)
    for i in path_elements:
        x <<= 4
        y <<= 4
        x |= (i & 0xf0) >> 4
        y |= (i & 0x0f)
    return z, x, y


def xyz_to_meta(pattern_xyz='12/981/1535'):
    """
    Convert meta tiles to z x y scheme for mod_tile
    Author: Chad Nelson based on reverse operation of Thomas Gratier's meta_to_xyz
    License: GPL, LGPL, WTFPL
    """
    path_elements = pattern_xyz.split('/')
    path_elements = map(int, path_elements)
    z = path_elements[0]
    x = path_elements[1]
    y = path_elements[2]
    meta_path = list([z, 0, 0, 0, 0, 0])
    for i in range(5, 1, -1):
        meta_path[i] = ((x & 0x0f) << 4) | (y & 0x0f)
        x >>= 4
        y >>= 4

    return meta_path


if __name__ == "__main__":
    print meta_to_xyz('6/0/0/0/50/136')
    print xyz_to_meta('6/56/40')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.