1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 Handle adding USGS elevations to an SABX 1.0 file.
23 """
24
25 import sys
26 import urllib
27
28 from sabx10.oxm import parse_no_def_namespaces
29 from sabx10.templating import SabxProcessor
30
32 """
33 Call the USGS web service to get the elevation for a point represented by
34 the (lat,lon) pair.
35 """
36 first = False
37 url = "http://gisdata.usgs.gov/" \
38 "xmlwebservices2/elevation_service.asmx/getElevation" \
39 "?X_Value=%s" \
40 "&Y_Value=%s" \
41 "&Elevation_Units=METERS" \
42 "&Source_Layer=-1" \
43 "&Elevation_Only=1" % (lon, lat)
44 tree = parse_no_def_namespaces(urllib.urlopen(url))
45 return tree.findtext("Elevation_Query/Elevation")
46
48 """
49 Add USGS elevations to all the points in an SABX 1.0 file.
50 """
51
53 """
54 Add the USGS elevations to the template data.
55 """
56 SabxProcessor.get_template_data(self)
57
58 count = 0
59 for seg in self.template_data['seg_list']:
60 for pt in seg.waypoints:
61 pt.usgs = get_usgs(pt.lat, pt.lon)
62
63 count += 1
64 if count % 100 == 0:
65 sys.stderr.write("%s" % count)
66 else:
67 sys.stderr.write(".")
68
69 sys.stderr.write("\n")
70