主要内容
设计一个可视化界面,编写相应代码,实现的功能有:可以输入某一地方经纬度,选择比例尺,选择东、西经,计算该地的90年代后的分幅编号,并将结果显示。
设计思路
主要包括input、scaleConvert、main三个文件。其中:input文件实现计算参数的输入与结果显示,scaleConvert文件实现不同比例尺下的参数转换,mian文件实现程序数据的计算。
代码实现
main.py文件
# 计算90年代后我国地形图的分幅编号
import math as ma
# import input
import scaleConvert as sC
'''
x: 纬差
y: 经差
a:1比100万图幅所在纬度带的字符所 对应的数字码
b:1比100万图幅所在经度带的数字码
c:1比100万图幅编号后所在行号
d:1比100万图幅编号后所在列号
'''
# 计算1:100w以下比例的图幅编号
def minNumbering(lon, lat, scale, ew):
x = sC.latitudeConvert(scale)
y = sC.longitudeConvert(scale)
a = ma.floor(lat / 4) + 1
be = ma.floor(lon / 6) + 31
bw = 30 - ma.floor(lon / 6)
c = str(int((4 / x) - (ma.floor((lat % 4) / x))))
d = str(ma.floor((lon % 6) / y) + 1)
c1 = c.zfill(3)
d1 = d.zfill(3)
ch1 = chr(ord(chr(a + 64)))
ch2 = sC.scaleCodeConvert(scale)
if ew == 2:
return ch1 + str(be) + ch2 + str(c1) + str(d1)
elif ew == 1:
return ch1 + str(bw) + ch2 + str(c1) + str(d1)
else:
return "计算错误"
# print("比例尺为:")
# print(ch1 + str(b) + ch2 + str(c1) + str(d1))
# 获取经纬度
def main():
lat = eval(input("输入纬度:")) # 输入纬度
lon = eval(input("输入经度:")) # 输入经度
scale = input("输入比例尺:(100万,50万,10万,5万,2.5万,1万,5千)") # 输入比例
minNumbering(lon, lat, scale)
return lat, lon, scale
if __name__ == '__main__':
main()
scaleConvert.py文件
# 比例尺代码转换
def scaleCodeConvert(scale):
numbers = {
"1:100万": "A",
"1:50万": "B",
"1:25万": "C",
"1:10万": "D",
"1:5万": "E",
"1:2.5万": "F",
"1:1万": "G",
"1:5千": "H"
}
return numbers.get(scale, None)
# 经差转换
def longitudeConvert(scale):
numbers = {
"1:100万": 6,
"1:50万": 3,
"1:25万": 2/3,
"1:10万": 1/2,
"1:5万": 1/4,
"1:2.5万": 1/8,
"1:1万": 1/16,
"1:5千": 1/32
}
return numbers.get(scale, None)
# 纬差转换
def latitudeConvert(scale):
numbers = {
"1:100万": 4,
"1:50万": 2,
"1:25万": 1,
"1:10万": 1/2,
"1:5万": 1/3,
"1:2.5万": 1/6,
"1:1万": 1/12,
"1:5千": 1/24
}
return numbers.get(scale, None)
gui.py文件
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
import main
def getSelection():
scale = var.get()
ew = var1.get()
n1 = eval(v.get())
n2 = eval(latitudeE.get())
messagebox.showinfo("计算结果", main.minNumbering(n2, n1, scale, ew))
root = Tk()
root.title("计算地图编号")
root.geometry("350x300+500+250")
var1 = IntVar()
var1.set(1)
label = Label(root, text="选择经度范围", width=30)
label.grid(row=0, column=1)
choice1 = Radiobutton(root, text="西经", variable=var1, value=1, command=getSelection)
choice1.grid(row=0, column=1)
choice2 = Radiobutton(root, text="东经", variable=var1, value=2, command=getSelection)
choice2.grid(row=1, column=1)
v = StringVar()
longitudeL = Label(root, text="输入经度")
longitudeL.grid(row=6, column=0, pady=5)
latitudeL = Label(root, text="输入纬度")
latitudeL.grid(row=7, column=0, pady=5)
longitudeE = Entry(root, textvariable=v)
latitudeE = Entry(root)
longitudeE.grid(row=6, column=1, pady=5)
latitudeE.grid(row=7, column=1, pady=5)
surebtn = Button(root, text="确定经纬度参数", command=getSelection)
surebtn.grid(row=8, column=1, pady=5)
exitbtn = Button(root, text="退出程序", command=root.destroy)
exitbtn.grid(row=15, column=1, pady=5)
var = StringVar()
cb = Combobox(root, textvariable=var)
cb["value"] = "1:100万", "1:50万", "1:25万", "1:10万", "1:5万", "1:2.5万", "1:1万", "1:5千"
cb.current(0)
cb.grid(row=3, column=1, pady=10)
btn = Button(root, text="选择比例尺", command=getSelection)
btn.grid(row=4, column=1, pady=10)
root.mainloop()
运行结果
|