2 # vi: set softtabstop=4 shiftwidth=4 tabstop=8 expandtab:
10 def latdist(lat1
, lat2
):
11 return (lat1
- lat2
) * 111.325
13 def longdist(lat
, long1
, long2
):
14 return (long1
- long2
) * math
.cos(lat
/ 180.0 * math
.pi
) * 111.325
16 def locdist(loc1
, loc2
):
17 """terrible approximation"""
18 xdist
= longdist(loc1
.latitude
, loc1
.longitude
, loc2
.longitude
)
19 ydist
= latdist(loc1
.latitude
, loc2
.latitude
)
20 return math
.sqrt(xdist
* xdist
+ ydist
* ydist
)
22 def analyze(stoplist
):
23 home
= [stop
for stop
in stoplist
24 if isinstance(stop
, BusStopMashup
.HomeLocation
)][0]
26 westiest
= min(stop
.location
.longitude
for stop
in stoplist
)
27 eastiest
= max(stop
.location
.longitude
for stop
in stoplist
)
28 northiest
= min(stop
.location
.latitude
for stop
in stoplist
)
29 southiest
= max(stop
.location
.latitude
for stop
in stoplist
)
31 print "\twest-east distance: %f" % (eastiest
- westiest
)
32 print "\twest-east distance: %f km" % longdist(home
.location
.latitude
,
34 print "\tnorth-south distance: %f" % (southiest
- northiest
)
35 print "\tnorth-south distance: %f km" % latdist(southiest
, northiest
)
39 dist
= locdist(stop
.location
, home
.location
)
43 print "\tMax dist from home: %f km" % maxdist
45 print "\tDegree dist from home: %f N, %f S, %f W, %f E" % (
46 home
.location
.latitude
- northiest
,
47 southiest
- home
.location
.latitude
,
48 home
.location
.longitude
- westiest
,
49 eastiest
- home
.location
.longitude
)
51 if __name__
== '__main__':
52 filename
= "grabs/stoplocations.pickle"
54 datapoints
= pickle
.load(open(filename
, "r"))
56 c
= BusStopMashup
.Client()
58 for k
in ('41 antares', 'heron & data centre', 'kent & albert',
59 'carling & preston', 'bank & florence'):
60 datapoints
[k
] = list(c
.findStops(k
))
62 f
= open(filename
, "w")
63 pickle
.dump(datapoints
, f
)
67 analyze(datapoints
[k
])