完成了同时导出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,

95
nwed.py
View File

@ -1,9 +1,31 @@
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
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" i = "\n" + level * "\t"
if len(elem): if len(elem):
if not elem.text or not elem.text.strip(): if not elem.text or not elem.text.strip():
@ -11,15 +33,16 @@ def indent(elem, level=0):
if not elem.tail or not elem.tail.strip(): if not elem.tail or not elem.tail.strip():
elem.tail = i elem.tail = i
for elem in elem: for elem in elem:
indent(elem, level + 1) self.indent(elem, level + 1)
if not elem.tail or not elem.tail.strip(): if not elem.tail or not elem.tail.strip():
elem.tail = i elem.tail = i
else: else:
if level and (not elem.tail or not elem.tail.strip()): if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i elem.tail = i
def AddEleElevationCurve(
def AddEleElevationCurve(elevationCurves, id, vec_list, curve_side=None): self, elevationCurves, id, vec_list, curve_id, curve_side=None
):
if curve_side: if curve_side:
elevationCurve_attribs = {"ID": id, "CurveSide": curve_side} elevationCurve_attribs = {"ID": id, "CurveSide": curve_side}
else: else:
@ -35,7 +58,11 @@ def AddEleElevationCurve(elevationCurves, id, vec_list, curve_side=None):
segmentList, segmentList,
"EleElevationCurveSegment", "EleElevationCurveSegment",
# TODO 这个ID其实依据中、边导线会变化。 # TODO 这个ID其实依据中、边导线会变化。
attrib={"ID": "4", "StartPointClass": "NotSet", "EndPointClass": "NotSet"}, attrib={
"ID": curve_id,
"StartPointClass": "NotSet",
"EndPointClass": "NotSet",
},
) )
SubElement(eleElevationCurveSegment, "GrowthHeight").text = "0" SubElement(eleElevationCurveSegment, "GrowthHeight").text = "0"
SubElement(eleElevationCurveSegment, "LinkedSectionObjectID_Group") SubElement(eleElevationCurveSegment, "LinkedSectionObjectID_Group")
@ -46,28 +73,24 @@ def AddEleElevationCurve(elevationCurves, id, vec_list, curve_side=None):
eleElevationCurveSegment, "VecListRendering" eleElevationCurveSegment, "VecListRendering"
) )
for vec in vec_list: for vec in vec_list:
SubElement(vec_list_rendering_element, "Vector3", attrib={"xyz": ",".join(vec)}) SubElement(
vec_list_rendering_element, "Vector3", attrib={"xyz": ",".join(vec)}
)
return elevationCurve return elevationCurve
def AddAnnotationElements(self, sectionData, pole_attrib, xyz):
def AddAnnotationElements(sectionData, pole_attrib, xyz): pdmGraphicsObject = SubElement(
pdmGraphicsObject = SubElement(sectionData, "PdmGraphicsObject", attrib=pole_attrib) sectionData, "PdmGraphicsObject", attrib=pole_attrib
)
SubElement(pdmGraphicsObject, "GrowthHeight").text = "0" SubElement(pdmGraphicsObject, "GrowthHeight").text = "0"
SubElement(pdmGraphicsObject, "LinkedSectionObjectID_Group") SubElement(pdmGraphicsObject, "LinkedSectionObjectID_Group")
SubElement(pdmGraphicsObject, "Position", attrib={"xyz": xyz}) SubElement(pdmGraphicsObject, "Position", attrib={"xyz": xyz})
def write(self, xml_path):
section_name = "002"
licheng = "100"
remarks_start = "002"
pole_name_start = "4001"
remarks_end = "003"
pole_name_end = "4002"
verticalExtent2 = "20" # 边线宽度
root = Element( root = Element(
"OverheadTransmissionLineDrawing", "OverheadTransmissionLineDrawing",
attrib={ attrib={
"Name": section_name, "Name": self.section_name,
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd": "http://www.w3.org/2001/XMLSchema", "xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
"Description": "", "Description": "",
@ -99,57 +122,61 @@ SubElement(elevAdjSections, "GrowthHeight").text = "0"
SubElement(elevAdjSections, "LinkedSectionObjectID_Group") SubElement(elevAdjSections, "LinkedSectionObjectID_Group")
sections = SubElement(elevAdjSections, "Sections") sections = SubElement(elevAdjSections, "Sections")
SubElement( SubElement(
sections, "ElevationAdjSection", attrib={"Position": "0", "ElevationAjusting": "0"} sections,
"ElevationAdjSection",
attrib={"Position": "0", "ElevationAjusting": "0"},
) )
SubElement(root, "GPSPointGroups") SubElement(root, "GPSPointGroups")
SubElement(root, "Orthoimages") SubElement(root, "Orthoimages")
SubElement(root, "GPSXianGao") SubElement(root, "GPSXianGao")
SubElement(root, "HouseSwing") SubElement(root, "HouseSwing")
sectionData = SubElement(root, "SectionData") sectionData = SubElement(root, "SectionData")
SubElement(sectionData, "licheng").text = licheng SubElement(sectionData, "licheng").text = self.licheng
SubElement(sectionData, "lstlicheng") SubElement(sectionData, "lstlicheng")
SubElement(sectionData, "lstSctnRcd") SubElement(sectionData, "lstSctnRcd")
SubElement(sectionData, "ForestElevationCurves") SubElement(sectionData, "ForestElevationCurves")
elevationCurves = SubElement(sectionData, "ElevationCurves") elevationCurves = SubElement(sectionData, "ElevationCurves")
AddEleElevationCurve(elevationCurves, "1", [["0", "0"], ["100", "200"]]) self.AddEleElevationCurve(elevationCurves, "1", self.mid_vec_list, "4")
AddEleElevationCurve(elevationCurves, "2", [["0", "0"], ["100", "202"]], "Left") self.AddEleElevationCurve(elevationCurves, "2", self.left_vec_list, "5", "Left")
AddEleElevationCurve(elevationCurves, "3", [["0", "0"], ["100", "205"]], "Right") self.AddEleElevationCurve(
elevationCurves, "3", self.right_vec_list, "6", "Right"
)
annotationElements = SubElement(sectionData, "AnnotationElements") annotationElements = SubElement(sectionData, "AnnotationElements")
AddAnnotationElements( self.AddAnnotationElements(
annotationElements, annotationElements,
{ {
"xsi:type": "ElePowerLinePole", "xsi:type": "ElePowerLinePole",
"ID": "7", "ID": "7",
"CurveSide": "All", "CurveSide": "All",
"Remarks": remarks_start, "Remarks": self.remarks_start,
"PoleType": "AnglePole", "PoleType": "AnglePole",
"LeftElevation": "0", "LeftElevation": "0",
"RightElevation": "0", "RightElevation": "0",
"CableAngle": "0", "CableAngle": "0",
"PoleName": pole_name_start, "PoleName": self.pole_name_start,
}, },
xyz="0,0", xyz=",".join(self.mid_vec_list[0]),
) )
AddAnnotationElements( self.AddAnnotationElements(
annotationElements, annotationElements,
{ {
"xsi:type": "ElePowerLinePole", "xsi:type": "ElePowerLinePole",
"ID": "8", "ID": "8",
"CurveSide": "All", "CurveSide": "All",
"Remarks": remarks_end, "Remarks": self.remarks_end,
"PoleType": "AnglePole", "PoleType": "AnglePole",
"LeftElevation": "0", "LeftElevation": "0",
"RightElevation": "0", "RightElevation": "0",
"CableAngle": "0", "CableAngle": "0",
"PoleName": pole_name_end, "PoleName": self.pole_name_end,
}, },
xyz="100,200", xyz=",".join(self.mid_vec_list[-1]),
) )
mapData = SubElement(root, "MapData") mapData = SubElement(root, "MapData")
SubElement(mapData, "GrowthHeight").text = "0" SubElement(mapData, "GrowthHeight").text = "0"
SubElement(mapData, "LinkedSectionObjectID_Group") SubElement(mapData, "LinkedSectionObjectID_Group")
SubElement(mapData, "verticalExtent2").text = verticalExtent2 SubElement(mapData, "verticalExtent2").text = self.verticalExtent2
SubElement(mapData, "MapElements") SubElement(mapData, "MapElements")
tree = ElementTree(root) tree = ElementTree(root)
indent(root) self.indent(root)
tree.write("result.nwed", encoding="utf-8", xml_declaration=True) tree.write(xml_path, 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)