def match_coordinates(self, location, tweet):
     """Returns true if a tweet is sent out from within the given locations, else False"""
     if location['type'] == 'continent':
         return self.area_contains(location['geonameid'], tweet['coordinates'])
     if location['type'] == 'town':
         return spatial.distance_coords(tweet['coordinates'], location['coordinates']) < MAX_DISTANCE_CITY_COORDINATE
     else:
         return self.area_contains(location['country_geonameid'], tweet['coordinates'])
 def match_bbox(self, location, tweet):
     """Returns true if a tweet is sent out from within the given locations, else False"""
     bbox = tweet['bbox']
     bbox_center = (bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2
     if location['type'] == 'continent':
         return self.area_contains(location['geonameid'], bbox_center)
     elif location['type'] == 'town':
         return spatial.distance_coords(bbox_center, location['coordinates']) < MAX_DISTANCE_BBOX_CENTER
     else:
         return self.area_contains(location['country_geonameid'], bbox_center)
Exemple #3
0
 def distance_to_coordinates(self, coordinates, pg):
     if self.type in ('town', 'adm5', 'adm4', 'adm3', 'adm2', 'landmark'):
         if self.coordinates:
             return distance_coords(self.coordinates, coordinates)
         else:
             return None
     else:
         pg.cur.execute(
             """
             SELECT ST_Distance(locations.geom::geography, ST_GeographyFromText('POINT(%s %s)')) FROM locations WHERE location_ID = %s
         """, (coordinates[0], coordinates[1], self.location_ID))
         res = pg.cur.fetchone()
         if not res:
             return None
         else:
             return res[0]
 def is_near(self, loc1, loc2):
     """Returns true if two locations are nearby"""
     if loc1['type'] == 'town' and loc2['type'] == 'town':
         return spatial.distance_coords(loc1['coordinates'], loc2['coordinates']) < NEAR_DISTANCE
     else:
         return False