Compare commits
10 Commits
b5e17a3b9e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0665a83a9c | ||
|
|
d7e16069db | ||
|
|
6caafc91a5 | ||
|
|
8c60899f8e | ||
|
|
dc7cb8fc8c | ||
|
|
1387aa277e | ||
|
|
363a14e98b | ||
|
|
34b7dfb9e0 | ||
|
|
057c199b18 | ||
|
|
308259306f |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -8,3 +8,9 @@ canva
|
|||||||
*.xls*
|
*.xls*
|
||||||
*.toml
|
*.toml
|
||||||
control_file_template.txt
|
control_file_template.txt
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
__pycache__
|
||||||
|
Lib
|
||||||
|
Scripts
|
||||||
|
example
|
||||||
|
|||||||
50
cad.py
Normal file
50
cad.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
from typing import List
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def convert_dxf_to_dwg(dxf_files: List[str]):
|
||||||
|
cad_file_path = r"D:/Program Files/Cad2022/AutoCAD 2022/accoreconsole.exe"
|
||||||
|
first_dwg_file = dxf_files[0]
|
||||||
|
dir_path = os.path.dirname(first_dwg_file)
|
||||||
|
script_path = f"{dir_path}/batch.scr"
|
||||||
|
for _, dxf in enumerate(dxf_files):
|
||||||
|
with open(script_path, "w", encoding="ansi") as f:
|
||||||
|
file_name_path, _ = os.path.splitext(dxf)
|
||||||
|
new_dwg_name = f"{file_name_path}.dwg"
|
||||||
|
if os.path.exists(new_dwg_name):
|
||||||
|
os.remove(new_dwg_name)
|
||||||
|
new_dwg_name = new_dwg_name.replace("//", "/")
|
||||||
|
f.write(f'saveas 2004 "{new_dwg_name}"\n')
|
||||||
|
cmd = rf'"{cad_file_path}" /s "{script_path}" /i "{dxf}" /iso'
|
||||||
|
cmd = cmd.replace("//", "/")
|
||||||
|
subprocess.call(
|
||||||
|
cmd,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_dxf_to_dwg1(dxf_files: List[str]):
|
||||||
|
cad_file_path = r"D:/Program Files/Cad2022/AutoCAD 2022/acad.exe"
|
||||||
|
first_dwg_file = dxf_files[0]
|
||||||
|
dir_path = os.path.dirname(first_dwg_file)
|
||||||
|
script_path = f"{dir_path}/batch.scr"
|
||||||
|
with open(script_path, "w", encoding="ansi") as f:
|
||||||
|
f.write("FILEDIA 0\n")
|
||||||
|
for ind, dxf in enumerate(dxf_files):
|
||||||
|
f.write(f'_open "{dxf}"\n')
|
||||||
|
file_name_path, _ = os.path.splitext(dxf)
|
||||||
|
new_dwg_name = f"{file_name_path}.dwg"
|
||||||
|
if os.path.exists(new_dwg_name):
|
||||||
|
os.remove(new_dwg_name)
|
||||||
|
f.write(f'saveas 2004 "{new_dwg_name}"\n')
|
||||||
|
if ind == len(dxf_files) - 1:
|
||||||
|
f.write("FILEDIA 1\n") # 最后一个回复打开dialog
|
||||||
|
f.write("qquit\n")
|
||||||
|
else:
|
||||||
|
f.write(f"_close\n")
|
||||||
|
# f.write("qquit\n")
|
||||||
|
cmd = rf'"{cad_file_path}" /b "{script_path}"'
|
||||||
|
subprocess.Popen(cmd)
|
||||||
196
dem.py
196
dem.py
@@ -8,6 +8,8 @@ import numpy as np
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from pw import DFile, ControlFile
|
from pw import DFile, ControlFile
|
||||||
import dem_utils
|
import dem_utils
|
||||||
|
from nwed import Nwed
|
||||||
|
import cad
|
||||||
|
|
||||||
|
|
||||||
class Dem:
|
class Dem:
|
||||||
@@ -45,16 +47,23 @@ 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(self):
|
||||||
|
# TODO:不应该设置缩放因数
|
||||||
|
dxfs = []
|
||||||
|
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="R2010")
|
||||||
|
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, 0]
|
start_point_name: str = excel_pfs.iloc[foo, 3]
|
||||||
end_point_name: str = excel_pfs.iloc[foo + 1, 0]
|
end_point_name: str = excel_pfs.iloc[foo + 1, 3]
|
||||||
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])
|
||||||
@@ -65,7 +74,7 @@ class Dem:
|
|||||||
left_elevation = self.get_elevation(line_coordination[:, 0:2])
|
left_elevation = self.get_elevation(line_coordination[:, 0:2])
|
||||||
center_elevation = self.get_elevation(line_coordination[:, 2:4])
|
center_elevation = self.get_elevation(line_coordination[:, 2:4])
|
||||||
right_elevation = self.get_elevation(line_coordination[:, 4:6])
|
right_elevation = self.get_elevation(line_coordination[:, 4:6])
|
||||||
dm_doc = ezdxf.new(dxfversion="R2004")
|
dm_doc = ezdxf.new(dxfversion="R2010")
|
||||||
# 设置线形
|
# 设置线形
|
||||||
# for name, desc, pattern in linetypes():
|
# for name, desc, pattern in linetypes():
|
||||||
# if name not in dm_doc.linetypes:
|
# if name not in dm_doc.linetypes:
|
||||||
@@ -76,60 +85,123 @@ class Dem:
|
|||||||
# )
|
# )
|
||||||
dm_msp = dm_doc.modelspace()
|
dm_msp = dm_doc.modelspace()
|
||||||
x_axis = [0]
|
x_axis = [0]
|
||||||
cord_0 = line_coordination[0, 2:4] # 取中线的
|
cord_0 = line_coordination[0, 2:4] # 取中线的x轴作为横坐标
|
||||||
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, left_elevation[i] * 2)
|
(x_axis[i] / 5 / zoom_factor, left_elevation[i] * 2 / zoom_factor)
|
||||||
for i in range(len(left_elevation))
|
for i in range(len(left_elevation))
|
||||||
],
|
]
|
||||||
|
# dm_whole_msp.add_polyline2d([[0,0],[100,100]])
|
||||||
|
# dm_doc.saveas('f.dxf')
|
||||||
|
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(
|
dm_msp.add_polyline2d(left_line, dxfattribs={"color": 1}) # 红色
|
||||||
[
|
mid_line = [
|
||||||
(x_axis[i] / 5, center_elevation[i] * 2)
|
(x_axis[i] / 5 / zoom_factor, center_elevation[i] * 2 / zoom_factor)
|
||||||
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},
|
||||||
) # 蓝色
|
) # 蓝色
|
||||||
# 树的线
|
# 树的线
|
||||||
# 考虑用最高边线的情况
|
# 考虑用最高边线的情况
|
||||||
if self._tree_height > 0:
|
tree_line = [
|
||||||
dm_msp.add_polyline2d(
|
(
|
||||||
[
|
x_axis[i] / 5 / zoom_factor,
|
||||||
(x_axis[i] / 5, ( np.max( (center_elevation[i],left_elevation[i],right_elevation[i])) + self._tree_height) * 2)
|
(
|
||||||
|
np.max(
|
||||||
|
(
|
||||||
|
center_elevation[i],
|
||||||
|
left_elevation[i],
|
||||||
|
right_elevation[i],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
+ self._tree_height
|
||||||
|
)
|
||||||
|
* 2
|
||||||
|
/ zoom_factor,
|
||||||
|
)
|
||||||
for i in range(len(center_elevation))
|
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)
|
os.makedirs(out_dxf_file_dir, exist_ok=True)
|
||||||
ezdxf.options.set(
|
# ezdxf.options.set(
|
||||||
"odafc-addon",
|
# "odafc-addon",
|
||||||
"win_exec_path",
|
# "win_exec_path",
|
||||||
"d:/ProgramFiles/ODAFileConverter/ODAFileConverter.exe",
|
# "d:/ProgramFiles/ODAFileConverter/ODAFileConverter.exe",
|
||||||
)
|
# )
|
||||||
from ezdxf.addons.odafc import export_dwg
|
# TODO 去掉odafc依赖
|
||||||
|
# from ezdxf.addons.odafc import export_dwg
|
||||||
|
|
||||||
export_dwg(
|
# export_dwg(
|
||||||
dm_doc,
|
# dm_doc,
|
||||||
f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dwg",
|
# f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dwg",
|
||||||
replace=True,
|
# replace=True,
|
||||||
) # 写断面文件
|
# ) # 写断面文件
|
||||||
|
dm_doc_dxf = f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dxf"
|
||||||
|
dm_doc.saveas(dm_doc_dxf)
|
||||||
|
dxfs.append(dm_doc_dxf)
|
||||||
# 写Z文件
|
# 写Z文件
|
||||||
with open(
|
z_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
|
||||||
f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}", "w"
|
with open(z_file_path, "w") as z_file:
|
||||||
) 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],
|
||||||
@@ -171,7 +243,51 @@ 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()
|
||||||
plate_doc.saveas(f"{out_dxf_file_dir}/plate.dxf")
|
##################
|
||||||
|
##################
|
||||||
|
# 写nwed
|
||||||
|
section_name = f"{100+int(start_point_name[1:])}"
|
||||||
|
licheng = f"{mileage[-1]}"
|
||||||
|
remarks_start = f"{int(start_point_name[1:])}"
|
||||||
|
pole_name_start = f"{start_num}"
|
||||||
|
remarks_end = f"{int(end_point_name[1:])}"
|
||||||
|
pole_name_end = f"{end_num}"
|
||||||
|
toml_dict = self._toml_dict
|
||||||
|
side_width = toml_dict["parameter"]["side_width"] # 边线宽度
|
||||||
|
verticalExtent2 = f"{side_width}"
|
||||||
|
mid_vec_list = list(map(lambda x: [f"{x[0]*5}", f"{x[1]/2}"], mid_line))
|
||||||
|
right_vec_list = list(map(lambda x: [f"{x[0]*5}", f"{x[1]/2}"], right_line))
|
||||||
|
left_vec_list = list(map(lambda x: [f"{x[0]*5}", f"{x[1]/2}"], left_line))
|
||||||
|
nwed = Nwed(
|
||||||
|
section_name,
|
||||||
|
licheng,
|
||||||
|
remarks_start,
|
||||||
|
pole_name_start,
|
||||||
|
remarks_end,
|
||||||
|
pole_name_end,
|
||||||
|
verticalExtent2,
|
||||||
|
mid_vec_list,
|
||||||
|
right_vec_list,
|
||||||
|
left_vec_list,
|
||||||
|
)
|
||||||
|
nwed.write(
|
||||||
|
f"{out_dxf_file_dir}/{100+int(start_point_name[1:])}.nwed",
|
||||||
|
)
|
||||||
|
# 写整个断面文件
|
||||||
|
# export_dwg(
|
||||||
|
# dm_whole_doc,
|
||||||
|
# f"{out_dxf_file_dir}/DA.dwg",
|
||||||
|
# replace=True,
|
||||||
|
# )
|
||||||
|
dm_whole_doc_dxf = f"{out_dxf_file_dir}/DA.dxf"
|
||||||
|
dm_whole_doc.saveas(dm_whole_doc_dxf)
|
||||||
|
# cad.convert_dxf_to_dwg([f"{out_dxf_file_dir}/DA.dxf"])
|
||||||
|
dxfs.append(dm_whole_doc_dxf)
|
||||||
|
# 写平面文件
|
||||||
|
plate_doc_dxf = f"{out_dxf_file_dir}/plate.dxf"
|
||||||
|
plate_doc.saveas(plate_doc_dxf)
|
||||||
|
dxfs.append(plate_doc_dxf)
|
||||||
|
cad.convert_dxf_to_dwg(dxf_files=dxfs)
|
||||||
|
|
||||||
def get_elevation(self, site_x_y):
|
def get_elevation(self, site_x_y):
|
||||||
"""Get the elevation of given locations from DEM in GCS.
|
"""Get the elevation of given locations from DEM in GCS.
|
||||||
@@ -257,7 +373,6 @@ 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
|
||||||
|
|
||||||
@@ -265,8 +380,11 @@ class Dem:
|
|||||||
path_length = (
|
path_length = (
|
||||||
(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的精度
|
||||||
|
dem_resolution = 5
|
||||||
|
# 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)
|
||||||
# 计算左右边线
|
# 计算左右边线
|
||||||
@@ -282,7 +400,9 @@ class Dem:
|
|||||||
left_offset_y = side_width * math.sin(line_angel + math.pi / 2)
|
left_offset_y = side_width * math.sin(line_angel + math.pi / 2)
|
||||||
left_offset_point_x = center_point_x + left_offset_x
|
left_offset_point_x = center_point_x + left_offset_x
|
||||||
left_offset_point_y = center_point_y + left_offset_y
|
left_offset_point_y = center_point_y + left_offset_y
|
||||||
right_offset_point_x = center_point_x - left_offset_x # 向左偏移和向右偏移正好是相反的
|
right_offset_point_x = (
|
||||||
|
center_point_x - left_offset_x
|
||||||
|
) # 向左偏移和向右偏移正好是相反的
|
||||||
right_offset_point_y = center_point_y - left_offset_y
|
right_offset_point_y = center_point_y - left_offset_y
|
||||||
r = np.array(
|
r = np.array(
|
||||||
[
|
[
|
||||||
|
|||||||
4
main.py
4
main.py
@@ -3,11 +3,11 @@ from dem import Dem
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
toml_file_path = r"db_JS.toml"
|
toml_file_path = r"db_山地750.toml"
|
||||||
else:
|
else:
|
||||||
toml_file_path = sys.argv[1]
|
toml_file_path = sys.argv[1]
|
||||||
logger.info(f'读取配置文件{toml_file_path}')
|
logger.info(f'读取配置文件{toml_file_path}')
|
||||||
dem = Dem(toml_file_path)
|
dem = Dem(toml_file_path)
|
||||||
dem.get_dem_info(if_print=True)
|
dem.get_dem_info(if_print=True)
|
||||||
dem.write_dxf()
|
dem.write()
|
||||||
print("Finished.")
|
print("Finished.")
|
||||||
|
|||||||
182
nwed.py
Normal file
182
nwed.py
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
from xml.etree.ElementTree import Element
|
||||||
|
from xml.etree.ElementTree import ElementTree
|
||||||
|
from xml.etree.ElementTree import SubElement
|
||||||
|
import attrs
|
||||||
|
from typing import List, Tuple
|
||||||
|
|
||||||
|
|
||||||
|
@attrs.define
|
||||||
|
class Nwed:
|
||||||
|
# section_name = "002"
|
||||||
|
# licheng = "100"
|
||||||
|
# remarks_start = "002"
|
||||||
|
# pole_name_start = "4001"
|
||||||
|
# remarks_end = "003"
|
||||||
|
# pole_name_end = "4002"
|
||||||
|
# verticalExtent2 = "20" # 边线宽度
|
||||||
|
section_name: str
|
||||||
|
licheng: str
|
||||||
|
remarks_start: str
|
||||||
|
pole_name_start: str
|
||||||
|
remarks_end: str
|
||||||
|
pole_name_end: str
|
||||||
|
verticalExtent2: str # 边线宽度
|
||||||
|
mid_vec_list: List[List[str]]
|
||||||
|
right_vec_list: List[List[str]]
|
||||||
|
left_vec_list: List[List[str]]
|
||||||
|
|
||||||
|
def indent(self, elem, level=0):
|
||||||
|
i = "\n" + level * "\t"
|
||||||
|
if len(elem):
|
||||||
|
if not elem.text or not elem.text.strip():
|
||||||
|
elem.text = i + "\t"
|
||||||
|
if not elem.tail or not elem.tail.strip():
|
||||||
|
elem.tail = i
|
||||||
|
for elem in elem:
|
||||||
|
self.indent(elem, level + 1)
|
||||||
|
if not elem.tail or not elem.tail.strip():
|
||||||
|
elem.tail = i
|
||||||
|
else:
|
||||||
|
if level and (not elem.tail or not elem.tail.strip()):
|
||||||
|
elem.tail = i
|
||||||
|
|
||||||
|
def AddEleElevationCurve(
|
||||||
|
self, elevationCurves, id, vec_list, curve_id, curve_side=None
|
||||||
|
):
|
||||||
|
if curve_side:
|
||||||
|
elevationCurve_attribs = {"ID": id, "CurveSide": curve_side}
|
||||||
|
else:
|
||||||
|
elevationCurve_attribs = {"ID": id}
|
||||||
|
elevationCurve = SubElement(
|
||||||
|
elevationCurves, "EleElevationCurve", attrib=elevationCurve_attribs
|
||||||
|
) # 中线
|
||||||
|
SubElement(elevationCurve, "GrowthHeight").text = "0"
|
||||||
|
SubElement(elevationCurve, "LinkedSectionObjectID_Group")
|
||||||
|
SubElement(elevationCurve, "wallheight").text = "0"
|
||||||
|
segmentList = SubElement(elevationCurve, "SegmentList")
|
||||||
|
eleElevationCurveSegment = SubElement(
|
||||||
|
segmentList,
|
||||||
|
"EleElevationCurveSegment",
|
||||||
|
# TODO 这个ID其实依据中、边导线会变化。
|
||||||
|
attrib={
|
||||||
|
"ID": curve_id,
|
||||||
|
"StartPointClass": "NotSet",
|
||||||
|
"EndPointClass": "NotSet",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
SubElement(eleElevationCurveSegment, "GrowthHeight").text = "0"
|
||||||
|
SubElement(eleElevationCurveSegment, "LinkedSectionObjectID_Group")
|
||||||
|
vec_list_element = SubElement(eleElevationCurveSegment, "VecList")
|
||||||
|
for vec in vec_list:
|
||||||
|
SubElement(vec_list_element, "Vector3", attrib={"xyz": ",".join(vec)})
|
||||||
|
vec_list_rendering_element = SubElement(
|
||||||
|
eleElevationCurveSegment, "VecListRendering"
|
||||||
|
)
|
||||||
|
for vec in vec_list:
|
||||||
|
SubElement(
|
||||||
|
vec_list_rendering_element, "Vector3", attrib={"xyz": ",".join(vec)}
|
||||||
|
)
|
||||||
|
return elevationCurve
|
||||||
|
|
||||||
|
def AddAnnotationElements(self, sectionData, pole_attrib, xyz):
|
||||||
|
pdmGraphicsObject = SubElement(
|
||||||
|
sectionData, "PdmGraphicsObject", attrib=pole_attrib
|
||||||
|
)
|
||||||
|
SubElement(pdmGraphicsObject, "GrowthHeight").text = "0"
|
||||||
|
SubElement(pdmGraphicsObject, "LinkedSectionObjectID_Group")
|
||||||
|
SubElement(pdmGraphicsObject, "Position", attrib={"xyz": xyz})
|
||||||
|
|
||||||
|
def write(self, xml_path):
|
||||||
|
root = Element(
|
||||||
|
"OverheadTransmissionLineDrawing",
|
||||||
|
attrib={
|
||||||
|
"Name": self.section_name,
|
||||||
|
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
|
||||||
|
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
|
||||||
|
"Description": "",
|
||||||
|
"Version": "1.0",
|
||||||
|
"StartAngle": "0",
|
||||||
|
"EndAngle": "0",
|
||||||
|
"NextID": "9",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
SubElement(root, "lstCrossingCable")
|
||||||
|
drawingFrames = SubElement(root, "DrawingFrames", attrib={"PaperSizeId": "0"})
|
||||||
|
SubElement(drawingFrames, "GrowthHeight").text = "0"
|
||||||
|
SubElement(drawingFrames, "LinkedSectionObjectID_Group")
|
||||||
|
frames = SubElement(drawingFrames, "Frames")
|
||||||
|
frame = SubElement(
|
||||||
|
frames,
|
||||||
|
"Frame",
|
||||||
|
attrib={
|
||||||
|
"Name": "完整图纸",
|
||||||
|
"SplitterPosition": "0",
|
||||||
|
"PaperOrientation": "Landscape",
|
||||||
|
"UserVerticalOffset": "0",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
SubElement(frame, "GrowthHeight").text = "0"
|
||||||
|
SubElement(frame, "LinkedSectionObjectID_Group")
|
||||||
|
elevAdjSections = SubElement(frame, "ElevAdjSections")
|
||||||
|
SubElement(elevAdjSections, "GrowthHeight").text = "0"
|
||||||
|
SubElement(elevAdjSections, "LinkedSectionObjectID_Group")
|
||||||
|
sections = SubElement(elevAdjSections, "Sections")
|
||||||
|
SubElement(
|
||||||
|
sections,
|
||||||
|
"ElevationAdjSection",
|
||||||
|
attrib={"Position": "0", "ElevationAjusting": "0"},
|
||||||
|
)
|
||||||
|
SubElement(root, "GPSPointGroups")
|
||||||
|
SubElement(root, "Orthoimages")
|
||||||
|
SubElement(root, "GPSXianGao")
|
||||||
|
SubElement(root, "HouseSwing")
|
||||||
|
sectionData = SubElement(root, "SectionData")
|
||||||
|
SubElement(sectionData, "licheng").text = self.licheng
|
||||||
|
SubElement(sectionData, "lstlicheng")
|
||||||
|
SubElement(sectionData, "lstSctnRcd")
|
||||||
|
SubElement(sectionData, "ForestElevationCurves")
|
||||||
|
elevationCurves = SubElement(sectionData, "ElevationCurves")
|
||||||
|
self.AddEleElevationCurve(elevationCurves, "1", self.mid_vec_list, "4")
|
||||||
|
self.AddEleElevationCurve(elevationCurves, "2", self.left_vec_list, "5", "Left")
|
||||||
|
self.AddEleElevationCurve(
|
||||||
|
elevationCurves, "3", self.right_vec_list, "6", "Right"
|
||||||
|
)
|
||||||
|
annotationElements = SubElement(sectionData, "AnnotationElements")
|
||||||
|
self.AddAnnotationElements(
|
||||||
|
annotationElements,
|
||||||
|
{
|
||||||
|
"xsi:type": "ElePowerLinePole",
|
||||||
|
"ID": "7",
|
||||||
|
"CurveSide": "All",
|
||||||
|
"Remarks": self.remarks_start,
|
||||||
|
"PoleType": "AnglePole",
|
||||||
|
"LeftElevation": "0",
|
||||||
|
"RightElevation": "0",
|
||||||
|
"CableAngle": "0",
|
||||||
|
"PoleName": self.pole_name_start,
|
||||||
|
},
|
||||||
|
xyz=",".join(self.mid_vec_list[0]),
|
||||||
|
)
|
||||||
|
self.AddAnnotationElements(
|
||||||
|
annotationElements,
|
||||||
|
{
|
||||||
|
"xsi:type": "ElePowerLinePole",
|
||||||
|
"ID": "8",
|
||||||
|
"CurveSide": "All",
|
||||||
|
"Remarks": self.remarks_end,
|
||||||
|
"PoleType": "AnglePole",
|
||||||
|
"LeftElevation": "0",
|
||||||
|
"RightElevation": "0",
|
||||||
|
"CableAngle": "0",
|
||||||
|
"PoleName": self.pole_name_end,
|
||||||
|
},
|
||||||
|
xyz=",".join(self.mid_vec_list[-1]),
|
||||||
|
)
|
||||||
|
mapData = SubElement(root, "MapData")
|
||||||
|
SubElement(mapData, "GrowthHeight").text = "0"
|
||||||
|
SubElement(mapData, "LinkedSectionObjectID_Group")
|
||||||
|
SubElement(mapData, "verticalExtent2").text = self.verticalExtent2
|
||||||
|
SubElement(mapData, "MapElements")
|
||||||
|
tree = ElementTree(root)
|
||||||
|
self.indent(root)
|
||||||
|
tree.write(xml_path, encoding="utf-8", xml_declaration=True)
|
||||||
3
pw.py
3
pw.py
@@ -97,5 +97,6 @@ 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}/C{segments[0]-4000+100}.dat", "w") as c_file:
|
# with open(f"{out_dir}/PW{segments[0]-4000+1}.dat", "w") as c_file:
|
||||||
|
with open(f"{out_dir}/PW01.dat", "w") as c_file:
|
||||||
c_file.write(c_template)
|
c_file.write(c_template)
|
||||||
|
|||||||
Reference in New Issue
Block a user