完成了同时导出nwed文件的功能。

This commit is contained in:
n3040 2024-01-29 00:21:46 +08:00
parent 34b7dfb9e0
commit 363a14e98b
3 changed files with 208 additions and 149 deletions

35
dem.py
View File

@ -8,6 +8,7 @@ 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
class Dem: class Dem:
@ -45,7 +46,7 @@ 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:不应该设置缩放因数 # TODO:不应该设置缩放因数
zoom_factor = 1 zoom_factor = 1
excel_pfs = self._read_path_file() excel_pfs = self._read_path_file()
@ -82,7 +83,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] # 取中线的 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))
# 左边线 # 左边线
@ -234,6 +235,36 @@ 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,

319
nwed.py
View File

@ -1,155 +1,182 @@
from xml.etree.ElementTree import Element from xml.etree.ElementTree import Element
from xml.etree.ElementTree import ElementTree from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import SubElement from xml.etree.ElementTree import SubElement
import attrs
from typing import List, Tuple
def indent(elem, level=0): @attrs.define
i = "\n" + level * "\t" class Nwed:
if len(elem): # section_name = "002"
if not elem.text or not elem.text.strip(): # licheng = "100"
elem.text = i + "\t" # remarks_start = "002"
if not elem.tail or not elem.tail.strip(): # pole_name_start = "4001"
elem.tail = i # remarks_end = "003"
for elem in elem: # pole_name_end = "4002"
indent(elem, level + 1) # verticalExtent2 = "20" # 边线宽度
if not elem.tail or not elem.tail.strip(): section_name: str
elem.tail = i licheng: str
else: remarks_start: str
if level and (not elem.tail or not elem.tail.strip()): pole_name_start: str
elem.tail = i 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(elevationCurves, id, vec_list, curve_side=None): def AddEleElevationCurve(
if curve_side: self, elevationCurves, id, vec_list, curve_id, curve_side=None
elevationCurve_attribs = {"ID": id, "CurveSide": curve_side} ):
else: if curve_side:
elevationCurve_attribs = {"ID": id} elevationCurve_attribs = {"ID": id, "CurveSide": curve_side}
elevationCurve = SubElement( else:
elevationCurves, "EleElevationCurve", attrib=elevationCurve_attribs elevationCurve_attribs = {"ID": id}
) # 中线 elevationCurve = SubElement(
SubElement(elevationCurve, "GrowthHeight").text = "0" elevationCurves, "EleElevationCurve", attrib=elevationCurve_attribs
SubElement(elevationCurve, "LinkedSectionObjectID_Group") ) # 中线
SubElement(elevationCurve, "wallheight").text = "0" SubElement(elevationCurve, "GrowthHeight").text = "0"
segmentList = SubElement(elevationCurve, "SegmentList") SubElement(elevationCurve, "LinkedSectionObjectID_Group")
eleElevationCurveSegment = SubElement( SubElement(elevationCurve, "wallheight").text = "0"
segmentList, segmentList = SubElement(elevationCurve, "SegmentList")
"EleElevationCurveSegment", eleElevationCurveSegment = SubElement(
# TODO 这个ID其实依据中、边导线会变化。 segmentList,
attrib={"ID": "4", "StartPointClass": "NotSet", "EndPointClass": "NotSet"}, "EleElevationCurveSegment",
) # TODO 这个ID其实依据中、边导线会变化。
SubElement(eleElevationCurveSegment, "GrowthHeight").text = "0" attrib={
SubElement(eleElevationCurveSegment, "LinkedSectionObjectID_Group") "ID": curve_id,
vec_list_element = SubElement(eleElevationCurveSegment, "VecList") "StartPointClass": "NotSet",
for vec in vec_list: "EndPointClass": "NotSet",
SubElement(vec_list_element, "Vector3", attrib={"xyz": ",".join(vec)}) },
vec_list_rendering_element = SubElement( )
eleElevationCurveSegment, "VecListRendering" SubElement(eleElevationCurveSegment, "GrowthHeight").text = "0"
) SubElement(eleElevationCurveSegment, "LinkedSectionObjectID_Group")
for vec in vec_list: vec_list_element = SubElement(eleElevationCurveSegment, "VecList")
SubElement(vec_list_rendering_element, "Vector3", attrib={"xyz": ",".join(vec)}) for vec in vec_list:
return elevationCurve 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 AddAnnotationElements(sectionData, pole_attrib, xyz): def write(self, xml_path):
pdmGraphicsObject = SubElement(sectionData, "PdmGraphicsObject", attrib=pole_attrib) root = Element(
SubElement(pdmGraphicsObject, "GrowthHeight").text = "0" "OverheadTransmissionLineDrawing",
SubElement(pdmGraphicsObject, "LinkedSectionObjectID_Group") attrib={
SubElement(pdmGraphicsObject, "Position", attrib={"xyz": xyz}) "Name": self.section_name,
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
section_name = "002" "Description": "",
licheng = "100" "Version": "1.0",
remarks_start = "002" "StartAngle": "0",
pole_name_start = "4001" "EndAngle": "0",
remarks_end = "003" "NextID": "9",
pole_name_end = "4002" },
verticalExtent2 = "20" # 边线宽度 )
root = Element( SubElement(root, "lstCrossingCable")
"OverheadTransmissionLineDrawing", drawingFrames = SubElement(root, "DrawingFrames", attrib={"PaperSizeId": "0"})
attrib={ SubElement(drawingFrames, "GrowthHeight").text = "0"
"Name": section_name, SubElement(drawingFrames, "LinkedSectionObjectID_Group")
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", frames = SubElement(drawingFrames, "Frames")
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema", frame = SubElement(
"Description": "", frames,
"Version": "1.0", "Frame",
"StartAngle": "0", attrib={
"EndAngle": "0", "Name": "完整图纸",
"NextID": "9", "SplitterPosition": "0",
}, "PaperOrientation": "Landscape",
) "UserVerticalOffset": "0",
SubElement(root, "lstCrossingCable") },
drawingFrames = SubElement(root, "DrawingFrames", attrib={"PaperSizeId": "0"}) )
SubElement(drawingFrames, "GrowthHeight").text = "0" SubElement(frame, "GrowthHeight").text = "0"
SubElement(drawingFrames, "LinkedSectionObjectID_Group") SubElement(frame, "LinkedSectionObjectID_Group")
frames = SubElement(drawingFrames, "Frames") elevAdjSections = SubElement(frame, "ElevAdjSections")
frame = SubElement( SubElement(elevAdjSections, "GrowthHeight").text = "0"
frames, SubElement(elevAdjSections, "LinkedSectionObjectID_Group")
"Frame", sections = SubElement(elevAdjSections, "Sections")
attrib={ SubElement(
"Name": "完整图纸", sections,
"SplitterPosition": "0", "ElevationAdjSection",
"PaperOrientation": "Landscape", attrib={"Position": "0", "ElevationAjusting": "0"},
"UserVerticalOffset": "0", )
}, SubElement(root, "GPSPointGroups")
) SubElement(root, "Orthoimages")
SubElement(frame, "GrowthHeight").text = "0" SubElement(root, "GPSXianGao")
SubElement(frame, "LinkedSectionObjectID_Group") SubElement(root, "HouseSwing")
elevAdjSections = SubElement(frame, "ElevAdjSections") sectionData = SubElement(root, "SectionData")
SubElement(elevAdjSections, "GrowthHeight").text = "0" SubElement(sectionData, "licheng").text = self.licheng
SubElement(elevAdjSections, "LinkedSectionObjectID_Group") SubElement(sectionData, "lstlicheng")
sections = SubElement(elevAdjSections, "Sections") SubElement(sectionData, "lstSctnRcd")
SubElement( SubElement(sectionData, "ForestElevationCurves")
sections, "ElevationAdjSection", attrib={"Position": "0", "ElevationAjusting": "0"} elevationCurves = SubElement(sectionData, "ElevationCurves")
) self.AddEleElevationCurve(elevationCurves, "1", self.mid_vec_list, "4")
SubElement(root, "GPSPointGroups") self.AddEleElevationCurve(elevationCurves, "2", self.left_vec_list, "5", "Left")
SubElement(root, "Orthoimages") self.AddEleElevationCurve(
SubElement(root, "GPSXianGao") elevationCurves, "3", self.right_vec_list, "6", "Right"
SubElement(root, "HouseSwing") )
sectionData = SubElement(root, "SectionData") annotationElements = SubElement(sectionData, "AnnotationElements")
SubElement(sectionData, "licheng").text = licheng self.AddAnnotationElements(
SubElement(sectionData, "lstlicheng") annotationElements,
SubElement(sectionData, "lstSctnRcd") {
SubElement(sectionData, "ForestElevationCurves") "xsi:type": "ElePowerLinePole",
elevationCurves = SubElement(sectionData, "ElevationCurves") "ID": "7",
AddEleElevationCurve(elevationCurves, "1", [["0", "0"], ["100", "200"]]) "CurveSide": "All",
AddEleElevationCurve(elevationCurves, "2", [["0", "0"], ["100", "202"]], "Left") "Remarks": self.remarks_start,
AddEleElevationCurve(elevationCurves, "3", [["0", "0"], ["100", "205"]], "Right") "PoleType": "AnglePole",
annotationElements = SubElement(sectionData, "AnnotationElements") "LeftElevation": "0",
AddAnnotationElements( "RightElevation": "0",
annotationElements, "CableAngle": "0",
{ "PoleName": self.pole_name_start,
"xsi:type": "ElePowerLinePole", },
"ID": "7", xyz=",".join(self.mid_vec_list[0]),
"CurveSide": "All", )
"Remarks": remarks_start, self.AddAnnotationElements(
"PoleType": "AnglePole", annotationElements,
"LeftElevation": "0", {
"RightElevation": "0", "xsi:type": "ElePowerLinePole",
"CableAngle": "0", "ID": "8",
"PoleName": pole_name_start, "CurveSide": "All",
}, "Remarks": self.remarks_end,
xyz="0,0", "PoleType": "AnglePole",
) "LeftElevation": "0",
AddAnnotationElements( "RightElevation": "0",
annotationElements, "CableAngle": "0",
{ "PoleName": self.pole_name_end,
"xsi:type": "ElePowerLinePole", },
"ID": "8", xyz=",".join(self.mid_vec_list[-1]),
"CurveSide": "All", )
"Remarks": remarks_end, mapData = SubElement(root, "MapData")
"PoleType": "AnglePole", SubElement(mapData, "GrowthHeight").text = "0"
"LeftElevation": "0", SubElement(mapData, "LinkedSectionObjectID_Group")
"RightElevation": "0", SubElement(mapData, "verticalExtent2").text = self.verticalExtent2
"CableAngle": "0", SubElement(mapData, "MapElements")
"PoleName": pole_name_end, tree = ElementTree(root)
}, self.indent(root)
xyz="100,200", tree.write(xml_path, encoding="utf-8", xml_declaration=True)
)
mapData = SubElement(root, "MapData")
SubElement(mapData, "GrowthHeight").text = "0"
SubElement(mapData, "LinkedSectionObjectID_Group")
SubElement(mapData, "verticalExtent2").text = verticalExtent2
SubElement(mapData, "MapElements")
tree = ElementTree(root)
indent(root)
tree.write("result.nwed", encoding="utf-8", xml_declaration=True)

3
pw.py
View File

@ -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}/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) c_file.write(c_template)