Skip to content

Instantly share code, notes, and snippets.

@MateoV
Last active October 6, 2015 22:45
Show Gist options
  • Save MateoV/58626810fa596b9d2b84 to your computer and use it in GitHub Desktop.
Save MateoV/58626810fa596b9d2b84 to your computer and use it in GitHub Desktop.
import json
import mercantile
output = {}
output['type'] = 'FeatureCollection'
output['features'] = []
with open('testlist', 'r') as f:
for line in f:
x = int(line.split('-')[1])
y = int(line.split('-')[2])
z = int(line.split('-')[0])
bounds = mercantile.bounds(x,y,z)
coords = [
[bounds.west, bounds.south],
[bounds.west, bounds.north],
[bounds.east, bounds.north],
[bounds.east, bounds.south],
[bounds.west, bounds.south]
]
feature = {}
feature['type'] = 'Feature'
feature['properties'] = {
'tile': [x,y,z]
}
feature['geometry'] = {
'type': 'Polygon',
'coordinates': [coords]
}
output['features'].append(feature)
writeout = json.dumps(output, separators=(',', ':'))
f_out = open('vivid-westerneu-bboxes.geojson', 'w')
f_out.write(writeout)
f_out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment