How to access QGIS menu items using python

1.1k Views Asked by At

I've managed to put together some python code that loads some point data from a csv and displays it on the screen. However, I woul now like to create some Voronoi polygons from the points using the Voronoi polygon tool that is listed under the menu Vector->Geometry Tools -> Voronoi Polygons (I'm using QGIS version 2.4.0). Is there a python method that allows access to the drop down menu items? If somebody could point towards and similar example that would be appreciated. I would like to add the voroni polygon process to the code below.

#--- 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

There are 0 best solutions below