add feature

This commit is contained in:
baol 2024-12-02 10:18:14 +08:00
parent 7767ad2181
commit 3b8f76e6ef
7 changed files with 56714 additions and 782325 deletions

18
main.py
View File

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