Compare commits

...

2 Commits

Author SHA1 Message Date
n3040 057c199b18 生成整个断面。 2024-01-03 09:23:35 +08:00
n3040 308259306f 设置了缩放因数 2023-06-12 22:27:48 +08:00
2 changed files with 99 additions and 28 deletions

125
dem.py
View File

@ -46,15 +46,21 @@ class Dem:
return dem_row, dem_col, dem_band, dem_gt, dem_proj
def write_dxf(self):
# TODO:不应该设置缩放因数
zoom_factor = 1
excel_pfs = self._read_path_file()
segments = []
plate_doc = ezdxf.new(dxfversion="R2010")
plate_msp = plate_doc.modelspace()
toml_dict = self._toml_dict
out_dxf_file_dir = toml_dict["parameter"]["out_dxf_file_dir"]
# 写整个断面
dm_whole_doc = ezdxf.new(dxfversion="R2004")
dm_whole_accumulative_distance = 0 # 累加里程
dm_whole_msp = dm_whole_doc.modelspace()
for foo in range(len(excel_pfs) - 1):
start_point_name: str = excel_pfs.iloc[foo, 0]
end_point_name: str = excel_pfs.iloc[foo + 1, 0]
start_point_name: str = excel_pfs.iloc[foo, 3]
end_point_name: str = excel_pfs.iloc[foo + 1, 3]
point_x_s = float(excel_pfs.iloc[foo, 1])
point_y_s = float(excel_pfs.iloc[foo, 2])
point_x_e = float(excel_pfs.iloc[foo + 1, 1])
@ -79,35 +85,90 @@ class Dem:
cord_0 = line_coordination[0, 2:4] # 取中线的
for cord in line_coordination[1:, 2:4]:
x_axis.append(dem_utils.distance(cord, cord_0))
dm_msp.add_polyline2d(
[
(x_axis[i] / 5, left_elevation[i] * 2)
for i in range(len(left_elevation))
],
# 左边线
left_line = [
(x_axis[i] / 5 / zoom_factor, left_elevation[i] * 2 / zoom_factor)
for i in range(len(left_elevation))
]
dm_whole_msp.add_polyline2d(
np.array(left_line)
+ np.hstack(
(
dm_whole_accumulative_distance * np.ones((len(x_axis), 1)) / 5,
np.zeros((len(x_axis), 1)),
)
),
dxfattribs={"color": 1},
) # 红色
dm_msp.add_polyline2d(
[
(x_axis[i] / 5, center_elevation[i] * 2)
for i in range(len(center_elevation))
]
dm_msp.add_polyline2d(left_line, dxfattribs={"color": 1}) # 红色
mid_line = [
(x_axis[i] / 5 / zoom_factor, center_elevation[i] * 2 / zoom_factor)
for i in range(len(center_elevation))
] # 中线
dm_whole_msp.add_polyline2d(
np.array(mid_line)
+ np.hstack(
(
dm_whole_accumulative_distance * np.ones((len(x_axis), 1)) / 5,
np.zeros((len(x_axis), 1)),
)
)
)
dm_msp.add_polyline2d(mid_line)
# 右边线
right_line = [
(x_axis[i] / 5 / zoom_factor, right_elevation[i] * 2 / zoom_factor)
for i in range(len(right_elevation))
]
dm_whole_msp.add_polyline2d(
np.array(right_line)
+ np.hstack(
(
dm_whole_accumulative_distance * np.ones((len(x_axis), 1)) / 5,
np.zeros((len(x_axis), 1)),
)
),
dxfattribs={"color": 5}, # 蓝色
)
dm_msp.add_polyline2d(
[
(x_axis[i] / 5, right_elevation[i] * 2)
for i in range(len(right_elevation))
],
right_line,
dxfattribs={"color": 5},
) # 蓝色
# 树的线
# 考虑用最高边线的情况
if self._tree_height > 0:
dm_msp.add_polyline2d(
[
(x_axis[i] / 5, ( np.max( (center_elevation[i],left_elevation[i],right_elevation[i])) + self._tree_height) * 2)
for i in range(len(center_elevation))
]
tree_line = [
(
x_axis[i] / 5 / zoom_factor,
(
np.max(
(
center_elevation[i],
left_elevation[i],
right_elevation[i],
)
)
+ self._tree_height
)
* 2
/ zoom_factor,
)
for i in range(len(center_elevation))
]
if self._tree_height > 0:
dm_whole_msp.add_polyline2d(
np.array(tree_line)
+ np.hstack(
(
dm_whole_accumulative_distance
* np.ones((len(x_axis), 1))
/ 5,
np.zeros((len(x_axis), 1)),
)
),
dxfattribs={"color": 5},
)
dm_msp.add_polyline2d(tree_line, dxfattribs={"color": 5})
dm_whole_accumulative_distance += x_axis[-1]
os.makedirs(out_dxf_file_dir, exist_ok=True)
ezdxf.options.set(
"odafc-addon",
@ -122,14 +183,16 @@ class Dem:
replace=True,
) # 写断面文件
# 写Z文件
with open(
f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}", "w"
) as z_file:
z_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
with open(z_file_path, "w") as z_file:
z_file.write("0 ")
z_file.write(f"{center_elevation[0]*2} ")
z_file.write("0 ")
z_file.write("0 ")
z_file.write(f"{center_elevation[0]*2-50}")
if foo == 0:
# copy file a to dist b
shutil.copy(z_file_path, f"{out_dxf_file_dir}/ZDA")
# 写平面文件
plate_msp.add_polyline2d(
line_coordination[:, 0:2],
@ -171,6 +234,13 @@ class Dem:
segments, tower_start_num, control_file_template_path, out_dxf_file_dir
)
c_file.save()
# 写整个断面文件
export_dwg(
dm_whole_doc,
f"{out_dxf_file_dir}/DA.dwg",
replace=True,
)
# 写平面文件
plate_doc.saveas(f"{out_dxf_file_dir}/plate.dxf")
def get_elevation(self, site_x_y):
@ -257,7 +327,6 @@ class Dem:
)
)
site_ele[i] = point_z
# print(f"row:{Yline} col:{Xpixel} elev:{site_ele[i]}")
pass
return site_ele
@ -266,7 +335,9 @@ class Dem:
(point_x_s - point_x_e) ** 2 + (point_y_s - point_y_e) ** 2
) ** 0.5
dem_resolution = self._dem_resolution # dem的精度
n = round(path_length / dem_resolution)
# TODO:设定为5m 1个点。
# n = round(path_length / dem_resolution)
n = round(path_length / 5)
center_point_x = np.linspace(point_x_s, point_x_e, n, endpoint=True)
center_point_y = np.linspace(point_y_s, point_y_e, n, endpoint=True)
# 计算左右边线

2
pw.py
View File

@ -97,5 +97,5 @@ class ControlFile:
c_template = c_template.replace(
"{CONTROL_FILE}", f"S{segments[0]-4000+100}"
)
with open(f"{out_dir}/C{segments[0]-4000+100}.dat", "w") as c_file:
with open(f"{out_dir}/PW{segments[0]-4000+100}.dat", "w") as c_file:
c_file.write(c_template)