예제 #1
0
def new_track_from_db(str_tid, str_cuid, geom, desc):
    try:
        tid = int(str_tid)
        cuid = int(str_cuid)

        lonlats = cg.geom2lonlats(geom)
        if not len(lonlats) > 0:
            return None

        rds = []
        i = 0
        #for s in desc.split(','):
        #    if s == '':
        #        continue
        #    thso = s.split(' ')
        #    tt = time.strptime(thso[0], "%Y-%m-%dT%H:%M:%SZ")
        #    hh = int(thso[1])
        #    ss = int(thso[2])/1000.0*60.0
        #    if i == 0 or lonlats[i] != lonlats[i-1]:
        #        rds.append( {'time':tt, 'head':hh, 'speed':ss, 'gps_lonlat':lonlats[i]} )
        #    i = i + 1
        #rds = tuple(rds)
        #return Track(tid, cuid, rds, desc)
	for s in desc.split(','):
		if s == '':
			continue
		tt = time.strptime(s, '%Y-%m-%d %H:%M:%S')
		if i == 0 or lonlats[i] !=lonlats[i-1]:
			rds.append({'time':tt,'gps_lonlat':lonlats[i]})
		i = i+1
	rds = tuple(rds)
	return Track(tid, cuid, rds, desc)
    except Exception,e:
        print e
        return None
예제 #2
0
    def reverse_way_by_id(self, wid):
        sql = "select id, source, target, x1, y1, x2, y2, st_astext(geom_way) as geom from " + self.tbname + " where id = %s"
        self.cursor.execute(sql, (wid, ))
        row = self.cursor.fetchone()
        t = int(row['source'])
        s = int(row['target'])
        x2 = float(row['x1'])
        y2 = float(row['y1'])
        x1 = float(row['x2'])
        y1 = float(row['y2'])
        geom = row['geom']
        lonlats = list(cg.geom2lonlats(geom))
        lonlats.reverse()
        geom = cg.lonlats2geom(lonlats)

        print geom
        sql = "update " + self.tbname + " set (source, target, x1, y1, x2, y2, geom_way) = (%s,%s,%s,%s,%s,%s,st_geomfromtext(%s,%s)) where id = %s"
        self.cursor.execute(sql, (s, t, x1, y1, x2, y2, geom, 4326, wid))
        self.conn.commit()
예제 #3
0
 def reverse_way_by_id(self, wid):
     sql = "select id, source, target, x1, y1, x2, y2, st_astext(geom_way) as geom from " + self.tbname + " where id = %s"
     self.cursor.execute(sql, (wid,))
     row = self.cursor.fetchone()
     t = int(row['source'])
     s = int(row['target'])
     x2 = float(row['x1'])
     y2 = float(row['y1'])
     x1 = float(row['x2'])
     y1 = float(row['y2'])
     geom = row['geom']
     lonlats = list(cg.geom2lonlats(geom))
     lonlats.reverse()
     geom = cg.lonlats2geom(lonlats)
    
     print geom
     sql = "update " + self.tbname + " set (source, target, x1, y1, x2, y2, geom_way) = (%s,%s,%s,%s,%s,%s,st_geomfromtext(%s,%s)) where id = %s"
     self.cursor.execute(sql, (s,t,x1,y1,x2,y2,geom,4326,wid))
     self.conn.commit()
예제 #4
0
def new_path_from_db(gw, str_tid, str_way_ids, geom):
    tid = int(str_tid)
    ways = ()

    try:
        lonlats = cg.geom2lonlats(geom)
        if not len(lonlats) > 0:
            return None

        ways = []
        for s in str_way_ids.split(","):
            if s == "":
                continue
            ways.append(int(s))
        ways = tuple(ways)
        if not len(ways) > 0:
            return None
    except Exception, e:
        return None