Package sabx10 :: Package utils :: Module sabx_usgs
[hide private]
[frames] | no frames]

Source Code for Module sabx10.utils.sabx_usgs

 1  ############################################################################### 
 2  # 
 3  # sabx10 - an SABX file manipulation library 
 4  # Copyright (C) 2009, 2010 Jay Farrimond (jay@sabikerides.com) 
 5  # 
 6  # This file is part of sabx10. 
 7  # 
 8  # sabx10 is free software: you can redistribute it and/or modify it under the 
 9  # terms of the GNU General Public License as published by the Free Software 
10  # Foundation, either version 3 of the License, or (at your option) any later 
11  # version. 
12  # 
13  # sabx10 is distributed in the hope that it will be useful, but WITHOUT ANY 
14  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 
15  # A PARTICULAR PURPOSE.  See the GNU General Public License for more details. 
16  # 
17  # You should have received a copy of the GNU General Public License along with 
18  # sabx10.  If not, see <http://www.gnu.org/licenses/>. 
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   
31 -def get_usgs(lat, lon):
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
47 -class UsgsProcessor(SabxProcessor):
48 """ 49 Add USGS elevations to all the points in an SABX 1.0 file. 50 """ 51
52 - def get_template_data(self):
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