This commit is contained in:
baol 2024-12-25 09:41:48 +08:00
commit a931d9ceb4
7 changed files with 56714 additions and 782325 deletions

18
main.py
View File

@ -15,6 +15,9 @@ a = 0.25
n = 19
val = (np.linspace((x_min**a), (x_max**a), n)) ** (1 / a)
hours = 168
# 生成颜色映射
color_mapping = create_color_gradient_mapping(val)
@ -48,7 +51,7 @@ def read_binary_file(file_path):
while True:
# print("index", index)
if index > 335:
if index > hours:
break
time_bytes = file.read(8)
time = struct.unpack("<d", time_bytes)[0]
@ -113,7 +116,7 @@ def generate_river_czml(river_df, runoff_df, level=4, start_time=None):
"name": "River Flow Visualization",
"version": "1.0",
"clock": {
"interval": f"{format_time(start_time)}/{format_time(start_time + timedelta(hours=335))}",
"interval": f"{format_time(start_time)}/{format_time(start_time + timedelta(hours=hours))}",
"currentTime": format_time(start_time),
"multiplier": 3600, # 1小时/秒
"range": "LOOP_STOP",
@ -126,13 +129,14 @@ def generate_river_czml(river_df, runoff_df, level=4, start_time=None):
# 为每条河段创建一个entity
for idx in river_df.index:
river_index = river_df.loc[idx, "Index"]
river_id = river_df.loc[idx, "Index"]
print("river_index", river_id)
coords = mapping(river_df.loc[idx, "geometry"])["coordinates"]
# new_coords = [coord for point in coords for coord in point]
# print(new_coords)
new_coords = []
for coord in coords:
new_coords.extend([[x, y, 0] for x, y in coord])
new_coords.extend([[round(x, 5), round(y, 5), 0] for x, y in coord])
# 获取该河段的所有时间点的径流数据
river_runoff = runoff_df.iloc[:, idx - 1].values
@ -144,13 +148,13 @@ def generate_river_czml(river_df, runoff_df, level=4, start_time=None):
for hour, runoff in enumerate(river_runoff):
time_offset = hour * 3600 # 转换为秒
value = round(runoff / 86400, 3)
print("value", value)
# print("value", value)
color = get_color_from_value1(abs(value), color_mapping)
color_property["rgba"].extend([time_offset] + list(color))
# 创建河段实体
entity = {
"id": f"{river_index}",
"id": f"{river_id}",
"name": f"River Segment {idx}",
"polyline": {
"positions": {
@ -192,7 +196,7 @@ save_czml(czml_data, 'river_flow.czml')
if __name__ == "__main__":
level = 1
level = 4
# 读取文件
river_df = read_shp("lz.in/1.geojson", level)
runoff_df = read_binary_file("lz.out/lz.rivqdown.dat")

View File

@ -54,7 +54,7 @@ def read_binary_file(file_path):
# print(f"Data: {data}")
while True:
# print("index", index)
if index > 335:
if index > 25:
break
time_bytes = file.read(8)
time = struct.unpack("<d", time_bytes)[0]

BIN
river-sim.zip Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff