import sqlite3
import bd_gc_84
import csv
import time
start =time.clock()
print("正在运行..................")
#新建csv文件
file = open('dezhou.csv', 'w', encoding='utf-8', newline="")
csv_writer = csv.writer(file)
csv_writer.writerow(["x","y","count","cityId","date"])
#打开数据库
con = sqlite3.connect("E:\BaiDuMap\hydata.db")
c = con.cursor()
i = 0
for row in c.execute("select * from heatmapdata where cityId = 372"):
# if i >= 100000:
# break
# print(row)
#百度墨卡托转百度经纬度
bd09mcTobd09ll = bd_gc_84.mercatortobd09(row[0],row[1])
# print(bd09mcTobd09ll)
#百度经纬度转国测
bd09togc = bd_gc_84.bd09togcj02(bd09mcTobd09ll[0],bd09mcTobd09ll[1])
# print(bd09togc)
#国测转84
gcto84 = bd_gc_84.gcj02towgs84(bd09togc[0],bd09togc[1])
# print(gcto84)
#写入文件
csv_writer.writerow([gcto84[0],gcto84[1],row[2],row[3],row[4]])
i = i + 1
#利用百度接口进行转换
# url = "https://api.map.baidu.com/geoconv/v1/?coords=" + x + "," + y + "&from=6&to=3&ak=TAnwBKfyivSOa4iqeO6Gw6lRhNF3zKel"
# print (url)
#关闭文档
file.close()
print("运行结束!")
#关闭数据库
c.close()
con.close()
print("转换数据总量:" + str(i))
end = time.clock()
print("运行时间:" + "%.3f"%(end-start)+"秒")
Python读取SQLite数据库(将百度坐标转换为84坐标)并写入csv
于 2022-11-17 17:05:07 首次发布