def get_poi_within_radius_old(p_lat, p_lon, radius, category_id=None):
    """
    Returns all the points of interest (POI) within the radius of the given point
    :param p_lat: the latitude of the given point
    :param p_lon: the longitude of the given point
    :param radius: the radius in metres
    :param category_id: the optional id of a certain category if left blank all categories will be considered
    :return: returns a list of tuples (distance, POI)
    """
    ret_val = []
    ancestor_key = ndb.Key("FIContent_v1", "POI")

    if category_id is not None:
        poi_query = POI.query(ancestor=ancestor_key).filter(
            POI.categoryID == category_id)
    else:
        poi_query = POI.query(ancestor=ancestor_key)

    potential_poi = poi_query.fetch()

    for poi in potential_poi:
        dist = distance_between_points(p_lat, p_lon, poi.lat, poi.lon)
        if dist < radius:
            ret_val.append((dist, poi))

    return ret_val
def get_poi_within_radius_old(p_lat, p_lon, radius, category_id=None):
    """
    Returns all the points of interest (POI) within the radius of the given point
    :param p_lat: the latitude of the given point
    :param p_lon: the longitude of the given point
    :param radius: the radius in metres
    :param category_id: the optional id of a certain category if left blank all categories will be considered
    :return: returns a list of tuples (distance, POI)
    """
    ret_val = []
    ancestor_key = ndb.Key("FIContent_v1", "POI")

    if category_id is not None:
        poi_query = POI.query(ancestor=ancestor_key).filter(POI.categoryID == category_id)
    else:
        poi_query = POI.query(ancestor=ancestor_key)

    potential_poi = poi_query.fetch()

    for poi in potential_poi:
        dist = distance_between_points(p_lat, p_lon, poi.lat, poi.lon)
        if dist < radius:
            ret_val.append((dist, poi))

    return ret_val
def get_poi_between_latitudes(lat_min, lat_max, category_id=None):
    """
    Returns all POI that have their latitudes between lat_min i lat_max
    :param lat_min:
    :param lat_max:
    :param category_id:
    :return:
    """
    ancestor_key = ndb.Key("FIContent_v1", "POI")
    if category_id is not None:
        poi_query = POI.query(ancestor=ancestor_key).filter(POI.lat > lat_min).filter(POI.lat < lat_max)\
            .filter(POI.categoryID == category_id)
    else:
        poi_query = POI.query(ancestor=ancestor_key).filter(
            POI.lat > lat_min).filter(POI.lat < lat_max)

    return poi_query.fetch(projection=[POI.lat, POI.lon])
def get_poi_between_latitudes(lat_min, lat_max, category_id=None):
    """
    Returns all POI that have their latitudes between lat_min i lat_max
    :param lat_min:
    :param lat_max:
    :param category_id:
    :return:
    """
    ancestor_key = ndb.Key("FIContent_v1", "POI")
    if category_id is not None:
        poi_query = (
            POI.query(ancestor=ancestor_key)
            .filter(POI.lat > lat_min)
            .filter(POI.lat < lat_max)
            .filter(POI.categoryID == category_id)
        )
    else:
        poi_query = POI.query(ancestor=ancestor_key).filter(POI.lat > lat_min).filter(POI.lat < lat_max)

    return poi_query.fetch(projection=[POI.lat, POI.lon])
Ejemplo n.º 5
0
    def insert_item(self, item):
        """
        Inserts a POI item into the data store
        :param item: XML Element with the required fields
        """
        c_name = item.find('name').text
        c_address = item.find('address').text
        c_latitude = item.find('latitude').text
        c_longitude = item.find('longitude').text
        c_open = item.find('open').text
        c_close = ''
        c_website = item.find('website').text
        c_category_id = self.request.get('category_id').encode('utf-8')
        c_description = ''
        c_days = '0'

        ancestor_key = ndb.Key("FIContent_v1", "POI")
        p = POI(parent=ancestor_key, name=c_name, categoryID=int(c_category_id), lat=float(c_latitude),
                lon=float(c_longitude), description=c_description, open=c_open, close=c_close, days=int(c_days),
                address=c_address, website=c_website)
        p.put()