Qgis 里的Python腳本介紹


QGIS 入門演示之《用 QGIS 畫矢量交通路線圖

腳本編程之准備知識《Python 教程

QGIS API

QGIS插件庫

運行QGIS腳本,對於桌面應用來講有4種方式:

  • QGIS 啟動時自動運行Python腳本
  • QGIS 控制台中運行發布的Python命令
  • 創建Python寫的插件
  • 創建基於QGIS API的應用程序

QGIS服務端綁定:

  • 2.8 開始,QGIS服務端包含Python插件 (see: Server Python Plugins)
  • 2.11開始 (2015-08-11), QGIS 服務庫包含Python 綁定,可以在Python應用中嵌入QGIS服務。

1、 啟動腳本

啟動腳本可以通過指定環境變量PYQGIS_STARTUP來指定啟動時運行的腳本。也可以編輯位於安裝目錄.qgis2/python/startup.py 文件。

2、控制台

通過菜單:Plugins ‣ Python Console 來打開。

3、插件

如何創建插件

4、應用程序

1) 獨立腳本

使用PyQGIS 來創建腳本

from qgis.core import *

# supply path to qgis install location
QgsApplication.setPrefixPath("/path/to/qgis/installation", True)

# create a reference to the QgsApplication, setting the
# second argument to False disables the GUI
qgs = QgsApplication([], False)

# load providers
qgs.initQgis()

# Write your code here to load some layers, use processing algorithms, etc.

# When your s

 

2)自定義程序

from qgis.core import * # supply path to qgis install location QgsApplication.setPrefixPath("/path/to/qgis/installation", True) # create a reference to the QgsApplication # setting the second argument to True enables the GUI, which we need to do # since this is a custom application qgs = QgsApplication([], True) # load providers qgs.initQgis() # Write your code here to load some layers, use processing algorithms, etc. # When your script is complete, call exitQgis() to remove the provider and # layer registries from memory qgs.exitQgis()

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM