• pyqgis学习


    1.
    错误:ImportError: No module named qgis.core
    解决方法:python的qgis,初始化变量:
    D:PROGRA~1QGIS3~1.0OSGeo4W.bat
    D:PROGRA~1QGIS3~1.0inpy3_env.bat
    D:PROGRA~1QGIS3~1.0inqt5_env.bat
    SET PYTHONPATH=D:PROGRA~1QGIS3~1.0appsqgispython;D:PROGRA~1QGIS3~1.0appsQt5plugins
    SET PATH=D:PROGRA~1QGIS3~1.0appsQt5plugins;%PATH%

    2.
    错误:This application failed to start because it could not find or load the Qt platform plugin "windows"
    in "".
    解决方法:把 包含qwindows.dll的目录platform复制到 D:Program FilesQGIS 3.0in

    3.
    错误:QgisProject.read和QgisVectorLayer构造失败
    解决方法:
    环境变量没有设定好,在qgis.bat基础上去掉启动qgis,增加环境变量PYTHONPATH

    4.
    错误:QtCore.pyqtSignal信号发射接收问题解决
    解决方法:
    1.QtCore.pyqtSignal必须声明为类的变量
    2.所在类必须继承与QtObject
    3.构造函数必须直接调用QtCore.QObject.__init__(self)

    5.
    错误:在qtthread中启动httpserver崩溃的问题
    解决方法:
    1.原因python的httpserver模块默认打印到控制台,会导致qgis应为同步问题崩溃
    2.重载BaseHTTPRequestHandler的log_message方法,去掉打印

    5.
    多线程使用HTTPServer服务,并和主线程通讯的例子

    from http.server import BaseHTTPRequestHandler
    from http.server import HTTPServer
    from PyQt5 import QtCore
    import time
    
    class MyHttpServer(HTTPServer):
        def log_message(self, format, *args):
            pass
    
    class TodoHandler(BaseHTTPRequestHandler):
        def do_GET(self):
            if self.path != '/':
                self.send_error(404, "File not found.")
                return
            self.send_response(200)
            self.send_header('Content-type', 'application/json')
            self.end_headers()
            self.wfile.write(b"{}")
    
            self.server.request_.emit( 5.0, 5.0 )
     
        def log_message(self, format, *args):
            pass
    
    class TestRun(QtCore.QObject):
    
        request_ = QtCore.pyqtSignal(float, float)
    
        def __init__(self):
            QtCore.QObject.__init__(self)
    
        def run(self):
            #for i in range(0,100):
            #    time.sleep(0.1)
            #    print(i)
            #print('-- server running --')
            server = MyHttpServer(('localhost', 8888), TodoHandler)
            server.request_ = self.request_
            server.serve_forever()
    
    class TestRev(QtCore.QObject):
        def __init__(self):
            QtCore.QObject.__init__(self)
    
        def onRequest(self, x, y):
            ext = iface.mapCanvas().extent()
            ext += QgsVector(int(x),int(y))
            iface.mapCanvas().setExtent(ext)
    
        def onError(self, e, exception_string):
            print('Worker thread raised an exception:
    '.format(exception_string))
        
    a = TestRev()
    
    r = TestRun()
    t = QtCore.QThread()
    r.moveToThread(t)
    r.request_.connect(a.onRequest)
    t.started.connect(r.run)
    t.start()





  • 相关阅读:
    H5中https://j.map.baidu.com/e7/M6hJ的地址是如何生成的
    转义符
    vue-json-excel导出数字字符串转为科学计数法问题和文件格式问题
    高级JavaScript(4)RegExp,正则表达式
    js7种数据类型
    gulp自动化打包及静态文件自动添加版本号
    解决——CSS :before、:after ,当content使用中文时有时候会出现乱码
    【移动端】移动端点击可点击元素时,出现蓝色默认背景色
    我去!爬虫遇到字体反爬,哭了
    实战|教你用Python玩转Mysql
  • 原文地址:https://www.cnblogs.com/adgnat/p/9025049.html
Copyright © 2020-2023  润新知