-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.py
More file actions
57 lines (42 loc) · 3.64 KB
/
query.py
File metadata and controls
57 lines (42 loc) · 3.64 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import overpy
api = overpy.Overpass()
# test one: (37.87139, -122.27330, 37.87257, -122.27175)
# city of berkeley: (37.84369, -122.33657, 37.91079, -122.22803)
ways_to_remove = [42213220, 42213222, 42213221, 42213224, 233174480, 43843096, 233174481, 37890122, 429259488, 468644955, 755808071, 843904961, 109192573, 410615368, 410615363, 431330572, 760603475, 760603476, 26131333, 774106512, 37061369, 825518424, 28997628, 315995498, 315995499, 520151688, 520151686, 327897036, 431330572, 271976774, 760603475, 763736266, 669491504, 669491501, 428833982, 428833982, 454023413, 88800450, 429259483, 34361074, 34361074, 874580606, 685038710, 685038711, 702596278, 843765026, 262514539, 262514522, 262514531, 906507793, 836651243, 220677320, 35973828, 6347978, 34865267, 836254397, 836254398, 34865268, 314580358, 314580358, 648979893, 648979895, 26379233, 614080393, 677381359, 25947958, 6405082, 26379231, 25947963, 26379230, 24785079, 26379230, 394991558, 658636582, 857408775, 430174931, 440149767, 757212144, 28997620, 184898397, 190385734, 190385739, 42638944, 190380686, 30734877, 190380687, 309025800, 190385736, 190385737, 28997620, 400536078, 400536079, 293158397, 293158396, 512366677, 293158402, 69020838, 25946977, 25946976, 25946975, 943750924, 38939370, 38939355, 38939354, 38939379, 910274505, 25947073, 125718644, 125718643, 182465630, 182465632, 182465634, 182465631, 182465631, 28005527, 182465641, 28474146, 28474155, 28474149, 6339168, 28474144, 28474167, 28474164, 28474195, 28474629, 6339168, 28474189, 28474172, 6339168, 25315659, 43075595, 677381361, 31656181, 24221427, 31656187, 31655275, 24221429, 35973829, 31656176, 31655273, 6371277, 6404484, 423824701, 423824697, 423824692, 423824686, 423824691, 23224930, 423824689, 423824694, 423824700, 423824702, 423824698, 423824700, 423824699, 23224932, 23224931, 23224933, 423824703, 423824685, 23224929, 23224928, 423824690, 423824687, 423824695, 423824693, 23224936, 23224935, 23224934, 182465627, 32210743, 164658210, 28077014, 28077013, 28077015, 7805688, 28077358, 894807766, 14390061, 236340609, 7786736, 28077558, 678597146, 678597118, 6390755, 6339833, 49241114, 49241115, 6353149]
ways_to_add = [223940141, 430174933, 8013480, 25946974]
region = "(37.84369, -122.33657, 37.91079, -122.22803)"
query_string = "((way" + region + """ ["highway"] ["service" != "alley"] ["service" != "emergency_access"] ["service" != "drive-through"] ["service" != "slipway"] ["service" != "parking_aisle"] ["service" != "driveway"] ["highway" != "motorway"] ["highway" != "motorway_link"] ["highway" != "corridor"] ["access" != "no"] ["access" != "private"] ["highway" != "cycleway"];\n"""
for way in ways_to_add:
query_string += "way(" + str(way) + ");\n"
query_string += "); - ("
for way in ways_to_remove:
query_string += "way(" + str(way) + ");\n"
query_string += """
);
);
(._;>;);
out body;
"""
manual_query = query_string.replace(region, "({{bbox}})")
queryFile = open("query.txt", "w")
queryFile.write(manual_query)
queryFile.close()
result = api.query(query_string)
wayFile = open("berkeleyWays.csv", "w")
wayFile.write("name,highway,node_ids\n")
nodeFile = open("berkeleyNodes.csv", "w")
nodeFile.write("id,latitude,longitude\n")
for way in result.ways:
way_name = way.tags.get("name", "n/a")
highway_type = way.tags.get("highway", "n/a")
wayFile.write(way_name + ',' + highway_type + ',')
node_ids = ''
for node in way.nodes:
node_ids = node_ids + str(node.id) + '-'
node_ids = node_ids[:-1]
wayFile.write(node_ids + '\n')
for node in result.nodes:
nodeFile.write(str(node.id) + ',')
print(f'{node.lat:.7f},{node.lon:.7f}', file=nodeFile)
wayFile.close()
nodeFile.close()