def all_within (self, longitude, latitude, km_radius=ixmaps.EARTH_EQUAT_RADIUS*2, set_to_render=False): """Create a list of carrier hotels within a given radius in km.""" point = ixmaps.ll_to_xyz(latitude, longitude) chotel = None chotel_tuple_list = [] # --- Create list of chotels within radius --- for ch in self.chotels: dist = ixmaps.distance_km(point, ch['xyz']) if dist < km_radius: chotel_tuple_list.append ((dist, ch)) # --- Sort chotels list --- chotel_tuple_list.sort() # --- Convert to non-tupple by removing distance meta-info --- chotel_list = [] for ch in chotel_tuple_list: chotel_list.append (ch[1]) # --- Set whether to render --- for ch in chotel_list: if set_to_render: ch['networks'] = '' ch['to_render'] = True # print chotel_list return chotel_list
def __init__(self, id, name, lat, long, owner): self.id = id self.name = name self.lat = lat self.long = long if id: self.xyz = ll_to_xyz(lat,long) else: self.xyz = (0.0, 0.0, 0.0) self.owner = owner
def __init__(self, conn): qres = conn.query("select * from chotel") try: id = qres.dictresult()[0]['id'] except IndexError: raise TracerouteException, "failed to find any carrier hotels" chotels = qres.dictresult() for ch in chotels: ch['xyz'] = ixmaps.ll_to_xyz(ch['lat'], ch['long']) ch['to_render'] = False self.chotels = chotels self.reset()
def nearest(self, longitude, latitude, km_radius=ixmaps.EARTH_EQUAT_RADIUS*2): """Find the nearest carrier hotel that's within a given radius in km.""" point = ixmaps.ll_to_xyz(latitude, longitude) max_dist = km_radius chotel = None for ch in self.chotels: dist = ixmaps.distance_km(point, ch['xyz']) if dist < max_dist: #print ch['id'], ch['long'], ch['lat'], dist, max_dist max_dist = dist chotel = ch return chotel
def set_geoloc(self, lat, long): self.lat = lat self.long = long self.xyz = ll_to_xyz(lat,long)