Beispiel #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
Beispiel #2
0
def mark(point):
    point.vis = True
    connect.execute("UPDATE pictures SET visited=True WHERE id=%s", [point.ID])
Beispiel #3
0
def addpicture():
    query = 'INSERT INTO `pictures` (`position`, `bearing`, `focus`) VALUES (GeometryFromText(%s), %s, %s);'
    vals = ('POINT(' + request.form['lat'] + ' ' + request.form['lng'] + ')', request.form['bearing'], request.form['focus'])
    connect.execute(query, vals)
    return render_template('common/picture_response.html')