Compare commits
6 Commits
057c199b18
...
6caafc91a5
| Author | SHA1 | Date |
|---|---|---|
|
|
6caafc91a5 | |
|
|
8c60899f8e | |
|
|
dc7cb8fc8c | |
|
|
1387aa277e | |
|
|
363a14e98b | |
|
|
34b7dfb9e0 |
|
|
@ -8,3 +8,9 @@ canva
|
|||
*.xls*
|
||||
*.toml
|
||||
control_file_template.txt
|
||||
.idea
|
||||
.vscode
|
||||
__pycache__
|
||||
Lib
|
||||
Scripts
|
||||
example
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
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)
|
||||
f.write(f'saveas 2004 "{new_dwg_name}"\n')
|
||||
cmd = rf'"{cad_file_path}" /s "{script_path}" /i "{dxf}" /iso'
|
||||
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)
|
||||
86
dem.py
86
dem.py
|
|
@ -8,6 +8,8 @@ import numpy as np
|
|||
import pandas as pd
|
||||
from pw import DFile, ControlFile
|
||||
import dem_utils
|
||||
from nwed import Nwed
|
||||
import cad
|
||||
|
||||
|
||||
class Dem:
|
||||
|
|
@ -45,8 +47,9 @@ class Dem:
|
|||
|
||||
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()
|
||||
segments = []
|
||||
|
|
@ -82,7 +85,7 @@ class Dem:
|
|||
# )
|
||||
dm_msp = dm_doc.modelspace()
|
||||
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]:
|
||||
x_axis.append(dem_utils.distance(cord, cord_0))
|
||||
# 左边线
|
||||
|
|
@ -170,18 +173,22 @@ class Dem:
|
|||
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",
|
||||
"win_exec_path",
|
||||
"d:/ProgramFiles/ODAFileConverter/ODAFileConverter.exe",
|
||||
)
|
||||
from ezdxf.addons.odafc import export_dwg
|
||||
# ezdxf.options.set(
|
||||
# "odafc-addon",
|
||||
# "win_exec_path",
|
||||
# "d:/ProgramFiles/ODAFileConverter/ODAFileConverter.exe",
|
||||
# )
|
||||
# TODO 去掉odafc依赖
|
||||
# from ezdxf.addons.odafc import export_dwg
|
||||
|
||||
export_dwg(
|
||||
dm_doc,
|
||||
f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dwg",
|
||||
replace=True,
|
||||
) # 写断面文件
|
||||
# export_dwg(
|
||||
# dm_doc,
|
||||
# f"{out_dxf_file_dir}/D{100+int(start_point_name[1:])}.dwg",
|
||||
# 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_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
|
||||
with open(z_file_path, "w") as z_file:
|
||||
|
|
@ -234,14 +241,51 @@ class Dem:
|
|||
segments, tower_start_num, control_file_template_path, out_dxf_file_dir
|
||||
)
|
||||
c_file.save()
|
||||
##################
|
||||
##################
|
||||
# 写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,
|
||||
)
|
||||
# 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.saveas(f"{out_dxf_file_dir}/plate.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):
|
||||
"""Get the elevation of given locations from DEM in GCS.
|
||||
|
|
@ -336,8 +380,8 @@ class Dem:
|
|||
) ** 0.5
|
||||
dem_resolution = self._dem_resolution # dem的精度
|
||||
# TODO:设定为5m 1个点。
|
||||
# n = round(path_length / dem_resolution)
|
||||
n = round(path_length / 5)
|
||||
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)
|
||||
# 计算左右边线
|
||||
|
|
|
|||
4
main.py
4
main.py
|
|
@ -3,11 +3,11 @@ from dem import Dem
|
|||
from loguru import logger
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
toml_file_path = r"db_JS.toml"
|
||||
toml_file_path = r"db_山地750.toml"
|
||||
else:
|
||||
toml_file_path = sys.argv[1]
|
||||
logger.info(f'读取配置文件{toml_file_path}')
|
||||
dem = Dem(toml_file_path)
|
||||
dem.get_dem_info(if_print=True)
|
||||
dem.write_dxf()
|
||||
dem.write()
|
||||
print("Finished.")
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
"{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}/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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue