Skip to content

Instantly share code, notes, and snippets.

@keichan34
Created January 31, 2023 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keichan34/b79b214dd15070f25a9b12b1c911c535 to your computer and use it in GitHub Desktop.
Save keichan34/b79b214dd15070f25a9b12b1c911c535 to your computer and use it in GitHub Desktop.
地図タイルとそのタイルの子孫を

tile_children

あるタイルの子孫の一覧を取得する

USAGE

chmod +x tile_children.py
./tile_children.py [parent tile] [maxzoom] [suffix]

EXAMPLE

$ ./tile_children.py 0/0/0 1 .png
getting children of: 0/0/0 until zoom 1
0/0/0.png
1/0/0.png
1/1/0.png
1/1/1.png
1/0/1.png
$ ./tile_children.py 8/220/105 10 .png
getting children of: 8/220/105 until zoom 10
8/220/105.png
9/440/210.png
10/880/420.png
10/881/420.png
10/881/421.png
10/880/421.png
9/441/210.png
10/882/420.png
10/883/420.png
10/883/421.png
10/882/421.png
9/441/211.png
10/882/422.png
10/883/422.png
10/883/423.png
10/882/423.png
9/440/211.png
10/880/422.png
10/881/422.png
10/881/423.png
10/880/423.png

USAGE WITH OTHER TOOLS

$ ./tile_children.py 8/220/105 10 .png > tiles_to_delete.txt
getting children of: 8/220/105 until zoom 10
$ wc -l tiles_to_delete.txt
21 tiles_to_delete.txt
$ cat tiles_to_delete.txt | xargs rm -v
...
#!/usr/bin/env python3
import sys
def get_children(tile):
return [
[tile[0] * 2, tile[1] * 2, tile[2] + 1],
[tile[0] * 2 + 1, tile[1] * 2, tile[2 ] + 1],
[tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
[tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1]
]
def print_children_of_tile_until(tile, suffix, zoom):
if tile[2] == zoom:
return
for child in get_children(tile):
x, y, z = child
print(f"{z}/{x}/{y}{suffix}")
print_children_of_tile_until(child, suffix, zoom)
def main():
tile = map(int, sys.argv[1].split('/'))
maxZoom = int(sys.argv[2])
suffix = sys.argv[3]
z, x, y = tile
print(f"getting children of: {z}/{x}/{y} until zoom {maxZoom}", file=sys.stderr)
parent_tile = [x, y, z]
print(f"{z}/{x}/{y}{suffix}")
print_children_of_tile_until(parent_tile, suffix, maxZoom)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment