From f336e60171dca26099f368505bfa052aa29a64e8 Mon Sep 17 00:00:00 2001 From: zstadler Date: Fri, 25 Feb 2022 15:07:38 +0200 Subject: [PATCH 1/4] Add `tile_miltiplier` 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 | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 bin/tile_multiplier diff --git a/bin/tile_multiplier b/bin/tile_multiplier new file mode 100644 index 00000000..5ceccb4f --- /dev/null +++ b/bin/tile_multiplier @@ -0,0 +1,56 @@ +#!/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 + +Origin: https://github.com/Kikehulk/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__)) From 923a7cea53aed472e357d09d0313cbb9f7998585 Mon Sep 17 00:00:00 2001 From: zstadler Date: Fri, 25 Feb 2022 15:31:53 +0200 Subject: [PATCH 2/4] Fix lint issues --- bin/tile_multiplier | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/tile_multiplier b/bin/tile_multiplier index 5ceccb4f..b111e37b 100644 --- a/bin/tile_multiplier +++ b/bin/tile_multiplier @@ -20,6 +20,7 @@ from docopt import docopt import openmaptiles + def main(args): min_zoom = int(args['']) max_zoom = int(args['']) @@ -50,7 +51,8 @@ def main(args): s *= 2 for sx in range(0, s): for sy in range(0, s): - print_once(zz, xx+sx, yy+sy) + print_once(zz, xx + sx, yy + sy) + if __name__ == '__main__': main(docopt(__doc__, version=openmaptiles.__version__)) From eba98615aa99dc9c2c8573aae5fee91f81d5c508 Mon Sep 17 00:00:00 2001 From: zstadler Date: Fri, 25 Feb 2022 15:52:41 +0200 Subject: [PATCH 3/4] Update attribution --- bin/tile_multiplier | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/tile_multiplier b/bin/tile_multiplier index b111e37b..e012fe92 100644 --- a/bin/tile_multiplier +++ b/bin/tile_multiplier @@ -12,7 +12,7 @@ Usage: The minimum zoom for tile to be produced The maximum zoom for tile to be produced -Origin: https://github.com/Kikehulk/makina-maps/blob/master/nginx/tile_multiplier.py +Thanks @frodrigo for https://github.com/makina-maps/makina-maps/blob/master/nginx/tile_multiplier.py """ import sys From 9b67fc26950d28b6e237fdb9febc2e13980a5eca Mon Sep 17 00:00:00 2001 From: zstadler Date: Mon, 7 Mar 2022 00:22:58 +0200 Subject: [PATCH 4/4] chmod +x bin/tile_multiplier --- bin/tile_multiplier | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bin/tile_multiplier diff --git a/bin/tile_multiplier b/bin/tile_multiplier old mode 100644 new mode 100755