def place_details(self, place_id): # Gets full details from place table for id = place_id # Arguments: # place_id - a place id # Returns - a Place object populated with full place details sql = 'SELECT name, ST_AsText(coordinates), description ' \ 'FROM place ' \ 'WHERE id = ' + str(place_id) row = self._execute_query(sql) place = Place.from_db_string(row[1]) place.id = place_id place.name = row[0] place.description = row[2] return place
def places(self, n): # Gets the n closest places to location, sorted by distance from location # Arguments: # n - the number of places to be returned (0 returns all) # Returns - a list of Place objects representing places cursor = self.connection.cursor() sql = 'SELECT id, ST_AsText(coordinates), name, description, ' \ 'ST_Distance(' + self.location.point_string() + ', proj_coord) ' \ 'AS dist ' \ 'FROM place ' \ 'ORDER BY dist' # Limit query to n rows if required if n != '0': sql += ' LIMIT ' sql += n sql += ';' cursor.execute(sql) places = [] # Copy places to Place object and append to list for row in cursor: place = Place.from_db_string(row[1]) place.id = row[0] place.name = row[2] place.description = row[3] places.append(place) cursor.close() return places
def place2(): place = Place(2, 'Entrance', '-0.85324042683577', '51.2912194132039') place.description = 'Entrance Description' return place
def place3(): place = Place(3, 'Nature Reserve', '-0.8506869638536', '51.2924270909523') place.description = 'Nature Reserve Description' return place
def place1(): place = Place(1, 'Picnic Area', '-0.85198112970328', '51.2924438640308') place.description = 'Picnic Area Description' return place