37,720
社区成员
发帖
与我相关
我的任务
分享
#!/usr/local/env python
#-*- coding:utf-8 -*-
def getcrd(crdfile):
D = {}
coordlist = open(crdfile,'r')
for eachline in coordlist:
row = eachline.split()
D[row[0]] = row[1] + ' ' + row[2]
return D
def getlas(D, lasfile):
pathlist = lasfile.split('/')
wellname = lasfile[-1]
pathname = '/'.join(pathlist[0:-1])
newpathname = pathname + "/crdlasfile"
if os.path.isdir(newpathname):
crdpath = newpathname
else:
crdpath = os.mkdir(newpathname)
if wellname in D.keys():
crd = D[wellname].split()
xcrd = crd[0]
ycrd = crd[1]
oldlasfile = open(lasfile,'r')
resultfilename = crdpath + '/' + wellname + '.las'
newlasfile = open(resultfilename, 'w')
i = 0
for aline in oldlasfile:
newlasfile.write(aline)
if aline[0:3] == "UWI":
newlasfile.write("XCRD. " + xcrd + ": \n")
newlasfile.write("YCRD. " + ycrd + ": \n")
oldlasfile.close()
newlasfile.close()
else:
logname = crdpath + '/log.txt'
log = open(logname,'a')
log.write(wellname + " isn't in well coordiante file\n")
class TopApp:
def __init__(self, root):
# sone var for return
self.crdname = tkinter.StringVar()
self.lasname = tkinter.StringVar()
# a frame for place widgets
self.frame = tkinter.Frame(root)
# the programe name label
self.labeltitle = tkinter.Label(self.frame, text="Add coordinate to Las file", font="Arial -16 bold")
self.labeltitle.pack()
# the first labelframe for selecting coordinate file
self.labelcrd = tkinter.LabelFrame(self.frame, text=" Select coordinates file: ", labelanchor='nw', relief='groove', bd=2)
self.labelcrd.pack(anchor='w', ipadx=2, ipady=2, padx=2, pady=2)
self.entry = tkinter.Entry(self.labelcrd, bd=2, width=50, textvariable=self.crdname)
self.entry.pack(anchor='w', padx=2, pady=5)
self.buttoncrd = tkinter.Button(self.labelcrd, bd=2, text='Select...', width=10, command=self.COnSelectCrd)
self.buttoncrd.pack(after=self.entry, anchor='e', padx=5, pady=2)
self.buttoncrd.bind('<ButtonRelease-1>', self.COnSelectCrd)
# the second labelframe for selecting las files
self.labellas = tkinter.LabelFrame(self.frame, text=" Select las files: ",labelanchor='nw', relief='groove', bd=2)
self.labellas.pack(anchor='w', ipadx=2, ipady=2, padx=2, pady=2)
# a frame for place listbox and scrollbar
self.listframe = tkinter.Frame(self.labellas)
self.ysrb = tkinter.Scrollbar(self.listframe, orient="vertical")
self.ysrb.pack(side='right', fill='y')
self.dirlist = tkinter.Listbox(self.listframe, bd=2, width=50, listvariable=self.lasname, yscrollcommand=self.ysrb.set)
self.dirlist.pack(anchor='w', padx=2, pady=2)
self.ysrb["command"] = self.dirlist.yview
self.listframe.pack()
#a button for selecting las files
self.buttonlas = tkinter.Button(self.labellas, bd=2, text="Select...", width=10, command=self.COnSelectLas)
self.buttonlas.pack(after=self.listframe, anchor='e', padx=5, pady=2)
# the button for exiting programe
self.buttonexit = tkinter.Button(self.frame, text="Exit", bd=2, width=10, command=root.quit)
self.buttonexit.pack(side='right', padx=5, pady=2)
# the button for running programe
self.buttonrun = tkinter.Button(self.frame, text="Run", bd=2, width=10)
self.buttonrun.pack(side='right', anchor='e', padx=5, pady=2)
#self.buttonrun.bind('<ButtonRelease-1>', getlas())
self.frame.pack()
def COnSelectCrd(self):
filename = tkinter.filedialog.askopenfilename(title="Coordinate file")
self.crdname.set(filename)
def COnSelectLas(self):
filelist = tkinter.filedialog.askopenfilenames(title="Las files")
self.lasname.set(filelist)
if __name__ == "__main__":
import os
import tkinter
root = tkinter.Tk()
root.title("Crd2Las")
TopApp(root)
root.mainloop()
#crd = getcrd("coordinate.prn")
#getlas(crd, "Y57.LAS")