Compare commits
14 Commits
3864d128d0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0665a83a9c | ||
|
|
d7e16069db | ||
|
|
6caafc91a5 | ||
|
|
8c60899f8e | ||
|
|
dc7cb8fc8c | ||
|
|
1387aa277e | ||
|
|
363a14e98b | ||
|
|
34b7dfb9e0 | ||
|
|
057c199b18 | ||
|
|
308259306f | ||
|
|
b5e17a3b9e | ||
|
|
1fd8d0863a | ||
|
|
f4367893e2 | ||
|
|
a7e4809463 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -7,3 +7,10 @@ __pycache__
|
||||
canva
|
||||
*.xls*
|
||||
*.toml
|
||||
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)
|
||||
@@ -1,131 +0,0 @@
|
||||
PROJ
|
||||
LQ 800 6
|
||||
|
||||
|
||||
PATH
|
||||
{SEGMENT_N} {TOWER_NUM_START} 0
|
||||
{SEGMENT}
|
||||
|
||||
SECTION
|
||||
{SEGMENT_S} {SEGMENT_E} LQ2710 JL/G1A-400/50 2.5 4 2.25 JLB35A-150 3.35 4 30.85 0.75
|
||||
|
||||
|
||||
|
||||
CONTROL
|
||||
2500 50 .5E-5 -.5E-5 2.0 500 2.5 2500
|
||||
1 1 15 6 20 0
|
||||
|
||||
|
||||
TOWER
|
||||
26 0 6
|
||||
ZS129A1 ZBC1 34 48 0 150000 0
|
||||
H-2*21 48 25 9.64 53 53 53
|
||||
ZS129A2 ZBC1 49 54 0 150000 0
|
||||
H-2*21 48 25 9.64 53 53 53
|
||||
ZS129A1 ZBC1 35 48 0 150000 0
|
||||
H-2*21 48 25 9.64 53 53 53
|
||||
ZS129A2 ZBC1 49 54 0 150000 0
|
||||
H-2*21 48 25 9.64 53 53 53
|
||||
ZS229A1 ZBC2 35 48 0 150000 0
|
||||
H-2*21 50 28.27 11.88 52 52 52
|
||||
ZS229A2 ZBC2 49 51 0 150000 0
|
||||
H-2*21 50 28.27 11.88 52 52 52
|
||||
ZS229A3 ZBC2 52 60 0 150000 0
|
||||
H-2*21 50 28.27 11.88 52 52 52
|
||||
ZS229A4 ZBC2 61 72 0 150000 0
|
||||
H-2*21 50 28.27 11.88 52 52 52
|
||||
ZS229A1 ZBC2 35 48 0 150000 0
|
||||
H-2*21 50 28.27 11.88 52 52 52
|
||||
ZS229A2 ZBC2 49 51 0 150000 0
|
||||
H-2*21 50 28.27 11.88 52 52 52
|
||||
ZS229A3 ZBC2 52 60 0 150000 0
|
||||
H-2*21 50 28.27 11.88 52 52 52
|
||||
ZS229A4 ZBC2 61 72 0 150000 0
|
||||
H-2*21 50 28.27 11.88 52 52 52
|
||||
ZS329A1 ZBC3 35 48 0 150000 0
|
||||
H-2*21 54 32.41 13.02 53.5 53.5 53.5
|
||||
ZS329A2 ZBC3 49 51 0 150000 0
|
||||
H-2*21 54 32.41 13.02 53.5 53.5 53.5
|
||||
ZS329A3 ZBC3 52 60 0 150000 0
|
||||
H-2*21 54 32.41 13.02 53.5 53.5 53.5
|
||||
ZS329A4 ZBC3 61 72 0 150000 0
|
||||
H-2*21 54 32.41 13.02 53.5 53.5 53.5
|
||||
ZS329A1 ZBC3 35 48 0 150000 0
|
||||
H-2*21 54 32.41 13.02 53.5 53.5 53.5
|
||||
ZS329A2 ZBC3 49 51 0 150000 0
|
||||
H-2*21 54 32.41 13.02 53.5 53.5 53.5
|
||||
ZS329A3 ZBC3 52 60 0 150000 0
|
||||
H-2*21 54 32.41 13.02 53.5 53.5 53.5
|
||||
ZS329A4 ZBC3 61 72 0 150000 0
|
||||
H-2*21 54 32.41 13.02 53.5 53.5 53.5
|
||||
ZS429A1 ZBC4 35 48 0 150000 0
|
||||
H-2*21 58 34.50 14.06 56.5 56.5 56.5
|
||||
ZS429A2 ZBC4 49 51 0 150000 0
|
||||
H-2*21 58 34.50 14.06 56.5 56.5 56.5
|
||||
ZS429A3 ZBC4 52 60 0 150000 0
|
||||
H-2*21 58 34.50 14.06 56.5 56.5 56.5
|
||||
ZS429A1 ZBC4 35 48 0 150000 0
|
||||
H-2*21 58 34.50 14.06 56.5 56.5 56.5
|
||||
ZS429A2 ZBC4 49 51 0 150000 0
|
||||
H-2*21 58 34.50 14.06 56.5 56.5 56.5
|
||||
ZS429A3 ZBC4 52 60 0 150000 0
|
||||
H-2*21 58 34.50 14.06 56.5 56.5 56.5
|
||||
JG129A JC1 27 57 0 150000 0
|
||||
2*42-50 2*42-50 H-2*21
|
||||
JG229A JC2 27 57 0 150000 0
|
||||
2*42-50 2*42-50 H-2*21
|
||||
JG329A JC3 27 51 0 150000 0
|
||||
2*42-50 2*42-50 H-2*21
|
||||
JG429A JC4 27 67 0 150000 0
|
||||
2*42-50 2*42-50 H-2*21
|
||||
DJC DJC 27 42 0 150000 0
|
||||
2*42-50 2*42-50 H-2*21
|
||||
MX MX 31 42 0 150000 0
|
||||
2*42-50 2*42-50 H-2*21
|
||||
|
||||
*FIXED
|
||||
0 J1
|
||||
111.9 J1
|
||||
479 ZB2
|
||||
953 ZB2
|
||||
1258 ZB2
|
||||
1531.8 J1
|
||||
2074.6 ZB2
|
||||
2282.1 J1
|
||||
2586.3 ZB2
|
||||
3087.1 ZB2
|
||||
3559.5 ZB2
|
||||
3973 ZB2
|
||||
4212.8 ZB2
|
||||
|
||||
|
||||
|
||||
*NOTOWER
|
||||
|
||||
|
||||
|
||||
|
||||
*TGRP
|
||||
|
||||
|
||||
|
||||
|
||||
*FILE
|
||||
{CONTROL_FILE}.DAT
|
||||
|
||||
|
||||
*CLRNCE
|
||||
76970 77050 34
|
||||
|
||||
|
||||
*CHK
|
||||
10216 1
|
||||
|
||||
LR
|
||||
1 1 -400
|
||||
|
||||
|
||||
LINEBIKE
|
||||
2600 1.3 4.7 40
|
||||
|
||||
|
||||
247
dem.py
247
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,16 +47,23 @@ 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 = []
|
||||
plate_doc = ezdxf.new(dxfversion="R2010")
|
||||
plate_msp = plate_doc.modelspace()
|
||||
toml_dict = self._toml_dict
|
||||
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):
|
||||
start_point_name: str = excel_pfs.iloc[foo, 0]
|
||||
end_point_name: str = excel_pfs.iloc[foo + 1, 0]
|
||||
start_point_name: str = excel_pfs.iloc[foo, 3]
|
||||
end_point_name: str = excel_pfs.iloc[foo + 1, 3]
|
||||
point_x_s = float(excel_pfs.iloc[foo, 1])
|
||||
point_y_s = float(excel_pfs.iloc[foo, 2])
|
||||
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])
|
||||
center_elevation = self.get_elevation(line_coordination[:, 2:4])
|
||||
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():
|
||||
# if name not in dm_doc.linetypes:
|
||||
@@ -76,61 +85,124 @@ 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))
|
||||
dm_msp.add_polyline2d(
|
||||
[
|
||||
(x_axis[i] / 5, left_elevation[i] * 2)
|
||||
for i in range(len(left_elevation))
|
||||
],
|
||||
# 左边线
|
||||
left_line = [
|
||||
(x_axis[i] / 5 / zoom_factor, left_elevation[i] * 2 / zoom_factor)
|
||||
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},
|
||||
) # 红色
|
||||
dm_msp.add_polyline2d(
|
||||
[
|
||||
(x_axis[i] / 5, center_elevation[i] * 2)
|
||||
for i in range(len(center_elevation))
|
||||
]
|
||||
dm_msp.add_polyline2d(left_line, dxfattribs={"color": 1}) # 红色
|
||||
mid_line = [
|
||||
(x_axis[i] / 5 / zoom_factor, center_elevation[i] * 2 / zoom_factor)
|
||||
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(
|
||||
[
|
||||
(x_axis[i] / 5, right_elevation[i] * 2)
|
||||
for i in range(len(right_elevation))
|
||||
],
|
||||
right_line,
|
||||
dxfattribs={"color": 5},
|
||||
) # 蓝色
|
||||
# 树的线
|
||||
# TODO 没有考虑用最高边线的情况
|
||||
if self._tree_height > 0:
|
||||
dm_msp.add_polyline2d(
|
||||
[
|
||||
(x_axis[i] / 5, (center_elevation[i] + self._tree_height) * 2)
|
||||
for i in range(len(center_elevation))
|
||||
]
|
||||
# 考虑用最高边线的情况
|
||||
tree_line = [
|
||||
(
|
||||
x_axis[i] / 5 / zoom_factor,
|
||||
(
|
||||
np.max(
|
||||
(
|
||||
center_elevation[i],
|
||||
left_elevation[i],
|
||||
right_elevation[i],
|
||||
)
|
||||
)
|
||||
+ self._tree_height
|
||||
)
|
||||
* 2
|
||||
/ zoom_factor,
|
||||
)
|
||||
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)
|
||||
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文件
|
||||
with open(
|
||||
f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}", "w"
|
||||
) as z_file:
|
||||
z_file_path = f"{out_dxf_file_dir}/ZD{100+int(start_point_name[1:])}"
|
||||
with open(z_file_path, "w") as z_file:
|
||||
z_file.write("0 ")
|
||||
z_file.write(f"{center_elevation[0]*2} ")
|
||||
z_file.write("0 ")
|
||||
z_file.write("0 ")
|
||||
z_file.write(f"{center_elevation[0]*2-50}")
|
||||
# TODO:写平面文件
|
||||
if foo == 0:
|
||||
# copy file a to dist b
|
||||
shutil.copy(z_file_path, f"{out_dxf_file_dir}/ZDA")
|
||||
# 写平面文件
|
||||
plate_msp.add_polyline2d(
|
||||
line_coordination[:, 0:2],
|
||||
dxfattribs={"color": 1},
|
||||
@@ -171,7 +243,51 @@ class Dem:
|
||||
segments, tower_start_num, control_file_template_path, out_dxf_file_dir
|
||||
)
|
||||
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):
|
||||
"""Get the elevation of given locations from DEM in GCS.
|
||||
@@ -217,10 +333,6 @@ class Dem:
|
||||
Xpixel = (Xgeo[i] - gt[0]) / gt[1]
|
||||
Yline = (Ygeo[i] - gt[3]) / gt[5]
|
||||
# 寻找左上,左下,右上,右下4个点
|
||||
# lu_xy = np.array([math.floor(Xpixel), math.floor(Yline)]) # 左上
|
||||
# ld_xy = np.array([math.floor(Xpixel), math.ceil(Yline)]) # 左下
|
||||
# ru_xy = np.array([math.ceil(Xpixel), math.floor(Yline)]) # 右上
|
||||
# rd_xy = np.array([math.ceil(Xpixel), math.ceil(Yline)]) # 右下
|
||||
lu_xy = np.array([math.floor(Xpixel), math.ceil(Yline)]) # 左上
|
||||
ld_xy = np.array([math.floor(Xpixel), math.floor(Yline)]) # 左下
|
||||
ru_xy = np.array([math.ceil(Xpixel), math.ceil(Yline)]) # 右上
|
||||
@@ -237,36 +349,7 @@ class Dem:
|
||||
rd_elevation = gdal_data.ReadAsArray(
|
||||
int(rd_xy[0]), int(rd_xy[1]), 1, 1
|
||||
).astype(float)
|
||||
# delta_x = (Xpixel - ld_xy[0]) / 1 # 距离是1
|
||||
# delta_y = (ld_xy[1]-Yline) / 1
|
||||
# site_ele[i] = (
|
||||
# ld_elevation
|
||||
# + (lu_elevation - ld_elevation) * delta_y
|
||||
# + (rd_elevation - ld_elevation) * delta_x
|
||||
# + (ld_elevation - lu_elevation + ru_elevation - rd_elevation)
|
||||
# * delta_x
|
||||
# * delta_y
|
||||
# )
|
||||
|
||||
# 通过空间平面方程拟合Z值 参考《数字高程模型教程》 汤国安,李发源,刘学军编著 p89
|
||||
# equation_a = np.array(
|
||||
# [
|
||||
# [lu_xy[0], lu_xy[0] * lu_xy[1], lu_xy[1], 1],
|
||||
# [ld_xy[0], ld_xy[0] * ld_xy[1], ld_xy[1], 1],
|
||||
# [ru_xy[0], ru_xy[0] * ru_xy[1], ru_xy[1], 1],
|
||||
# [rd_xy[0], rd_xy[0] * rd_xy[1], rd_xy[1], 1],
|
||||
# ]
|
||||
# )
|
||||
# equation_b = np.array(
|
||||
# [lu_elevation[0], ld_elevation[0], ru_elevation[0], rd_elevation[0]]
|
||||
# )
|
||||
# equation_c = np.linalg.solve(equation_a, equation_b)
|
||||
# point_z = (
|
||||
# Xpixel * equation_c[0]
|
||||
# + equation_c[1] * Xpixel * Yline
|
||||
# + equation_c[2] * Yline
|
||||
# + equation_c[3]
|
||||
# )
|
||||
# 依据https://blog.csdn.net/jameschen9051/article/details/109469228中的公司
|
||||
point_z = (
|
||||
lu_elevation[0]
|
||||
* (
|
||||
@@ -290,7 +373,6 @@ class Dem:
|
||||
)
|
||||
)
|
||||
site_ele[i] = point_z
|
||||
# print(f"row:{Yline} col:{Xpixel} elev:{site_ele[i]}")
|
||||
pass
|
||||
return site_ele
|
||||
|
||||
@@ -298,8 +380,11 @@ class Dem:
|
||||
path_length = (
|
||||
(point_x_s - point_x_e) ** 2 + (point_y_s - point_y_e) ** 2
|
||||
) ** 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 / 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)
|
||||
# 计算左右边线
|
||||
@@ -308,14 +393,16 @@ class Dem:
|
||||
side_width = toml_dict["parameter"]["side_width"] # 边线宽度
|
||||
_line_angel = math.atan((point_y_e - point_y_s) / (point_x_e - point_x_s))
|
||||
if point_x_e < point_x_s:
|
||||
line_angel = _line_angel + math.pi / 2
|
||||
line_angel = _line_angel + math.pi
|
||||
else:
|
||||
line_angel = _line_angel
|
||||
left_offset_x = side_width * math.cos(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_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
|
||||
r = np.array(
|
||||
[
|
||||
|
||||
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.")
|
||||
|
||||
13
main_dem.py
13
main_dem.py
@@ -1,13 +0,0 @@
|
||||
import sys
|
||||
from dem import Dem
|
||||
from loguru import logger
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
toml_file_path = r"db_JS.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()
|
||||
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(
|
||||
"{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)
|
||||
|
||||
Reference in New Issue
Block a user