source: subversion/applications/routing/pyroute/mod_osmData.py

Last change on this file was 6016, checked in by ojw, 12 years ago

Fix download - make it around ownpos, not around london!

File size: 1.1 KB
Line 
1from loadOsm import LoadOsm
2from base import pyrouteModule
3import os
4import urllib
5
6class osmData(pyrouteModule):
7  def __init__(self, modules):
8    pyrouteModule.__init__(self,modules)
9    self.data = LoadOsm(None)
10 
11  def defaultFilename(self):
12    return("data/routing.osm")
13 
14  def loadDefault(self):
15    self.load(self.defaultFilename())
16   
17  def load(self,filename):
18    print "Loading OSM data from %s"%filename
19    self.data.loadOsm(filename)
20 
21  def download(self,params):
22    ownpos = self.get('ownpos')
23    if(not ownpos['valid']):
24      print "Can only download around own position"
25      return
26
27    lat = ownpos['lat']
28    lon = ownpos['lon']
29    size = 0.2
30   
31    url = "http://informationfreeway.org/api/0.5/way[bbox=%1.4f,%1.4f,%1.4f,%1.4f][highway|railway|waterway=*]" % (lon-size,lat-size,lon+size,lat+size)
32   
33    print "downloading %s" % url
34   
35    filename = self.defaultFilename()
36   
37    if(os.path.exists(filename)):
38      print "Removing existing file"
39      os.remove(filename)
40     
41    urllib.urlretrieve(url, filename)
42   
43    print "Finished downloading"
44    self.load(filename)
Note: See TracBrowser for help on using the repository browser.