Mar 25, 2010
Changed example title and moved to python directory
|
|
|
7 |
|
|
8 |
def getChart(chartData, chartDataScaling="-500,5000", chartType="lc",chartLabel="Elevation in Meters",chartSize="500x160", chartColor="orange", **chart_args): |
|
9 |
chart_args.update({ |
|
10 |
'cht': chartType, |
|
11 |
'chs': chartSize, |
|
12 |
'chl': chartLabel, |
|
13 |
'chco': chartColor, |
|
14 |
'chds': chartDataScaling, |
|
15 |
'chxt': 'x,y', |
|
16 |
'chxr': '1,-500,5000' |
|
17 |
}) |
|
18 |
|
|
19 |
dataString = 't:' + ','.join(str(x) for x in chartData) |
|
20 |
chart_args['chd'] = dataString.strip(',') |
|
21 |
|
|
22 |
chartUrl = CHART_BASE_URL + '?' + urllib.urlencode(chart_args) |
|
23 |
|
|
24 |
print("") |
|
25 |
print("Elevation Chart URL:") |
|
26 |
print("") |
|
27 |
print chartUrl |
|
28 |
|
|
29 |
def getElevation(path="36.578581,-118.291994|36.23998,-116.83171",samples="100",sensor="false", **elvtn_args): |
|
30 |
elvtn_args.update({ |
|
31 |
'path': path, |
|
32 |
'samples': samples, |
|
33 |
'sensor': sensor |
|
34 |
}) |
|
35 |
|
|
36 |
url = ELEVATION_BASE_URL + '?' + urllib.urlencode(elvtn_args) |
|
37 |
response = simplejson.load(urllib.urlopen(url)) |
|
38 |
|
|
39 |
|
|
40 |
# Create a dictionary for each results[] object |
|
41 |
elevationArray = [] |
|
42 |
|
|
43 |
for resultset in response['results']: |
|
44 |
elevationArray.append(resultset['elevation']) |
|
45 |
|
|
46 |
# Create the chart passing the array of elevation data |
|
47 |
getChart(chartData=elevationArray) |
|
48 |
|
|
49 |
if __name__ == '__main__': |
|
50 |
|
|
51 |
print("") |
|
52 |
print("Elevation Chart Maker 1.0") |
|
53 |
print("") |
|
54 |
print("The following service calculates elevation data between two points") |
|
55 |
print("and builds an HTTP chart using Google's Elevation service and Chart API") |
|
56 |
print("") |
|
57 |
|
|
58 |
# Collect the Latitude/Longitude input string |
|
59 |
# from the user |
|
60 |
startStr = raw_input('Enter the start latitude,longitude value (default Mt. Whitney) --> ').replace(' ','') |
|
61 |
if not startStr: |
|
62 |
startStr = "36.578581,-118.291994" |
|
63 |
|
|
64 |
endStr = raw_input('Enter the end latitude,longitude value (default Death Valley) --> ').replace(' ','') |
|
65 |
if not endStr: |
|
66 |
endStr = "36.23998,-116.83171" |
|
67 |
|
|
68 |
pathStr = startStr + "|" + endStr |
|
69 |
|
|
70 |
getElevation(pathStr) |