Example #1
0
	def geo_point(self):
		'''
		@return: the obituarys geo_point
		@rtype: dict
		'''
		lat, lon = geohash.decode(self.ghash)
		return {
			'lat': lat,
			'lon': lon
			}
Example #2
0
	def view_geohash(self,geo_hash):
		ent = classes.GHash.get_or_insert(geo_hash)
		
		db_roads = classes.Road.query(ancestor=ent.key).fetch(None)
		roads = self.package_to_visualizer(db_roads)
		
		db_natures = classes.Nature.query(ancestor=ent.key).fetch(None)
		natures = self.package_to_visualizer(db_natures)
		
		db_leisures = classes.Leisure.query(ancestor=ent.key).fetch(None)
		leisures = self.package_to_visualizer(db_leisures)
		
		db_buildingfootprints = classes.BuildingFootprint.query(ancestor=ent.key).fetch(None)
		buildingfootprints = self.package_to_visualizer(db_buildingfootprints)
			
		center = geohash.decode(ent.name)
		self.visualize(center,roads=roads,natures=natures,leisures=leisures,buildingfootprints=buildingfootprints)
Example #3
0
	def to_dict(self):
		'''
		Reverse engineers the city's key to model the form that the server
		receives a city from google maps
		'''
		flat_key = self.key.flat()
		country = flat_key[1]
		admin1 = flat_key[3]
		locality = flat_key[5]
		city_string = '{}, {}'.format(locality,admin1) if admin1 != ' ' else locality
		lat,lon =  geohash.decode(self.ghash)
		return {
			'city_string' : city_string,
			'country' : country,
			'administrative_area_level_1' : admin1,
			'locality' : locality,
			'lat' : lat,
			'lon' : lon
			}
Example #4
0
    def to_dict(self):
        '''
		Reverse engineers the city's key to model the form that the server
		receives a city from google maps
		'''
        flat_key = self.key.flat()
        country = flat_key[1]
        admin1 = flat_key[3]
        locality = flat_key[5]
        city_string = '{}, {}'.format(locality,
                                      admin1) if admin1 != ' ' else locality
        lat, lon = geohash.decode(self.ghash)
        return {
            'city_string': city_string,
            'country': country,
            'administrative_area_level_1': admin1,
            'locality': locality,
            'lat': lat,
            'lon': lon
        }
Example #5
0
	def fetch_radial_cities(self,ghash,precision=3,n=2):
		'''
		Fetches cities around the specified ghash
		Sorts the cities by distance from the center ghash
		@param ghash: the ghash of the center point
		@type ghash: str
		'''
		# calc the center geo_point
		center_geo_point = geohash.decode(ghash)
		# create a list of ghashes around the 
		ghash = utils.chop_ghash(ghash, precision)
		ghash_list = utils.create_ghash_list(ghash, n)
		# get a list of all the city keys in the range of ghashes
		city_keys_set = set([])
		for ghash in ghash_list:
			city_keys = models.City.query(
						models.City.ghash >= ghash,
						models.City.ghash <= ghash+"{"
						).iter(
							batch_size = 50,
							keys_only = True)
			city_keys_set.update(city_keys)
		
		city_futures = ndb.get_multi_async(city_keys_set)
		cities = (c.get_result() for c in city_futures)
		
		cities_list = []
		# calculate the distance from the center ghash
		for city in cities:
			# package the city for the radius list
			city_dict = city.package_for_radius_list()
			# calc distance from center point
			distance = utils.distance_between_points(center_geo_point, city.geo_point)
			# add the distance 
			city_dict['distance'] = distance
			cities_list.append(city_dict)
		
		# sort the list of cities by distance
		cities_list = sorted(cities_list,key=lambda c: c['distance'])
		return cities_list[:10]
Example #6
0
    def view_geohash(self, geo_hash):
        ent = classes.GHash.get_or_insert(geo_hash)

        db_roads = classes.Road.query(ancestor=ent.key).fetch(None)
        roads = self.package_to_visualizer(db_roads)

        db_natures = classes.Nature.query(ancestor=ent.key).fetch(None)
        natures = self.package_to_visualizer(db_natures)

        db_leisures = classes.Leisure.query(ancestor=ent.key).fetch(None)
        leisures = self.package_to_visualizer(db_leisures)

        db_buildingfootprints = classes.BuildingFootprint.query(
            ancestor=ent.key).fetch(None)
        buildingfootprints = self.package_to_visualizer(db_buildingfootprints)

        center = geohash.decode(ent.name)
        self.visualize(center,
                       roads=roads,
                       natures=natures,
                       leisures=leisures,
                       buildingfootprints=buildingfootprints)
Example #7
0
    def city_dict(self):
        '''
		Creates a dict form of the artists city for manage page, etc...
		@warning: This method assumes that each artist has a max of one city
		@return: All the fields that the manage page posts when the server receives a manage post
		@rtype: dict
		'''
        try:
            city = self.cities[0]
        except IndexError:
            # the artist does not have any cities
            # return an empty dict
            return {}
        else:
            # get the full city path
            city_key = city.city_key
            # flatten the key to get the whole path
            flat_key = city_key.flat()
            country = flat_key[1].title()
            admin1 = flat_key[3].title()
            locality = flat_key[5].title()

            # get the lat,lon from the ghash
            lat, lon = geohash.decode(city.ghash)

            # create a string version for display purposes
            city_string = '{}, {}'.format(
                locality, admin1) if admin1 != ' ' else locality

            city_dict = {
                'country': country,
                'administrative_area_level_1': admin1,
                'locality': locality,
                'lat': lat,
                'lon': lon,
                'city_string': city_string
            }
        return city_dict
Example #8
0
	def city_dict(self):
		'''
		Creates a dict form of the artists city for manage page, etc...
		@warning: This method assumes that each artist has a max of one city
		@return: All the fields that the manage page posts when the server receives a manage post
		@rtype: dict
		'''
		try:
			city = self.cities[0]
		except IndexError:
			# the artist does not have any cities
			# return an empty dict
			return {}
		else:
			# get the full city path
			city_key = city.city_key
			# flatten the key to get the whole path
			flat_key = city_key.flat()
			country = flat_key[1].title()
			admin1 = flat_key[3].title()
			locality = flat_key[5].title()
			
			# get the lat,lon from the ghash
			lat,lon = geohash.decode(city.ghash)
			
			# create a string version for display purposes
			city_string = '{}, {}'.format(locality,admin1) if admin1 != ' ' else locality
			
			city_dict = {
						'country' : country,
						'administrative_area_level_1' : admin1,
						'locality' : locality,
						'lat' : lat,
						'lon' : lon,
						'city_string' : city_string
						}
		return city_dict
Example #9
0
	def geo_point(self):
		return geohash.decode(self.ghash)
Example #10
0
 def geo_point(self):
     return geohash.decode(self.ghash)