Meant to create pyramid jobs for OSM2VectorTiles when only a tile list file is available (e.g. recovering missing tiles).
cat missing_tiles.txt | sed 's/MISSING//g' | python generate_pyramid_jobs.py
```
import json | |
import hashlib | |
import mercantile | |
import fileinput | |
def create_pyramid_job(x, y, min_zoom, max_zoom, bounds): | |
pyramid = { | |
'tile': { | |
'x': x, | |
'y': y, | |
'min_zoom': min_zoom, | |
'max_zoom': max_zoom | |
}, | |
'bounds': { | |
'west': bounds.west, | |
'south': bounds.south, | |
'east': bounds.east, | |
'north': bounds.north | |
} | |
} | |
def payload_id(): | |
hash_obj = json.dumps(pyramid, sort_keys=True).encode('utf-8') | |
return hashlib.sha1(hash_obj).hexdigest() | |
return { | |
'id': payload_id(), | |
'type': 'pyramid', | |
'pyramid': pyramid | |
} | |
def convert_line_to_tile(line): | |
z, x, y = line.split('/') | |
return { 'x': int(x), 'y': int(y), 'z': int(z) } | |
if __name__ == '__main__': | |
for line in fileinput.input(): | |
tile = convert_line_to_tile(line) | |
bounds = mercantile.bounds(tile['x'], tile['y'], tile['z']) | |
job = create_pyramid_job( | |
tile['x'], tile['y'], | |
min_zoom=tile['z'], max_zoom=14, bounds=bounds | |
) | |
print(json.dumps(job)) |