def getTile(self,x,y,z): # Use filename as dictionary key, so that zooms which happen to # use the dataset don't get loaded twice filename = vmap_load.getVmapFilename(x,y,z,self.d) if not filename: return None # If it doesn't already exist, then load it if not self.tiles.has_key(filename): #print("Loading %s" % (filename)) self.tiles[filename] = vmap_load.vmapData(filename) return self.tiles[filename]
def describe(self, lat,lon): """Find the way you're nearest to, and return a description of it""" z = vmap_load.getVmapBaseZoom(self.d) (sx,sy) = tilenames.latlon2xy(lat,lon, z) # download local data filename = vmap_load.getVmapFilename(sx,sy,z,self.d) if(filename != self.dataFilename or self.data == None): #print "road loading %s" % (filename) self.data = vmap_load.vmapData(filename) # look for nearest way (mindist, name) = (1E+10, "not found") for wid,way in self.data.ways.items(): (lastnlon,lastnlat,lastvalid) = (0,0,False) wayName = '' if(way.has_key('N')): wayName += way['N'] + " " if(way.has_key('r')): wayName += way['r'] + " " if(not wayName): wayName = "Way #%d" % wid for n in way['n']: # loop nodes in way (nlat,nlon,nid) = n if(lastvalid): distance = self.distancePointToLine(nlon, nlat, lastnlon, lastnlat, lon, lat) if(distance < mindist): mindist = distance name = wayName #print "Selecting %s at %d" % (name, mindist) (lastnlon,lastnlat,lastvalid) = (lon,lat,True) #print "Done" return(name)