def create(cls, **kwargs): """Insert a new Muni stop entry with all corresponding geoboxes. Args: system: The muni system to use. Always "sf-muni" right now. lat, lon: Coordinates of stop. stop_id: The stop ID of the stop. in_routes: List of inbound routes. out_routes: List of outbound routes. """ all_boxes = [] lat = kwargs.pop("lat") lon = kwargs.pop("lon") for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend( geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) kwargs["stop_id"] = str(kwargs["stop_id"]) kwargs["location"] = db.GeoPt(lat, lon) kwargs["key_name"] = "stop:%s:%s" % (kwargs["system"], kwargs["stop_id"]) kwargs["title"] = route_data.STOP_BY_ID[int(kwargs["stop_id"])][0] kwargs["geoboxes"] = all_boxes kwargs["has_inbound_routes"] = bool(len(kwargs["in_routes"]) > 0) kwargs["has_outbound_routes"] = bool(len(kwargs["out_routes"]) > 0) return cls(**kwargs)
def create(cls, **kwargs): """Insert a new Muni stop entry with all corresponding geoboxes. Args: system: The muni system to use. Always "sf-muni" right now. lat, lon: Coordinates of stop. stop_id: The stop ID of the stop. in_routes: List of inbound routes. out_routes: List of outbound routes. """ all_boxes = [] lat = kwargs.pop("lat") lon = kwargs.pop("lon") for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend(geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) kwargs["stop_id"] = str(kwargs["stop_id"]) kwargs["location"] = db.GeoPt(lat, lon) kwargs["key_name"] = "stop:%s:%s" % (kwargs["system"], kwargs["stop_id"]) kwargs["geoboxes"] = all_boxes kwargs["has_inbound_routes"] = bool(len(kwargs["in_routes"]) > 0) kwargs["has_outbound_routes"] = bool(len(kwargs["out_routes"]) > 0) return cls(**kwargs)
def make(self, line): x = line.split('\t') if(len(x) != 9): return False if(isint (x[ 0]) == False): return False if(isint (x[ 1]) == False): return False if(len (x[ 2]) > SLEN ): return False if(len (x[ 3]) > SLEN ): return False if(len (x[ 4]) > SLEN ): return False if(isint (x[ 5]) == False): return False if(isfloat (x[ 6]) == False): return False if(islat (x[ 6]) == False): return False if(isfloat (x[ 7]) == False): return False if(islon (x[ 7]) == False): return False if(len (x[ 8]) > SLEN ): return False self.lid = int(x[0]) self.stid = int(x[1]) self.lcname = x[2].decode('utf-8') self.liname = x[3].decode('utf-8') self.stname = x[4].decode('utf-8') self.pref = int(x[5]) self.lat = float(x[ 6]) self.lon = float(x[ 7]) self.geoboxes = [] self.geoboxes.extend(geobox.compute_set(self.lat, self.lon, RESOLUTION, SLICE)) return True
def process(lat, lon): all_boxes = [] for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend(geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) return all_boxes, db.GeoPt(lat, lon)
def make(self, line): x = line.split('\t') if(len(x) != 25): return False if(isint (x[ 0]) == False): return False if(isfloat (x[ 1]) == False): return False if(islat (x[ 1]) == False): return False if(isfloat (x[ 2]) == False): return False if(islon (x[ 2]) == False): return False if(len (x[ 3]) > SLEN ): return False if(len (x[ 4]) > SLEN ): return False if(isdatetime(x[ 5]) == False): return False if(len (x[ 6]) > SLEN ): return False if(isint (x[ 7]) == False): return False if(isint (x[ 8]) == False): return False if(len (x[ 9]) > SLEN ): return False if(len (x[10]) > SLEN ): return False if(len (x[11]) > SLEN ): return False if(isint (x[12]) == False): return False if(len (x[13]) > SLEN ): return False if(isint (x[14]) == False): return False if(isint (x[15]) == False): return False if(isint (x[16]) == False): return False if(isint (x[17]) == False): return False if(isint (x[18]) == False): return False if(isint (x[19]) == False): return False if(isint (x[20]) == False): return False if(isint (x[21]) == False): return False if(isint (x[22]) == False): return False if(isfloat (x[23]) == False): return False if(isint (x[24]) == False): return False self.tid = int(x[0]) self.lat = float(x[ 1]) self.lon = float(x[ 2]) self.geoboxes = [] self.geoboxes.extend(geobox.compute_set(self.lat, self.lon, RESOLUTION, SLICE)) self.uid = x[4].decode('utf-8') self.cdate = datetime.strptime(x[5], DATETIMEFORMAT) self.tname = x[6].decode('utf-8') self.stin = int(x[7]) self.stid = int(x[8]) self.stname = x[9].decode('utf-8') self.liname = x[10].decode('utf-8') self.comment = x[11].decode('utf-8') self.pos = int(x[12]) self.posinfo = x[13].decode('utf-8') self.room = int(x[14]) self.urinal = int(x[15]) self.west = int(x[16]) self.japan = int(x[17]) self.multi = int(x[18]) self.public = int(x[19]) self.gender = int(x[20]) self.point = int(x[21]) self.voters = int(x[22]) if(self.voters > 0): self.rate = float(self.point)/float(self.voters) else: self.rate = 0.0 self.confirm = int(x[24]) return True
def kml_to_csv(neighborhoods, district, data, writer, min_timestamp): parsetree = minidom.parseString(data) placemarks = parsetree.getElementsByTagName("Placemark") for place in placemarks: try: description = place.getElementsByTagName('description') extended_data = {} all_info = {} extended_data_nodes = place.getElementsByTagName('SimpleData') for entry in extended_data_nodes: entry_name = entry.getAttribute("name") entry_val = entry.firstChild extended_data[entry_name.lower()] = entry_val.data date = time.strptime(extended_data["date"] + ' ' + extended_data["time"], "%m/%d/%Y %H:%M") if time.mktime(date) < min_timestamp: continue for entry_name in ['category', 'description', 'incident', 'resolution']: all_info[entry_name] = extended_data[entry_name] # print date all_info["timestamp"] = time.mktime(date) location_node = place.getElementsByTagName('Point')[0].getElementsByTagName('coordinates')[0].firstChild.data lon = float(location_node.split(',')[0]) lat = float(location_node.split(',')[1]) all_info["lon"] = lon all_info["lat"] = lat all_info["district"] = district all_boxes = [] for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend(geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) all_info["geoboxes"] = all_boxes all_info["neighborhood"] = find_neighborhood(Point(lat,lon)) writer.writerow(all_info) except Exception, e: print e
def create(cls, **kwargs): lat = kwargs['lat'] lon = kwargs['lon'] location = db.GeoPt(lat, lon) name = kwargs['name'] url = kwargs['url'] area_name = kwargs['area_name'] country = kwargs['country'] all_boxes = [] for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend(geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) new_resort = Resort(name=name, location=location, lat=lat, lon=lon, area_name=area_name, country=country, url=url, geoboxes=all_boxes) return new_resort
def add(self, **kwargs): lat = kwargs.pop('lat') lon = kwargs.pop('lon') location = db.GeoPt(lat, lon) name = kwargs['name'] new_spot = Spot(name=name, location=location) all_boxes = [] #new_spot.pretty_address = kwargs['address'] for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend(geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) new_spot.geoboxes = all_boxes new_spot.description = kwargs['description'] print new_spot.geoboxes print new_spot.description new_spot.put()
def add(self, author, text, lat, lon, image): location = ndb.GeoPt(lat, lon) momento = Momento(author=author, text=text, location=location) if image: momento.image = db.Blob(image) thumbnail = images.resize(image, 100, 100) momento.thumbnail = db.Blob(thumbnail) all_boxes = [] for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend(geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) # logging.debug("Geoboxes " + str(all_boxes)) momento.geoboxes = all_boxes momento.put()
def add(self, **kwargs): lat = kwargs.pop('lat') lon = kwargs.pop('lon') location = db.GeoPt(lat, lon) name = kwargs['name'] new_store = Store(name=name, location=location) all_boxes = [] new_store.pretty_address = kwargs['address'] for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend(geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) new_store.geoboxes = all_boxes store_hour_dict = _make_hours(kwargs['store_hours']) for day, prop in _DAY_DICTIONARY.iteritems(): setattr(new_store, prop, store_hour_dict[day]) new_store.categories = kwargs['categories'] new_store.pretty_description = kwargs['description'] new_store.put()
def create(cls, **kwargs): lat = kwargs['lat'] lon = kwargs['lon'] location = db.GeoPt(lat, lon) name = kwargs['name'] url = kwargs['url'] area_name = kwargs['area_name'] country = kwargs['country'] all_boxes = [] for (resolution, slice, use_set) in GEOBOX_CONFIGS: if use_set: all_boxes.extend( geobox.compute_set(lat, lon, resolution, slice)) else: all_boxes.append(geobox.compute(lat, lon, resolution, slice)) new_resort = Resort(name=name, location=location, lat=lat, lon=lon, area_name=area_name, country=country, url=url, geoboxes=all_boxes) return new_resort