From 22c9008ff45151953866fde39ad3ced084a4dc8c Mon Sep 17 00:00:00 2001 From: zstadler Date: Mon, 14 Mar 2022 15:10:37 +0200 Subject: [PATCH] Add `tile_multiplier` (#407) Expand a list of changed tiles to higher and/or lower zoom levels. This program expands the list of tiles produced by [`import-diff`](https://github.com/openmaptiles/openmaptiles-tools/blob/master/bin/import-diff) to be used by [`generate-tiles`](https://github.com/openmaptiles/openmaptiles-tools/blob/master/bin/generate-tiles). [`import-diff`](https://github.com/openmaptiles/openmaptiles-tools/blob/master/bin/import-diff) produces a list of tiles in zoom `MAX_ZOOM` that need updating. When [`generate-tiles`](https://github.com/openmaptiles/openmaptiles-tools/blob/master/bin/generate-tiles) is used with `FILE_LIST`, it expects a list of tiles in all 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 `` and ``. - Each tile will appear once in its output. - The input zoom level need not be within the `..` range. Thanks @frodrigo for https://github.com/makina-maps/makina-maps/blob/master/nginx/tile_multiplier.py --- bin/tile_multiplier | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 bin/tile_multiplier diff --git a/bin/tile_multiplier b/bin/tile_multiplier new file mode 100755 index 00000000..e012fe92 --- /dev/null +++ b/bin/tile_multiplier @@ -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 and . +Each tile will appear once in its output. +The input zoom level need not be within the .. range. + +Usage: + tile_miltiplier + + The minimum zoom for tile to be produced + 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['']) + max_zoom = int(args['']) + 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__))