-
Notifications
You must be signed in to change notification settings - Fork 2
/
distance.py
36 lines (28 loc) · 849 Bytes
/
distance.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
#!/usr/bin/python3
import csv
import xml.etree.ElementTree as ET
def main():
parseXML('new_york_sample.xml')
def parseXML(xmlfile):
print(xmlfile)
tree = ET.parse(xmlfile)
root = tree.getroot()
print(root)
id = 1
intersections = []
for i in root.findall('./node'):
j = i.find('tag')
if j is not None and j.attrib['v'] == 'traffic_signals':
k = []
k.append(id)
k.append(i.attrib['lat'])
k.append(i.attrib['lon'])
intersections.append(k)
id = id + 1
headers = ['id', 'latitude', 'longitude']
with open('NYC_Intersetions.csv', 'w') as output_file:
writer = csv.writer(output_file, dialect='excel')
writer.writerow(headers)
writer.writerows(intersections)
if __name__ == '__main__':
main()