-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_stations.py
39 lines (31 loc) · 979 Bytes
/
get_stations.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
from urllib2 import urlopen
import zipfile
from StringIO import StringIO
import csv
import simplejson as json
fp = urlopen("http://www.mta.info/developers/data/nyct/subway/google_transit.zip")
ss = StringIO()
ss.write( fp.read() )
ss.seek(0)
zf = zipfile.ZipFile( ss )
stops = zf.open( "stops.txt" )
rd = csv.reader( stops )
header_row = rd.next()
print header_row
hdr = dict(zip(header_row,range(len(header_row))))
features = []
for row in rd:
geometry = {"type":"Point","coordinates":(row[hdr["stop_lon"]],row[hdr["stop_lat"]])}
properties={'marker-color':"#C4BFE3"}
for i,field in enumerate(header_row):
if field=="stop_lat" or field=="stop_lon":
continue
properties[field] = row[i]
feature = {"type":"Feature","properties":properties,"geometry":geometry}
features.append( feature )
output = {"type":"FeatureCollection","features":features}
fpout = open("stations.geojson","w")
fpout.write( json.dumps(output, indent=2) )
for row in rd:
print row
exit()