【发布时间】:2021-05-10 05:31:37
【问题描述】:
我需要在合适的时间将 4600 万个点插入 PostGIS 数据库。插入 1400 万个点执行了大约 40 分钟,它很糟糕而且效率很低。
我使用空间 GIST 索引创建了数据库并编写了以下代码:
import psycopg2
import time
start = time.time()
conn = psycopg2.connect(host='localhost', port='5432', dbname='test2', user='postgres', password='alfabet1')
filepath = "C:\\Users\\nmt1m.csv"
curs = conn.cursor()
with open(filepath, 'r') as text:
for i in text:
i = i.replace("\n", "")
i = i.split(sep=" ")
curs.execute(f"INSERT INTO nmt_1 (geom, Z) VALUES (ST_GeomFromText('POINTZ({i[0]} {i[1]} {i[2]})',0), {i[2]});")
conn.commit()
end = time.time()
print(end - start)
curs.close()
conn.close()
我正在寻找插入数据的最佳方法,它不一定是在 python 中。
谢谢 ;)
【问题讨论】:
标签: python database postgresql postgis