Compare commits
No commits in common. "6caafc91a5c4f6b4db1d1ac58f8cdcb7545f0cec" and "057c199b18efb43c883802cb8d013ffae9e5dbbb" have entirely different histories.
6caafc91a5
...
057c199b18
|
|
@ -8,9 +8,3 @@ canva
|
||||||
*.xls*
|
*.xls*
|
||||||
*.toml
|
*.toml
|
||||||
control_file_template.txt
|
control_file_template.txt
|
||||||
.idea
|
|
||||||
.vscode
|
|
||||||
__pycache__
|
|
||||||
Lib
|
|
||||||
Scripts
|
|
||||||
example
|
|
||||||
|
|
|
||||||
44
cad.py
44
cad.py
|
|
@ -1,44 +0,0 @@
|
||||||
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,8 +8,6 @@ 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:
|
||||||
|
|
@ -47,9 +45,8 @@ 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(self):
|
def write_dxf(self):
|
||||||
# TODO:不应该设置缩放因数
|
# TODO:不应该设置缩放因数
|
||||||
dxfs = []
|
|
||||||
zoom_factor = 1
|
zoom_factor = 1
|
||||||
excel_pfs = self._read_path_file()
|
excel_pfs = self._read_path_file()
|
||||||
segments = []
|
segments = []
|
||||||
|
|
@ -85,7 +82,7 @@ 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] # 取中线的x轴作为横坐标
|
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))
|
||||||
# 左边线
|
# 左边线
|
||||||
|
|
@ -173,22 +170,18 @@ class Dem:
|
||||||
dm_msp.add_polyline2d(tree_line, dxfattribs={"color": 5})
|
dm_msp.add_polyline2d(tree_line, dxfattribs={"color": 5})
|
||||||
dm_whole_accumulative_distance += x_axis[-1]
|
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",
|
||||||
# )
|
)
|
||||||
# TODO 去掉odafc依赖
|
from ezdxf.addons.odafc import export_dwg
|
||||||
# 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文件
|
||||||
z_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
|
z_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
|
||||||
with open(z_file_path, "w") as z_file:
|
with open(z_file_path, "w") as z_file:
|
||||||
|
|
@ -241,51 +234,14 @@ 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()
|
||||||
##################
|
|
||||||
##################
|
|
||||||
# 写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(
|
export_dwg(
|
||||||
# dm_whole_doc,
|
dm_whole_doc,
|
||||||
# f"{out_dxf_file_dir}/DA.dwg",
|
f"{out_dxf_file_dir}/DA.dwg",
|
||||||
# replace=True,
|
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(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.
|
||||||
|
|
@ -380,8 +336,8 @@ class Dem:
|
||||||
) ** 0.5
|
) ** 0.5
|
||||||
dem_resolution = self._dem_resolution # dem的精度
|
dem_resolution = self._dem_resolution # dem的精度
|
||||||
# TODO:设定为5m 1个点。
|
# TODO:设定为5m 1个点。
|
||||||
n = round(path_length / dem_resolution)
|
# n = round(path_length / dem_resolution)
|
||||||
# n = round(path_length / 5)
|
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)
|
||||||
# 计算左右边线
|
# 计算左右边线
|
||||||
|
|
|
||||||
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_山地750.toml"
|
toml_file_path = r"db_JS.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()
|
dem.write_dxf()
|
||||||
print("Finished.")
|
print("Finished.")
|
||||||
|
|
|
||||||
182
nwed.py
182
nwed.py
|
|
@ -1,182 +0,0 @@
|
||||||
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,6 +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+1}.dat", "w") as c_file:
|
with open(f"{out_dir}/PW{segments[0]-4000+100}.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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue