add feature
This commit is contained in:
parent
f33ea984f0
commit
d0d120130b
28
dat_2_pg.py
Normal file
28
dat_2_pg.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import psycopg
|
||||||
|
|
||||||
|
from read_dat import read_binary_file
|
||||||
|
|
||||||
|
file_path = "lz.out/lz.rivqdown.dat"
|
||||||
|
df = read_binary_file(file_path)
|
||||||
|
|
||||||
|
# PostgreSQL连接配置
|
||||||
|
postgres_config = {
|
||||||
|
"host": "192.168.3.12",
|
||||||
|
"user": "prepare",
|
||||||
|
"password": "preparepassword",
|
||||||
|
"dbname": "preparedb",
|
||||||
|
}
|
||||||
|
|
||||||
|
postgres_conn = psycopg.connect(**postgres_config)
|
||||||
|
postgres_cursor = postgres_conn.cursor()
|
||||||
|
|
||||||
|
for index, row in df.iterrows():
|
||||||
|
for i in range(len(row)):
|
||||||
|
postgres_cursor.execute(
|
||||||
|
"INSERT INTO river_flow (river_id, created_at, runoff) VALUES (%s, %s, %s)",
|
||||||
|
(i + 1, index, row[i]),
|
||||||
|
)
|
||||||
|
|
||||||
|
postgres_conn.commit()
|
||||||
|
postgres_cursor.close()
|
||||||
|
postgres_conn.close()
|
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
pandas
|
||||||
|
gdal
|
||||||
|
geopandas
|
||||||
|
psycopg[binary]
|
Loading…
x
Reference in New Issue
Block a user