import tkinter as tk
from tkinter import filedialog, messagebox
import math
'''打开选择文件夹对话框'''
window = tk.Tk()
window.title("测站改正1.0 by: 放放风")
window.geometry('795x290+300+200') # 290 160为窗口大小,+1000 +10 定义窗口弹出时的默认展示位置
window['background'] = 'RoyalBlue'
v = tk.StringVar()
# 方位角
def azimuth(x1, y1, x2, y2):
angle = 0
dx = x2 - x1
dy = y2 - y1
if dx == 0 and dy > 0: # 判断象限
angle = 0
if dx == 0 and dy < 0:
angle = 180
if dy == 0 and dx > 0:
angle = 90
if dy == 0 and dx < 0:
angle = 270
if dx > 0 and dy > 0:
angle = math.atan(dx / dy) * 180 / math.pi
elif dx < 0 and dy > 0:
angle = 360 + math.atan(dx / dy) * 180 / math.pi
elif dx < 0 and dy < 0:
angle = 180 + math.atan(dx / dy) * 180 / math.pi
elif dx > 0 and dy < 0:
angle = 180 + math.atan(dx / dy) * 180 / math.pi
angle = math.radians(angle)
return angle
#
def calc_angle():
t1 = text1_var.get()
t2 = text2_var.get()
t3 = text3_var.get()
t4 = text4_var.get()
x1 = float(t1.split(",")[0])
y1 = float(t1.split(",")[1])
x2 = float(t2.split(",")[0])
y2 = float(t2.split(",")[1])
x3 = float(t3.split(",")[0])
y3 = float(t3.split(",")[1])
x4 = float(t4.split(",")[0])
y4 = float(t4.split(",")[1])
#
d1 = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
d2 = math.sqrt((x4 - x3) ** 2 + (y4 - y3) ** 2)
text5_var.set(d1)
text7_var.set(d2)
d = (d1 - d2) / 2
text9_var.set(d)
dd = abs(round(d1 - d2, 3))
if dd > 0.02:
text15_var.set("请检查,误差为%.3f米" % dd)
else:
text15_var.set("数据正常,误差为%.3f米" % dd)
#
angle = azimuth(x1, y1, x2, y2)
text6_var.set(angle)
angle_qzy = azimuth(x3, y3, x4, y4)
text8_var.set(angle_qzy)
# rtk坐标平差
x_one = x1 + d * math.sin(angle)
y_one = y1 + d * math.cos(angle)
x_two = x2 - d * math.sin(angle)
y_two = y2 - d * math.cos(angle)
# 全站仪坐标旋转角度
angle_Difference = angle - angle_qzy
text10_var.set(angle_Difference)
# 旋转全站仪坐标
xs = x3 * math.cos(angle_Difference) + y3 * math.sin(angle_Difference)
ys = y3 * math.cos(angle_Difference) - x3 * math.sin(angle_Difference)
x = x4 * math.cos(angle_Difference) + y4 * math.sin(angle_Difference)
y = y4 * math.cos(angle_Difference) - x4 * math.sin(angle_Difference)
# 不知道怎么旋转的,旋转的方位角和rtk是一样的
#
# #计算旋转起点到改正rtk起点的位置差值
dx31 = xs - x_one
dy31 = ys - y_one
text11_var.set(dx31)
text12_var.set(dy31)
xx_1 = [str(round(xs - dx31, 5)), str(round(ys - dy31, 5))]
xx_1 = ",".join(xx_1)
xx_2 = [str(round(x - dx31, 5)), str(round(y - dy31, 5))]
xx_2 = ",".join(xx_2)
text13_var.set(xx_1)
text14_var.set(xx_2)
return
#
def filter_txt(patchw):
new_listw = []
charw = ""
with open(patchw) as f:
contentsw = f.readlines()
for linew in contentsw:
for xw in linew:
if xw != " ":
charw += xw
new_listw.append(charw)
charw = ""
filter_listw = [w for w in [r.replace("\n", "") for r in new_listw] if w != '']
return filter_listw
#
def get_Land_supply_coordinates():
p = []
Filer_paths = filedialog.askopenfilenames(filetypes=[("文本", "txt")], title="选择需要转换的文本") # 获取需要转换的规划文件绝对路径
if not Filer_paths:
tk.messagebox.showinfo('警告', "请选择需要转换的文本!")
return
Save_path = filedialog.askdirectory() # 返回需要保存的绝对路径
if not Save_path:
tk.messagebox.showinfo('警告', "请选择需要保存的路径!")
return
for path_1 in Filer_paths:
Filer_name = path_1.split("/")[-1].replace(".txt", ".(转换结果).txt") # 获取需要转换文件文件名
new_filer = open(Save_path + "/" + Filer_name, "w") # 打开文本,没有创建
s = filter_txt(path_1)
for n in s:
line_k = n.split(",")
num_2 = float(line_k[0])
x = float(line_k[2])
y = float(line_k[3])
z = str(line_k[4])
# result = calc_angle()
angle_Difference = float(text10_var.get())
dx31 = float(text11_var.get())
dy31 = float(text12_var.get())
# 旋转列表
xm = x * math.cos(angle_Difference) + y * math.sin(angle_Difference)
ym = y * math.cos(angle_Difference) - x * math.sin(angle_Difference)
num = str(num_2)
xm = str(xm - dx31)
ym = str(ym - dy31)
q = [num, "", xm, ym, z]
q = ",".join(q)
p.append(q)
for p_4 in p:
new_filer.writelines(p_4)
new_filer.write("\n")
p = []
new_filer.close()
return
lableAB = tk.Label(window, text="已知点", width=15, bg="Orange").grid(row=1, column=0)
lableCD = tk.Label(window, text="改正点", width=15, bg="Orange").grid(row=4, column=0)
lable1 = tk.Label(window, text="A(x1,y1)", width=15).grid(row=2, column=0)
text1_var = tk.StringVar() # 获取text_1输入的值
text1_var.set(r'0.000,0.000')
text1 = tk.Entry(window, textvariable=text1_var, bd=5).grid(row=2, column=1)
#
lable2 = tk.Label(window, text="B(x2,y2)", width=15).grid(row=3, column=0)
text2_var = tk.StringVar() # 获取text_1输入的值
text2_var.set(r'1000.000,0.000')
text2 = tk.Entry(window, textvariable=text2_var, bd=5).grid(row=3, column=1)
#
lable3 = tk.Label(window, text="C(x3,y4)", width=15).grid(row=5, column=0)
text3_var = tk.StringVar() # 获取text_1输入的值
text3_var.set(r'8960.000,9960.000')
text3 = tk.Entry(window, textvariable=text3_var, bd=5).grid(row=5, column=1)
#
lable4 = tk.Label(window, text="D(x4,y4)", width=15).grid(row=6, column=0)
text4_var = tk.StringVar() # 获取text_1输入的值
text4_var.set(r"9960.000,9960.000")
text4 = tk.Entry(window, textvariable=text4_var, bd=5).grid(row=6, column=1)
lable5 = tk.Label(window, text="AB距离", width=15).grid(row=1, column=4)
text5_var = tk.StringVar() # 获取text_1输入的值
text5 = tk.Entry(window, textvariable=text5_var, bd=5).grid(row=1, column=5)
lable6 = tk.Label(window, text="AB方位角", width=15).grid(row=2, column=4)
text6_var = tk.StringVar() # 获取text_1输入的值
text6 = tk.Entry(window, textvariable=text6_var, bd=5).grid(row=2, column=5)
lable7 = tk.Label(window, text="CD距离", width=15).grid(row=3, column=4)
text7_var = tk.StringVar() # 获取text_1输入的值
text7 = tk.Entry(window, textvariable=text7_var, bd=5).grid(row=3, column=5)
lable8 = tk.Label(window, text="CD方位角", width=15).grid(row=4, column=4)
text8_var = tk.StringVar() # 获取text_1输入的值
text8 = tk.Entry(window, textvariable=text8_var, bd=5).grid(row=4, column=5)
lable9 = tk.Label(window, text="距离差/2", width=15).grid(row=5, column=4)
text9_var = tk.StringVar() # 获取text_1输入的值
text9 = tk.Entry(window, textvariable=text9_var, bd=5).grid(row=5, column=5)
lable10 = tk.Label(window, text="方位角差", width=15).grid(row=6, column=4)
text10_var = tk.StringVar() # 获取text_1输入的值
text10 = tk.Entry(window, textvariable=text10_var, bd=5).grid(row=6, column=5)
lable11 = tk.Label(window, text="🔺x", width=15).grid(row=7, column=4)
text11_var = tk.StringVar() # 获取text_1输入的值
text11 = tk.Entry(window, textvariable=text11_var, bd=5).grid(row=7, column=5)
lable12 = tk.Label(window, text="🔺y", width=15).grid(row=8, column=4)
text12_var = tk.StringVar() # 获取text_1输入的值
text12 = tk.Entry(window, textvariable=text12_var, bd=5).grid(row=8, column=5)
lable13 = tk.Label(window, text="转换后:C", width=15).grid(row=1, column=6)
text13_var = tk.StringVar() # 获取text_1输入的值
text13 = tk.Entry(window, textvariable=text13_var, bd=5).grid(row=1, column=7)
lable14 = tk.Label(window, text="转换后:D", width=15).grid(row=2, column=6)
text14_var = tk.StringVar() # 获取text_1输入的值
text14 = tk.Entry(window, textvariable=text14_var, bd=5).grid(row=2, column=7)
lable15 = tk.Label(window, text="提示", width=15).grid(row=3, column=6)
text15_var = tk.StringVar() # 获取text_1输入的值
text15 = tk.Entry(window, textvariable=text15_var, bd=5, fg="Red").grid(row=3, column=7)
tk.Button(window, text="计算参数", width=15, height=1, command=calc_angle, bg="Silver").grid(row=15, column=4)
tk.Button(window, text="转换文件", width=15, height=1, command=get_Land_supply_coordinates, bg="Silver").grid(row=15,
column=5)
text20 = tk.Text(window, width=37, height=15)
text20.grid(row=4, column=6, rowspan=12, columnspan=4)
text20.tag_config("tag_1", backgroun="yellow", foreground="red")
text20.insert("insert",
"1.输入框中x,y为数学坐标系\n\n2.A,B为已知点:C,D为需改坐标。\n\n"
"3.必须先计算参数,再改正坐标文件。\n\n"
"文件格式为(num,,x,y,z)\n\n"
"4.z值不做计算\n\n"
"5.转换结果与cass测站改正比较有0公分误差,不完全重合\n")
text20.insert("end", "5.更多功能请联系:\ncemo9960@outlook.com", "tag_1")
cjip = tk.PhotoImage(file="D:\\a17.gif")
tk.Label(window, image=cjip, height=95, width=145).grid(row=7, column=0, rowspan=12, columnspan=5)
window.mainloop()
测站改正
最新推荐文章于 2024-05-06 18:00:00 发布