Skip to content

Instantly share code, notes, and snippets.

@lukasmartinelli
Created July 26, 2016 09:15
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 lukasmartinelli/64db109dbdaaa3bb4ea81bd2220c6593 to your computer and use it in GitHub Desktop.
Save lukasmartinelli/64db109dbdaaa3bb4ea81bd2220c6593 to your computer and use it in GitHub Desktop.
Pyramid Jobs from Tile List File

Usage

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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment