Ejemplo n.º 1
0
def cluster(point):
    global epsilon
    p = getObjPoint(point)
    closeBy = regionQuery(p, epsilon)
    if len(closeBy) == 0:
        sql = "INSERT INTO landmarks (position,centCnt,sumLat,sumLon) VALUES (POINT(%s, %s), %s, %s, %s)"
        vals = [p.lat, p.lon, 1, p.lat, p.lon]
        print 'Beginning new cluster', vals
        connect.execute(sql, vals)
        return

    minP = None
    minDist = 10000
    for dist, point in [(fDist(p, P), P) for P in closeBy]:
        if dist < minDist:
            print dist
            minP = point
            minDist = dist
    print "Minimum:", minDist, minP, minP.ID
    rows = connect.getRows("landmarks",['centCnt','sumLat','sumLon'], 'id=' + str(minP.ID))
    row = rows[0]
    cnt = row[0] + 1
    sumX = row[1] + p.lat
    sumY = row[2] + p.lon

    p.lat = sumX/cnt
    p.lon = sumY/cnt
    sql = "UPDATE landmarks SET position=POINT(%s, %s),centCnt=%s,sumLat=%s,sumLon=%s"
    where = " WHERE id=" + str(minP.ID)
    vals = [p.lat, p.lon, cnt, sumX, sumY]
    connect.execute(sql + where, vals)
    print 'Added to cluster ' + str(minP.ID), vals
Ejemplo n.º 2
0
def queryUnv():
    cols = ('id', 'X(position), Y(position)', 'visited', 'bearing', 'focus')
    points = list()
    for row in connect.getRows("pictures", cols, "visited=False"):
        p = Point(row[0],row[1], row[2], row[3], row[4], row[5])
        points.append(p)
    return points