forked from worldbank/ml4dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_get_elements.py
43 lines (37 loc) · 1.22 KB
/
01_get_elements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''
We're gonna download every pitch in the US (leisure=pitch) that is defined
as a way (we want to be able to compute a bounding box and centroid to
improve the CV analysis).
'''
from utils.geo import ELEMENTS_FILENAME
from utils.overpass_client import OverpassClient
import json
# The operator (._;>;); asks for the nodes and ways that are referred by
# the relations and ways in the result.
ql_pitch = '''\
way
[leisure=pitch]
({query_bb_s},{query_bb_w},{query_bb_n},{query_bb_e});
(._;>;);
out;
'''
# For the continental US bbox we use the one provided by:
# https://www.flickr.com/places/info/24875662
us_s = 24.9493
us_w = -125.0011
us_n = 49.5904
us_e = -66.9326
# Overpass requires a bbox in the SWNE format. Because the continental US is
# too big for a single query (it timeouts), we're gonna split in a smaller
# queries. This means (samples-1)^2 boxes.
samples = 11 # 100 boxes
# Total = 1,435,427
overpass_client = OverpassClient(endpoint='fr')
elements = overpass_client.get_bbox_elements(
ql_template=ql_pitch,
bb_s=us_s, bb_w=us_w, bb_n=us_n, bb_e=us_e,
samples=samples)
print 'Total elements found: %d' % len(elements)
# Cache the result
with open(ELEMENTS_FILENAME, 'w') as f:
json.dump(elements, f)