def get_yg(self):
     sql = 'SELECT id,lon,lat  FROM stations ;'
     self.cursor.execute(sql)
     result = self.cursor.fetchall()
     for dict in result:
         print(dict)
         print(dict['lat'], dict['lon'])
         lat, lon = conversion.get_lonlat(dict['lat'], dict['lon'])
         print(lat, lon)
         geocode = encode(lat, lon)
         a, b = decode(geocode)
         print(a, b)
         sql = 'UPDATE stations SET geohash = "%s" WHERE  id = %d ;' % (
             geocode, dict['id'])  # 更新下一站信息
         print(sql)
         self.cursor.execute(sql)
         self.db.commit()
     print(result)
Example #2
0
 def insert_nodes(self, info, stype='subways'):
     info = direction_check(info, self.single_uids)
     for l in info:  # 每条路线
         # 1.线路信息
         line = l['name']
         stations = l['stations']
         start_station = stations[0]['name']
         end_station = stations[-1]['name']
         wait_time = l['headway']
         endtime = l['endTime']
         self.dbm.line_feature(
             [start_station, end_station, wait_time, endtime, line], stype)
         for j in range(len(stations)):  # 每个站
             # 2.站点信息
             name = stations[j]['name']
             lon = stations[j]['geo'][2:13]
             lat = stations[j]['geo'][14:24]
             lon, lat = conversion.get_lonlat(float(lon), float(lat))
             self.dbm.stations([name, lon, lat,
                                line])  #1.存储站点信息;  注意:若单独调用,需要检查id信息