[Qgis-developer] Problem with a plugin to select polylines
boesiii
boesiii at yahoo.com
Thu Oct 18 11:51:44 PDT 2012
Hello All,
I am starting to develop my own plugin by starting and following
instructions at www.qgisworkshop.org but the plugin does not work when the
data is a polyline. Below is part of the plugin that deals with feature
selection. What do I need to change so that it will select polylines?
def selectFeature(self, point, button):
QMessageBox.information( self.iface.mainWindow(),"Info", "in
selectFeature function" )
# setup the provider select to filter results based on a rectangle
pntGeom = QgsGeometry.fromPoint(point)
# scale-dependent buffer of 2 pixels-worth of map units
pntBuff = pntGeom.buffer( (self.canvas.mapUnitsPerPixel() * 1),0)
rect = pntBuff.boundingBox()
# get currentLayer and dataProvider
cLayer = self.canvas.currentLayer()
selectList = []
if cLayer:
provider = cLayer.dataProvider()
feat = QgsFeature()
# create the select statement
provider.select([],rect) # the arguments mean no attributes
returned, and do a bbox filter with our buffered rectangle to limit the
amount of features
while provider.nextFeature(feat):
# if the feat geom returned from the selection
intersects our point then put it in a list
if feat.geometry().intersects(pntGeom):
selectList.append(feat.id())
# make the actual selection
cLayer.setSelectedFeatures(selectList)
else:
QMessageBox.information( self.iface.mainWindow(),"Info", "No
layer currently selected in TOC" )
Thanks for the help,
Ed
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Problem-with-a-plugin-to-select-polylines-tp5009694.html
Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
More information about the Qgis-developer
mailing list