Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tile_multiplier #407

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions bin/tile_multiplier
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
"""
Expand a list of changed tiles to higher and/or lower zoom levels.
For each line of the form z/x/y in its standard input, representing a tile, the program outputs all tiles that overlap it for all zoom levels between <min_zoom> and <max_zoom>.
Each tile will appear once in its output.
The input zoom level need not be within the <min_zoom>..<max_zoom> range.
Usage:
tile_miltiplier <min-zoom> <max-zoom>
<min-zoom> The minimum zoom for tile to be produced
<max-zoom> The maximum zoom for tile to be produced
Thanks @frodrigo for https://github.com/makina-maps/makina-maps/blob/master/nginx/tile_multiplier.py
"""

import sys
from docopt import docopt

import openmaptiles


def main(args):
min_zoom = int(args['<min-zoom>'])
max_zoom = int(args['<max-zoom>'])
tile_set = set()

def print_once(z, x, y):
if min_zoom <= z <= max_zoom:
tile = f'{z}/{x}/{y}'
num_tiles = len(tile_set)
tile_set.add(tile)
if num_tiles < len(tile_set):
print(tile)

for line in sys.stdin:
z, x, y = [int(i) for i in line.split('/')]
# Original zoom
print_once(z, x, y)
# Lower zoom levels
xx, yy = x, y
for zz in range(z - 1, min_zoom - 1, -1):
xx, yy = xx // 2, yy // 2
print_once(zz, xx, yy)
# Higher zoom levels
xx, yy = x, y
s = 1
for zz in range(z + 1, max_zoom + 1):
xx, yy = xx * 2, yy * 2
s *= 2
for sx in range(0, s):
for sy in range(0, s):
print_once(zz, xx + sx, yy + sy)


if __name__ == '__main__':
main(docopt(__doc__, version=openmaptiles.__version__))