Compare commits
No commits in common. "057c199b18efb43c883802cb8d013ffae9e5dbbb" and "b5e17a3b9e53ce545a87394132da26b3f9ba44e0" have entirely different histories.
057c199b18
...
b5e17a3b9e
123
dem.py
123
dem.py
|
|
@ -46,21 +46,15 @@ class Dem:
|
||||||
return dem_row, dem_col, dem_band, dem_gt, dem_proj
|
return dem_row, dem_col, dem_band, dem_gt, dem_proj
|
||||||
|
|
||||||
def write_dxf(self):
|
def write_dxf(self):
|
||||||
# TODO:不应该设置缩放因数
|
|
||||||
zoom_factor = 1
|
|
||||||
excel_pfs = self._read_path_file()
|
excel_pfs = self._read_path_file()
|
||||||
segments = []
|
segments = []
|
||||||
plate_doc = ezdxf.new(dxfversion="R2010")
|
plate_doc = ezdxf.new(dxfversion="R2010")
|
||||||
plate_msp = plate_doc.modelspace()
|
plate_msp = plate_doc.modelspace()
|
||||||
toml_dict = self._toml_dict
|
toml_dict = self._toml_dict
|
||||||
out_dxf_file_dir = toml_dict["parameter"]["out_dxf_file_dir"]
|
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):
|
for foo in range(len(excel_pfs) - 1):
|
||||||
start_point_name: str = excel_pfs.iloc[foo, 3]
|
start_point_name: str = excel_pfs.iloc[foo, 0]
|
||||||
end_point_name: str = excel_pfs.iloc[foo + 1, 3]
|
end_point_name: str = excel_pfs.iloc[foo + 1, 0]
|
||||||
point_x_s = float(excel_pfs.iloc[foo, 1])
|
point_x_s = float(excel_pfs.iloc[foo, 1])
|
||||||
point_y_s = float(excel_pfs.iloc[foo, 2])
|
point_y_s = float(excel_pfs.iloc[foo, 2])
|
||||||
point_x_e = float(excel_pfs.iloc[foo + 1, 1])
|
point_x_e = float(excel_pfs.iloc[foo + 1, 1])
|
||||||
|
|
@ -85,90 +79,35 @@ class Dem:
|
||||||
cord_0 = line_coordination[0, 2:4] # 取中线的
|
cord_0 = line_coordination[0, 2:4] # 取中线的
|
||||||
for cord in line_coordination[1:, 2:4]:
|
for cord in line_coordination[1:, 2:4]:
|
||||||
x_axis.append(dem_utils.distance(cord, cord_0))
|
x_axis.append(dem_utils.distance(cord, cord_0))
|
||||||
# 左边线
|
dm_msp.add_polyline2d(
|
||||||
left_line = [
|
[
|
||||||
(x_axis[i] / 5 / zoom_factor, left_elevation[i] * 2 / zoom_factor)
|
(x_axis[i] / 5, left_elevation[i] * 2)
|
||||||
for i in range(len(left_elevation))
|
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},
|
dxfattribs={"color": 1},
|
||||||
) # 红色
|
) # 红色
|
||||||
dm_msp.add_polyline2d(left_line, dxfattribs={"color": 1}) # 红色
|
dm_msp.add_polyline2d(
|
||||||
mid_line = [
|
[
|
||||||
(x_axis[i] / 5 / zoom_factor, center_elevation[i] * 2 / zoom_factor)
|
(x_axis[i] / 5, center_elevation[i] * 2)
|
||||||
for i in range(len(center_elevation))
|
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(
|
dm_msp.add_polyline2d(
|
||||||
right_line,
|
[
|
||||||
|
(x_axis[i] / 5, right_elevation[i] * 2)
|
||||||
|
for i in range(len(right_elevation))
|
||||||
|
],
|
||||||
dxfattribs={"color": 5},
|
dxfattribs={"color": 5},
|
||||||
) # 蓝色
|
) # 蓝色
|
||||||
# 树的线
|
# 树的线
|
||||||
# 考虑用最高边线的情况
|
# 考虑用最高边线的情况
|
||||||
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:
|
if self._tree_height > 0:
|
||||||
dm_whole_msp.add_polyline2d(
|
dm_msp.add_polyline2d(
|
||||||
np.array(tree_line)
|
[
|
||||||
+ np.hstack(
|
(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))
|
||||||
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)
|
os.makedirs(out_dxf_file_dir, exist_ok=True)
|
||||||
ezdxf.options.set(
|
ezdxf.options.set(
|
||||||
"odafc-addon",
|
"odafc-addon",
|
||||||
|
|
@ -183,16 +122,14 @@ class Dem:
|
||||||
replace=True,
|
replace=True,
|
||||||
) # 写断面文件
|
) # 写断面文件
|
||||||
# 写Z文件
|
# 写Z文件
|
||||||
z_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
|
with open(
|
||||||
with open(z_file_path, "w") as z_file:
|
f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}", "w"
|
||||||
|
) as z_file:
|
||||||
z_file.write("0 ")
|
z_file.write("0 ")
|
||||||
z_file.write(f"{center_elevation[0]*2} ")
|
z_file.write(f"{center_elevation[0]*2} ")
|
||||||
z_file.write("0 ")
|
z_file.write("0 ")
|
||||||
z_file.write("0 ")
|
z_file.write("0 ")
|
||||||
z_file.write(f"{center_elevation[0]*2-50}")
|
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(
|
plate_msp.add_polyline2d(
|
||||||
line_coordination[:, 0:2],
|
line_coordination[:, 0:2],
|
||||||
|
|
@ -234,13 +171,6 @@ class Dem:
|
||||||
segments, tower_start_num, control_file_template_path, out_dxf_file_dir
|
segments, tower_start_num, control_file_template_path, out_dxf_file_dir
|
||||||
)
|
)
|
||||||
c_file.save()
|
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")
|
plate_doc.saveas(f"{out_dxf_file_dir}/plate.dxf")
|
||||||
|
|
||||||
def get_elevation(self, site_x_y):
|
def get_elevation(self, site_x_y):
|
||||||
|
|
@ -327,6 +257,7 @@ class Dem:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
site_ele[i] = point_z
|
site_ele[i] = point_z
|
||||||
|
# print(f"row:{Yline} col:{Xpixel} elev:{site_ele[i]}")
|
||||||
pass
|
pass
|
||||||
return site_ele
|
return site_ele
|
||||||
|
|
||||||
|
|
@ -335,9 +266,7 @@ class Dem:
|
||||||
(point_x_s - point_x_e) ** 2 + (point_y_s - point_y_e) ** 2
|
(point_x_s - point_x_e) ** 2 + (point_y_s - point_y_e) ** 2
|
||||||
) ** 0.5
|
) ** 0.5
|
||||||
dem_resolution = self._dem_resolution # dem的精度
|
dem_resolution = self._dem_resolution # dem的精度
|
||||||
# TODO:设定为5m 1个点。
|
n = round(path_length / dem_resolution)
|
||||||
# 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_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)
|
center_point_y = np.linspace(point_y_s, point_y_e, n, endpoint=True)
|
||||||
# 计算左右边线
|
# 计算左右边线
|
||||||
|
|
|
||||||
2
pw.py
2
pw.py
|
|
@ -97,5 +97,5 @@ class ControlFile:
|
||||||
c_template = c_template.replace(
|
c_template = c_template.replace(
|
||||||
"{CONTROL_FILE}", f"S{segments[0]-4000+100}"
|
"{CONTROL_FILE}", f"S{segments[0]-4000+100}"
|
||||||
)
|
)
|
||||||
with open(f"{out_dir}/PW{segments[0]-4000+100}.dat", "w") as c_file:
|
with open(f"{out_dir}/C{segments[0]-4000+100}.dat", "w") as c_file:
|
||||||
c_file.write(c_template)
|
c_file.write(c_template)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue