无法在Pyqt5应用程序中导出Folium绘制多边形上的坐标

Cant export coordinates on Folium draw polygon in Pyqt5 app(无法在Pyqt5应用程序中导出Folium绘制多边形上的坐标)
本文介绍了无法在Pyqt5应用程序中导出Folium绘制多边形上的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用pyqt5编写应用程序,使用Folium来标记一些区域并获得GPS坐标。应用程序工作,我可以画多边形,但当我点击导出按钮,没有任何反应。也许有人遇到了类似的问题,知道原因吗?
import folium, io, sys
from folium.plugins.draw import Draw
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
from PyQt5 import QtWebEngineWidgets

class Mapy(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.interfejs()

    def interfejs(self):
        vbox = QVBoxLayout(self)
        self.webEngineView = QtWebEngineWidgets.QWebEngineView()
        self.loadPage()
        vbox.addWidget(self.webEngineView)
        self.setLayout(vbox)
        self.setGeometry(300, 300, 350, 250)
        self.setWindowTitle('mapy')
        self.show()

    def loadPage(self):
        m = folium.Map(
            location=[51.7687323,19.4569911], zoom_start=5
        )
        Draw(
            export=True,
            filename='my_data.geojson',
            position='topleft',
            draw_options={'polyline': False, 'rectangle': False,'circle':False, 'circlemarker':False},
            edit_options={'poly': {'allowIntersection': False}}
        ).add_to(m)
        data = io.BytesIO()
        m.save(data, close_file=False)
        self.webEngineView.setHtml(data.getvalue().decode())

if __name__ == '__main__':
    app = QApplication(sys.argv)
    okno = Mapy()
    sys.exit(app.exec_())

推荐答案

您必须使用页面配置文件中的downloadRequested信号管理下载:

import io
import sys

import folium
from folium.plugins.draw import Draw

from PyQt5.QtWidgets import QApplication, QFileDialog, QVBoxLayout, QWidget
from PyQt5.QtWebEngineWidgets import QWebEngineView


class Mapy(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.interfejs()

    def interfejs(self):
        vbox = QVBoxLayout(self)
        self.webEngineView = QWebEngineView()
        self.webEngineView.page().profile().downloadRequested.connect(
            self.handle_downloadRequested
        )
        self.loadPage()
        vbox.addWidget(self.webEngineView)
        self.setLayout(vbox)
        self.setGeometry(300, 300, 350, 250)
        self.setWindowTitle("mapy")
        self.show()

    def loadPage(self):
        m = folium.Map(location=[51.7687323, 19.4569911], zoom_start=5)
        Draw(
            export=True,
            filename="my_data.geojson",
            position="topleft",
            draw_options={
                "polyline": False,
                "rectangle": False,
                "circle": False,
                "circlemarker": False,
            },
            edit_options={"poly": {"allowIntersection": False}},
        ).add_to(m)
        data = io.BytesIO()
        m.save(data, close_file=False)
        self.webEngineView.setHtml(data.getvalue().decode())

    def handle_downloadRequested(self, item):
        path, _ = QFileDialog.getSaveFileName(
            self, "Save File", item.suggestedFileName()
        )
        if path:
            item.setPath(path)
            item.accept()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    okno = Mapy()
    sys.exit(app.exec_())

这篇关于无法在Pyqt5应用程序中导出Folium绘制多边形上的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)