从PyProj库提取CRS编码:Python程序问题求助与解决
PyProj CRS选择器程序问题及解决
问题背景
需要开发Python程序,从PyProj库获取CRS编码/定义并生成列表,支持用户通过下拉列表选择CRS并打印所选内容,但程序运行报错,已将PyProj更新至最新版本。
尝试的代码
import tkinter as tk from tkinter import ttk import pyproj def get_crs_list(): # 从pyproj CRS数据库获取可用CRS编码列表 crs_list = list(pyproj.database.get_codes("CRS")) return sorted(crs_list) def print_selected_crs(): selected_crs = combobox.get() print("Selected CRS:", selected_crs) # 创建主应用窗口 root = tk.Tk() root.title("CRS选择器") # 创建标签和下拉列表用于选择CRS label = ttk.Label(root, text="选择CRS:") label.pack(pady=10) crs_list = get_crs_list() combobox = ttk.Combobox(root, values=crs_list) combobox.pack() # 创建按钮用于打印所选CRS button = ttk.Button(root, text="打印CRS", command=print_selected_crs) button.pack(pady=10) # 启动主事件循环 root.mainloop()
报错信息
line 7, in get_crs_list crs_list = pyproj.get_crs_list() AttributeError: module 'pyproj' has no attribute 'get_crs_list'
可行解决方案代码
def get_crs_list(): crs_info_list = pyproj.database.query_crs_info(auth_name=None, pj_types=None) crs_list = ["EPSG:" + info[1] for info in crs_info_list] print(crs_list) return sorted(crs_list) # 输出示例: # ['EPSG:2000', 'EPSG:2001', 'EPSG:2002', 'EPSG:2003', 'EPSG:2004',.......]
内容的提问来源于stack exchange,提问作者Hanzo Hasashi
相关产品推荐
相关产品推荐

