首页 新闻 会员 周边

Python 地图数据检查工具 急急急

0
悬赏园豆:140 [待解决问题]

题目是
代码用python实现
设计开发用于空间数据质量检查的应用软件工具,该工具运行于单PC机桌面环境,不需要网络连接;说明及评估所采用的软件架构风格。
(1)基本功能要求:
A、地图数据加载:从应用中打开指定的图形或文档类型地图数据文件,并显示在应用程序窗口中。
B、地图数据显示:针对不同类型数据采用不同方式:图形形式的可视化符号显示(主要有栅格及矢量格式类型,原型中至少实现其中一种类型的可视化进行示意);文本形式直接显示数值内容(原型中可用普通文本文件示意)。
C、错误记录:通过在图形中或文本中指定位置,标记各项错误的位置;指出错误位置后,输入错误类型、错误描述等信息并自动给错误编号;在文件中保存所记录的错误信息。
D、错误记录查询:地图数据加载后,在质检工具中打开已保存的错误信息文件,可通过输入关键字搜索并显示出错情况。
(2)成果提交:
A、软件架构说明。说明所采用的软件架构风格及主要优缺点。
B、软件源码及可执行代码包。实现基本功能要求。提示:可使用所学编程语言平台中FILE I/O API及GUI构件。

代码

import json
import tkinter as tk
from tkinter import filedialog, messagebox, Text, Scrollbar
import geopandas as gpd
import rasterio
from rasterio.plot import show as rasterio_show
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
class SpatialQualityCheckApp:
def init(self, root):
self.root = root
self.root.title("空间数据质量检查工具")

    # 创建菜单
    menu = tk.Menu(self.root)
    self.root.config(menu=menu)
    
    file_menu = tk.Menu(menu, tearoff=0)
    file_menu.add_command(label="打开地图数据", command=self.load_map_data)
    file_menu.add_command(label="保存错误记录", command=self.save_error_record)
    file_menu.add_command(label="退出", command=root.quit)
    
    menu.add_cascade(label="文件", menu=file_menu)
    
    
    # 创建界面组件
    self.figure = plt.figure(figsize=(6, 6))
    self.canvas = FigureCanvasTkAgg(self.figure, master=self.root)
    self.canvas_widget = self.canvas.get_tk_widget()
    self.canvas_widget.pack(pady=20)
    
    self.error_label = tk.Label(self.root, text="错误记录")
    self.error_label.pack(pady=10)
    
    self.error_text = Text(self.root, width=80, height=10)
    self.error_text.pack(pady=10)
    
    self.scrollbar = Scrollbar(self.root, command=self.error_text.yview)
    self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
    self.error_text.config(yscrollcommand=self.scrollbar.set)
    
    self.search_label = tk.Label(self.root, text="搜索关键字")
    self.search_label.pack(pady=10)
    
    self.search_entry = tk.Entry(self.root)
    self.search_entry.pack(pady=10)
    
    self.search_button = tk.Button(self.root, text="搜索", command=self.search_error_record)
    self.search_button.pack(pady=10)
    
    # 初始化变量
    self.map_data = None
    self.error_data = []
    
def load_map_data(self):
    file_path = filedialog.askopenfilename(title="选择地图数据文件", filetypes=[("GeoJSON files", "*.geojson"), ("Shapefile", "*.shp"), ("Raster files", "*.tif"), ("Text files", "*.txt")])
    
    if file_path:
        self.plot_map_data(file_path)
    
def plot_map_data(self, file_path):
    self.figure.clear()
    self.error_data.clear()
    self.error_text.delete(1.0, tk.END)
    
    if file_path.endswith('.geojson') or file_path.endswith('.shp'):
        # 读取地图数据
        self.map_data = gpd.read_file(file_path)
        
        # 矢量数据,使用 geopandas 进行可视化
        ax = self.figure.add_subplot(111)
        self.map_data.plot(ax=ax)
        ax.set_aspect('equal')
        self.canvas.draw()
        
    elif file_path.endswith('.tif'):
        # 栅格数据,使用 rasterio 进行可视化
        with rasterio.open(file_path) as src:
            ax = self.figure.add_subplot(111)
            rasterio_show(src, ax=ax)
            ax.set_aspect('equal')
            self.canvas.draw()
            
    elif file_path.endswith('.txt'):
        # 文本文件,直接显示数值内容
        with open(file_path, 'r') as f:
            content = f.read()
        self.error_text.insert(tk.END, content)
        
    else:
        messagebox.showinfo("提示", "不支持的文件格式")
        
def save_error_record(self):
    error_info = {
        'errors': self.error_data
    }
    
    file_path = filedialog.asksaveasfilename(title="保存错误记录", defaultextension=".json", filetypes=[("JSON files", "*.json")])
    
    if file_path:
        with open(file_path, 'w') as f:
            json.dump(error_info, f)
            
def search_error_record(self):
    keyword = self.search_entry.get()
    
    results = [error for error in self.error_data if keyword in error['description']]
    
    self.error_text.delete(1.0, tk.END)
    
    for result in results:
        self.error_text.insert(tk.END, f"错误编号:{result['id']}, 错误类型:{result['type']}, 错误描述:{result['description']}\n")

if name == "main":
root = tk.Tk()
app = SpatialQualityCheckApp(root)
root.mainloop()

结果是这样的

可要求要做成这样的

我的地图数据导入和交互都出现了问题不知道怎么解决

Maple_01的主页 Maple_01 | 初学一级 | 园豆:4
提问于:2024-04-05 13:09
< >
分享
所有回答(1)
0

同学,你也是武大遥感空信的吧

xbhyd | 园豆:202 (菜鸟二级) | 2024-04-15 17:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册