Ejemplo n.º 1
0
def test_projnode_from_db_row(projnode1):

    # Tests ProjNode constructor from_db_row

    db_row = (1, 'POINT(480075.52727804193 155325.20673843563)', 'Node 1')

    act_node = ProjNode.from_db_row(db_row)

    assert_projnode(projnode1, act_node)

    return
Ejemplo n.º 2
0
    def nearest_node(self):

        # Finds the node nearest to location
        # Arguments:
        # Returns - the ProjNode closest to location

        sql = 'SELECT id, ST_AsText(proj_coord), name, ST_Distance(' + self.location.point_string() + ', proj_coord) ' \
              'AS dist ' \
              'FROM node ' \
              'ORDER BY dist ' \
              'LIMIT 1;'

        row = self._execute_query(sql)

        return ProjNode.from_db_row(row)
Ejemplo n.º 3
0
    def bed_nearest_node(self, bed_id):

        # Finds the id of the closest node to bed_id
        # Arguments:
        # bed_id - the id of the flower bed
        # Returns:
        # The ProjNode nearest to the flower bed

        sql = 'SELECT f.nearest_node, ST_AsText(n.proj_coord), n.name ' \
              'FROM flower_bed AS f ' \
              'JOIN node AS n ' \
              'ON f.nearest_node = n.id ' \
              'WHERE f.id = ' + str(bed_id) + ';'

        row = self._execute_query(sql)

        if not row:

            #If place doesn't exist, raise custom exception
            raise BedNotFound('Flower bed ' + str(bed_id) + ' not found')

        return ProjNode.from_db_row(row)
Ejemplo n.º 4
0
    def place_nearest_node(self, place_id):

        # Finds the id of the closest node to place_id
        # Arguments:
        # place_id - the id of the place
        # Returns:
        # ProjNode closest to the place

        sql = 'SELECT p.nearest_node, ST_AsText(n.proj_coord), n.name ' \
              'FROM place AS p ' \
              'JOIN node AS n ' \
              'ON p.nearest_node = n.id ' \
              'WHERE p.id = ' + str(place_id) + ';'

        row = self._execute_query(sql)

        if not row:

            #If place doesn't exist, raise custom exception
            raise PlaceNotFound('Place ' + str(place_id) + ' not found')

        return ProjNode.from_db_row(row)