供地坐标格式转换

import tkinter as tk
from tkinter import filedialog, messagebox
from decimal import Decimal

'''打开选择文件夹对话框'''
window = tk.Tk()
window.title("供地坐标提取1.0  by: 放放风")
window.geometry('415x555+1000+200')  # 290 160为窗口大小,+1000 +10 定义窗口弹出时的默认展示位置
window['background'] = 'LightPink'


# ------------------------------------------------------
def Polygon_area(file_name):  # 计算面积
    s = 0
    with open(file_name, "r") as f2:
        plan2 = [[Decimal(new2_lines_col2), Decimal(new2_lines_col1) + 40000000] for new2_lines_col1, new2_lines_col2 in
                 [lines2.split()[:-2] for lines2 in f2.readlines()[1:]]]
        point_num = len(plan2)
        for i in range(point_num):
            s += (plan2[i][1] * (plan2[i - 1][0] - plan2[(i + 1) % point_num][0]))
        mj = abs((s / Decimal(2)) / 10000)
        mj = round(mj, 4)
        return [mj, plan2]  # 返回面积(米);坐标,列表内值为字符串


# -----------------------------------------------------
def Land_supply_coordinates(file_names):
    n = 0
    mm = []
    t1 = text1_var.get()
    t2 = text2_var.get()
    t3 = text3_var.get()
    t4 = text4_var.get()
    t5 = text5_var.get()
    t6 = text6_var.get()
    t7 = text7_var.get()
    t8 = text8_var.get()
    t9 = text9_var.get()
    t10 = text10_var.get()
    t11 = text11_var.get()
    t12 = text12_var.get()
    t13 = text13_var.get()
    t14 = str(Polygon_area(file_names)[0])
    t15 = text15_var.get()
    t16 = text16_var.get()
    t17 = text17_var.get()
    t18 = text18_var.get()
    t19 = text19_var.get()
    Text_default_format = [["[属性描述]\n"],
                           ["格式版本号=" + str(t2) + "\n"],
                           ["数据生产单位 = " + str(t3) + "\n"],
                           ["数据生产日期 = " + str(t4) + "\n"],
                           ["坐标系=" + str(t5) + "\n"],
                           ["几度分带 = " + str(t6) + "\n"],
                           ["投影类型 = " + str(t7) + "\n"],
                           ["计量单位 = " + str(t8) + "\n"],
                           ["带号 = " + str(t9) + "\n"],
                           ["精度 = " + str(t10) + "\n"],
                           ["转换参数=" + str(t11) + "\n"],
                           ["[地块坐标]\n"],
                           [t13, t14, t15, t16, t17, t18, t19, "", "@" + "\n"]]  # 地块编号;地块面积;时间;项目名称;类型;图幅号;用地性质
    accuracy = len(t10) - 2
    for x in Polygon_area(file_names)[1]:
        n += 1
        if n < len(Polygon_area(file_names)[1]):
            mm.append(["j" + str(n), "1", str(round(x[0], accuracy)), str(round(x[1], accuracy)) + "\n"])
        elif n == len(Polygon_area(file_names)[1]):
            mm.append(["j" + str(n), "1", str(round(x[0], accuracy)), str(round(x[1], accuracy)) + "\n"])
            mm.append(["j" + str(n + 1), "1", mm[0][2], mm[0][3].replace("\n", "")])
    text_var = Text_default_format + mm
    return text_var


# ---------------------------------------------------
def get_Land_supply_coordinates():
    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
    else:
        for Filer_path in Filer_paths:  # 循环规划文件路径

            Filer_name = Filer_path.split("/")[-1].replace(".txt", "(供地坐标).txt")  # 获取规划文件文件名

            new_filer = open(Save_path + "/" + Filer_name, "w")  # 打开文本,没有创建

            for new_lines in Land_supply_coordinates(Filer_path):  # 循环列表
                print(new_lines)
                new_filer.writelines(",".join(new_lines))  # 列表用“,”合并,写入
            new_filer.close()  # 关闭文本
        tk.messagebox.showinfo('结果', "供地坐标转换成功!")
    return


# 文本框1-------------------------
lable1 = tk.Label(window, text="[属性描述]", width=15).grid(row=0, column=0)
text1_var = tk.StringVar()  # 获取text_1输入的值
text1_var.set(r'默认')
text1 = tk.Entry(window, textvariable=text1_var, bd=5).grid(row=0, column=1)
#
lable2 = tk.Label(window, text="格式版本号", width=15).grid(row=1, column=0)
text2_var = tk.StringVar()  # 获取text_1输入的值
text2_var.set(r'1.01版本')
text2 = tk.Entry(window, textvariable=text2_var, bd=5).grid(row=1, column=1)
#
lable3 = tk.Label(window, text="数据生产单位", width=15).grid(row=2, column=0)
text3_var = tk.StringVar()  # 获取text_1输入的值
text3_var.set(r'杭州通泰测绘有限公司')
text3 = tk.Entry(window, textvariable=text3_var, bd=5).grid(row=2, column=1)
#
lable4 = tk.Label(window, text="数据生产日期", width=15).grid(row=3, column=0)
text4_var = tk.StringVar()  # 获取text_1输入的值
text4_var.set(r'2021-01-01')
text4 = tk.Entry(window, textvariable=text4_var, bd=5).grid(row=3, column=1)
#
lable5 = tk.Label(window, text="坐标系", width=15).grid(row=4, column=0)
text5_var = tk.StringVar()  # 获取text_1输入的值
text5_var.set(r'2000国家大地坐标系')
text5 = tk.Entry(window, textvariable=text5_var, bd=5).grid(row=4, column=1)
#
lable6 = tk.Label(window, text="几度分带", width=15).grid(row=5, column=0)
text6_var = tk.StringVar()  # 获取text_1输入的值
text6_var.set(r'3')
text6 = tk.Entry(window, textvariable=text6_var, bd=5).grid(row=5, column=1)
#
lable7 = tk.Label(window, text="投影类型", width=15).grid(row=6, column=0)
text7_var = tk.StringVar()  # 获取text_1输入的值
text7_var.set(r'高斯克吕格')
text7 = tk.Entry(window, textvariable=text7_var, bd=5).grid(row=6, column=1)
#
lable8 = tk.Label(window, text="计量单位", width=15).grid(row=7, column=0)
text8_var = tk.StringVar()  # 获取text_1输入的值
text8_var.set(r'米')
text8 = tk.Entry(window, textvariable=text8_var, bd=5).grid(row=7, column=1)

#
lable9 = tk.Label(window, text="带号", width=15).grid(row=8, column=0)
text9_var = tk.StringVar()  # 获取text_1输入的值
text9_var.set(r'40')
text9 = tk.Entry(window, textvariable=text9_var, bd=5).grid(row=8, column=1)

#
lable10 = tk.Label(window, text="精度", width=15).grid(row=9, column=0)
text10_var = tk.StringVar()  # 获取text_1输入的值
text10_var.set(r'0.001')
text10 = tk.Entry(window, textvariable=text10_var, bd=5).grid(row=9, column=1)
#
lable11 = tk.Label(window, text="转换参数", width=15).grid(row=10, column=0)
text11_var = tk.StringVar()  # 获取text_1输入的值
text11_var.set(r',,,,,,')
text11 = tk.Entry(window, textvariable=text11_var, bd=5).grid(row=10, column=1)
#
lable12 = tk.Label(window, text="[地块坐标]", width=15).grid(row=11, column=0)
text12_var = tk.StringVar()  # 获取text_1输入的值
text12_var.set(r'默认')
text12 = tk.Entry(window, textvariable=text12_var, bd=5).grid(row=11, column=1)
# --------------------------------------------------------------------------------
lable13 = tk.Label(window, text="地块编号", width=15).grid(row=12, column=0)  # ???
text13_var = tk.StringVar()  # 获取text_1输入的值
text13_var.set(r'1')
text13 = tk.Entry(window, textvariable=text13_var, bd=5).grid(row=12, column=1)

#
lable14 = tk.Label(window, text="地块面积", width=15).grid(row=13, column=0)  # ????
text14_var = tk.StringVar()  # 获取text_1输入的值
text14_var.set(r'默认为公顷,保留四位小数')
text14 = tk.Entry(window, textvariable=text14_var, bd=5).grid(row=13, column=1)

#
lable15 = tk.Label(window, text="时间", width=15).grid(row=14, column=0)
text15_var = tk.StringVar()  # 获取text_1输入的值
text15_var.set(r'')
text15 = tk.Entry(window, textvariable=text15_var, bd=5).grid(row=14, column=1)
#
lable16 = tk.Label(window, text="项目名称", width=15).grid(row=15, column=0)
text16_var = tk.StringVar()  # 获取text_1输入的值
text16_var.set(r'')
text16 = tk.Entry(window, textvariable=text16_var, bd=5).grid(row=15, column=1)
#
lable17 = tk.Label(window, text="面", width=15).grid(row=16, column=0)
text17_var = tk.StringVar()  # 获取text_1输入的值
text17_var.set(r'面')
text17 = tk.Entry(window, textvariable=text17_var, bd=5).grid(row=16, column=1)
#
lable18 = tk.Label(window, text="分幅号", width=15).grid(row=17, column=0)
text18_var = tk.StringVar()  # 获取text_1输入的值
text18_var.set(r'')
text18 = tk.Entry(window, textvariable=text18_var, bd=5).grid(row=17, column=1)
#
lable19 = tk.Label(window, text="用地性质", width=15).grid(row=18, column=0)
text19_var = tk.StringVar()  # 获取text_1输入的值
text19_var.set(r'其他用地')
text19 = tk.Entry(window, textvariable=text19_var, bd=5).grid(row=18, column=1)
#
text20 = tk.Text(window, width=20, height=15)
text20.grid(row=3, column=2, rowspan=7, columnspan=5)
text20.tag_config("tag_1", backgroun="yellow", foreground="red")

text20.insert("insert","1.Cass 中输入 units ,建议单位精度保留五位小数!\n2.使用Getpl插件提取坐标(检查提取坐标精度是否与Cass中一致)。\n3.窗口中精度为输出精度,不建议高于输入坐标精度(默认保留三位小数)。\n")

text20.insert("end", "4.更多功能请联系:\ncemo9960@outlook.com", "tag_1")

cjip = tk.PhotoImage(file="D:\\a5.gif")
tk.Label(window, image=cjip, height=80, width=140).grid(row=16, column=2, rowspan=7, columnspan=5)
#
tk.Button(window, text="确定", width=20, height=1, command=get_Land_supply_coordinates, bg="Green").grid(row=1, column=2)

# -------------------------------------------
window.mainloop()

上一篇:不需要写Sql语句的Mybatis工具:Tkmybatis


下一篇:R timetk