供地坐标格式转换
import tkinter as tk
from tkinter import filedialog, messagebox
from decimal import Decimal
'''打开选择⽂件夹对话框'''
window = tk.Tk()
window.title("供地坐标提取与合并1.1 by: 放放风")
window['background']='LightPink'
v = tk.StringVar()
listbox = tk.Listbox(window, height=20, width=90, listvariable=v)
# 处理单击选项
def show(event):
# nearest可以传回最接近y坐标在Listbox的索引
# 传回⽬前选项的索引
listbox.index = arest(event.y)
# 处理拖拽选项
def showInfo(event):
# 获取⽬前选项的新索引
newIndex = arest(event.y)
# 判断,如果向上拖拽
if newIndex < listbox.index:
# 获取新位置的内容
x = (newIndex)
# 删除新内容
listbox.delete(newIndex)
# 将新内容插⼊,相当于插⼊我们移动后的位置
listbox.insert(newIndex +1, x)
# 把需要移动的索引值变成我们所希望的索引,达到了移动的⽬的
listbox.index = newIndex
elif newIndex > listbox.index:
# 获取新位置的内容
x = (newIndex)
# 删除新内容
listbox.delete(newIndex)
# 将新内容插⼊,相当于插⼊我们移动后的位置
listbox.insert(newIndex -1, x)
# 把需要移动的索引值变成我们所希望的索引,达到了移动的⽬的
listbox.index = newIndex
#
def listbox_delete():
listbox.delete(0, tk.END)
#
def open_hebing():
Filer_paths = filedialog.askopenfilenames(filetypes=[("⽂本","txt")], title="供地坐标合并")# 获取需要转换的规划⽂件绝对路径if not Filer_paths:
return
return Filer_paths
def list_save2():# 选择需要处理的⽂件,循环插⼊路径到列表框
for x in open_hebing():
listbox.insert(tk.END, x)
listbox.bind('<Button-1>', show)
listbox.bind('<Button-1>', show)
listbox.bind('<B1-Motion>', showInfo)
def get_hebing():
n =0
textk =[]
save_text = filedialog.asksaveasfilename(defaultextension='.txt', filetypes=[("TXT",".txt")], title="请输⼊保存的⽂件名") if not save_text:
return
plan =open(save_text,"w")
plan2 =open("","w")
lxo = v.get().split("'")
xxo =[xxj for xxj in lxo if len(xxj)>3]# 获取的列表框值提取
for x in xxo:
plan2.write(x)
plan2.write("\n")
n +=1
with open(x)as f:
contentsw = f.readlines()
if n ==1:
textk.append(contentsw)
else:
if"扣除地块"in x:
n -=2# 地块号为1时,在列表中的位置为0
if n ==0:#
textk[n].append("\n")
for c in contentsw[13:]:
textk[n].append(c)# 添加扣除地块,扣除地块不需要前⾯属性值,contentsw取第13个位置
k0 = textk[n][12].split(",")# 第⼀个列表第12个值切⽚
k2 = k0[0]# 取到列表12的位置第1个值,原地块的jzd个数
k22 = k0[1]# 取到列表12的位置第2个值,原地块的⾯积
k1 =(contentsw[12].split(","))[0]# 取到循环contentsw的第⼗⼆个位置切⽚的第1个位置--扣除地块的jzd个数 k11 =(contentsw[12].split(","))[1]# 取到循环contentsw的第⼗⼆个位置切⽚的第2个位置--扣除地块的⾯积 k3 =int(k2)+int(k1)# jzd个数相减
k33 = Decimal(k22)- Decimal(k11)# 地块⾯积相减
k0[0]=str(k3)# 列表k0的第⼀个值替换为相减的jzd
k0[1]=str(k33)# 列表k0的第⼆个值替换为相减的⾯积
textk[n][12]=(",".join(k0))# 列表第n(0)的第12个位置替换为k0--替换的的相减jzd个数,相减的⾯积
n +=1# 因为0+1还是0所以+1让列表继续循环
elif n >0:# 地块号为2时,在列表中的位置为1
textk[n].append("\n")
for c in contentsw[13:]:
textk[n].append(c)# 添加扣除地块,扣除地块不需要前⾯属性值,contentsw取第13个位置
k0 = textk[n][0].split(",")# 地块2在列表中位置为1,取位置1的第12个值切⽚
k2 = k0[0]# 取到列表12的位置第1个值,原地块的jzd个数
k22 = k0[1]# 取到列表12的位置第2个值,原地块的⾯积
k1 =(contentsw[12].split(","))[0]# 取到循环contentsw的第⼗⼆个位置切⽚的第1个位置--扣除地块的jzd个数 k11 =(contentsw[12].split(","))[1]# 取到循环contentsw的第⼗⼆个位置切⽚的第2个位置--扣除地块的⾯积 k3 =int(k2)+int(k1)# jzd个数相减
k33 = Decimal(k22)- Decimal(k11)# 地块⾯积相减
k0[0]=str(k3)# 列表k0的第⼀个值替换为相减的jzd
k0[1]=str(k33)# 列表k0的第⼆个值替换为相减的⾯积
textk[n][0]=(",".join(k0))# 列表第n(0)的第12个位置替换为k0--替换的的相减jzd个数,相减的⾯积
n +=1
else:
textk.append(contentsw[12:])
for xa in textk:
plan.writelines(xa)
plan.write("\n")
plan.write("\n")
plan2.close()
plan.close()
return
# ------------------------------------------------------
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 adlines()[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 = ()
t2 = ()
t3 = ()
t4 = ()
t5 = ()
t6 = ()
t7 = ()
t8 = ()
t9 = ()
t10 = ()
t11 = ()
t12 = ()
t13 = ()
t14 =str(Polygon_area(file_names)[0])
t15 = ()
t16 = ()
t17 = ()
t18 = ()
t19 = ()
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(1),"1", mm[0][2], mm[0][3].replace("\n","")])
Text_default_format[12][0]=str(n +1)
Text_default_format[12][0]=str(n +1)
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:
return
return Filer_paths
def list_save():# 选择需要处理的⽂件,循环插⼊路径到列表框
for x in get_Land_supply_coordinates():
listbox.insert(tk.END, x)
listbox.bind('<Button-1>', show)
listbox.bind('<B1-Motion>', showInfo)
def get_save():# 选择需要保存的路径,循环列表框返回的路径
n =0
mc =1
Save_path = filedialog.askdirectory()# 返回需要保存的绝对路径
if not Save_path:
return
else:
lo = v.get().split("'")
xo =[xj for xj in lo if len(xj)>3]
for Filer_path in xo:# 循环规划⽂件路径
n +=1
Filer_name = Filer_path.split("/")[-1].replace(".txt","(供地坐标).txt")# 获取规划⽂件⽂件名
new_filer =open(Save_path +"/"+ Filer_name,"w")# 打开⽂本,没有创建
gh = Land_supply_coordinates(Filer_path)
if"扣除地块"in Filer_name:
mc +=1
n -=1
gh[12][2]=str(n)# 扣除地块与地块号保持⼀致
for gg in range(len(gh[13:])):# 循环列表位置13开始的值
gh[13:][gg][1]=str(mc)# 第⼆个位置的1改为mc
else:
gh[12][2]=str(n)
mc =1
for new_lines in gh:# 循环列表
new_filer.writelines(",".join(new_lines))# 列表⽤“,”合并,写⼊
new_filer.close()# 关闭⽂本
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 = 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)
getsavefilenametext6_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'默认')
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'默认(1,)')
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论