Created
May 17, 2016 07:50
-
-
Save lukasmartinelli/f902b21f9a8e7a7406ea762b17f2a893 to your computer and use it in GitHub Desktop.
Scripts to deal with XYZ tile lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fileinput | |
import sys | |
def around_north_pole(y): | |
return y < 75 | |
def around_south_pole(y): | |
return y > 184 | |
if __name__ == '__main__': | |
for line in fileinput.input(): | |
z, x, y = line.split('/') | |
#if not around_north_pole(int(y)) and not around_south_pole(int(y)): | |
# sys.stdout.write(line) | |
if around_north_pole(int(y)): | |
sys.stdout.write(line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import mercantile | |
import fileinput | |
def create_feature(x, y, z): | |
west, south, east, north = mercantile.bounds(x, y, z) | |
return { | |
"type": "Feature", | |
"properties": { | |
"x": x, | |
"y": y, | |
"z": z | |
}, | |
"geometry": { | |
"type": "Polygon", | |
'coordinates': [[ | |
[west, south], | |
[west, north], | |
[east, north], | |
[east, south], | |
[west, south]]] | |
} | |
} | |
def convert_line_to_tile(line): | |
tile_part = line.split('\t') | |
z, x, y = tile_part[0].split('/') | |
return { | |
'x': int(x), | |
'y': int(y), | |
'z': int(z) | |
} | |
def features(): | |
for line in fileinput.input(): | |
tile = convert_line_to_tile(line) | |
yield create_feature(tile['x'], tile['y'], tile['z']) | |
collection = { | |
"type": "FeatureCollection", | |
"features": list(features()) | |
} | |
print(json.dumps(collection)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import mercantile | |
import hashlib | |
import fileinput | |
def create_pyramid_job(x, y, z): | |
bounds = mercantile.bounds(x, y, z) | |
pyramid = { | |
'tile': { | |
'x': x, | |
'y': y, | |
'min_zoom': z, | |
'max_zoom': 14 | |
}, | |
'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): | |
tile_part = line.split('\t') | |
z, x, y = tile_part[0].split('/') | |
return { | |
'x': int(x), | |
'y': int(y), | |
'z': int(z) | |
} | |
for line in fileinput.input(): | |
tile = convert_line_to_tile(line) | |
print(json.dumps(create_pyramid_job(tile['x'], tile['y'], tile['z']))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment