add feature

This commit is contained in:
baol 2024-11-28 12:17:53 +08:00
parent f33ea984f0
commit d0d120130b
2 changed files with 32 additions and 0 deletions

28
dat_2_pg.py Normal file
View 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
View File

@ -0,0 +1,4 @@
pandas
gdal
geopandas
psycopg[binary]