如何使用python访问QGIS菜单项

时间:2014-11-26 02:48:16

标签: python qgis

我设法将一些python代码放在​​一起,从csv加载一些点数据并将其显示在屏幕上。但是,我现在想要使用菜单Vector-> Geometry Tools - >中列出的Voronoi多边形工具从点创建一些Voronoi多边形。 Voronoi Polygons(我正在使用QGIS版本2.4.0)。是否有允许访问下拉菜单项的python方法?如果有人可以指出和类似的例子,将被赞赏。我想将voroni多边形过程添加到下面的代码中。

#--- Load a csv file and set CRS
#---1 Reference library
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from qgis.core import *
from qgis.utils import iface

#---  2 Turn of the CRS dialog box
s = QSettings()
oldValidation = s.value( "/Projections/defaultBehaviour")
s.setValue( "/Projections/defaultBehaviour", "useGlobal" )

#--- 3 Set file name here
InFlnm='Test.csv'

#--- 4  Set pathname here
InDrPth='C:/_Work/PyQGIS/Test/'

#--- 5 Build file name an path for uri
InFlPth="file:///"+InDrPth+InFlnm

#---  6 Set import Sting here note only need to set x and y other come for free
uri = InFlPth+"?delimiter=%s&xField=%s&yField=%s" % (",","x","y")

#--- 7 Load point layer
bh = QgsVectorLayer(uri, InFlnm, "delimitedtext")

#--- 8 Set CRS - this does not appear to work not sure why but no matter the damn thing loads!
bh.setCrs(QgsCoordinateReferenceSystem(4326, QgsCoordinateReferenceSystem.EpsgCrsId))

#--- 9 Display the layer into QGIS (but it asks for CRS before displaying_
QgsMapLayerRegistry.instance().addMapLayer(bh)

#--- 10 turn CRS dialog box back on again
s.setValue( "/Projections/defaultBehaviour", oldValidation )

0 个答案:

没有答案