Friday, 30 January 2015

pyqgis - Selecting and Identifying Single Feature using QGIS Plugin?


given is a layer with some nodes on it and every node has some attributes(name, id, etc...). For showing up the informations of a single node I can use the "Identify Feature Tool". Choose the tool, click the node and see the informations. I am trying to develop a Plugin with Python, which is doing almost the same: Start the Plugin, click on a node and get the informations about this node(output in the python console is enough for the first steps). Okay, so this is the status: I was following this tutorial: http://www.qgisworkshop.org/html/workshop/plugins_tutorial.html which works not for QGIS 2.0. The 'MouseClickEvent' is working, I get the X,Y-coordinates. But I am not able to select and to get the informations of a node. That is my selectFeature function, which is called by result = QObject.connect(self.clickTool, SIGNAL("canvasClicked(const QgsPoint &, Qt::MouseButton)"), self.selectFeature):


def selectFeature(self, point, button):
#pntGeom = QgsGeometry.fromPoint(point)
#pntBuff = pntGeom.buffer( (self.canvas.mapUnitsPerPixel() * 2),0)
#rect = pntBuff.boundingBox()

layer = self.canvas.currentLayer()

selected_features = layer.selectedFeatures()
for i in selected_features:
attrs = i.attributeMap()
for (k,attr) in attrs.iteritems():
print "%d: %s" % (k, attr.toString())

This let me see nothing. I was reading and trying out a lot of things and at the moment in feel a bit lost. I lost the overview.


Do I need these geometry functions to capture the node by clicking the mouse button?


What functions do I need to get the attributes of a single selected feature?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...