[Qgis-developer] Get Feature Id on clicked point
Arpita Singh
singarpita at gmail.com
Tue Mar 16 14:34:14 EDT 2010
Hi All
I am trying to build an application in which I am unable to retrieve the
featureId of the Feature at user clicked point, instead it is giving
featureId one by one sequentially...
can any one help by giving some code in python.
My function is given as:
def sel1(self,p,b):
transform = self.canvas.getCoordinateTransform()
mapPoint = transform.toMapCoordinates(p.x(),p.y())
provider = layer.getDataProvider()
feat = QgsFeature()
allAttrs = provider.allAttributesList()
provider.select(allAttrs, QgsRect(), False)
RubberBand=QgsRubberBand
g = feat.setGeometry(QgsGeometry.fromPoint(QgsPoint(p.x(),p.y())))
geom = feat.geometry()
RubberBand = QgsRubberBand(self.canvas,geom.vectorType() == QGis.Polygon)
RubberBand.setToGeometry(geom,layer)
RubberBand.setWidth(2)
RubberBand.setColor(Qt.red)
RubberBand.show()
while provider.getNextFeature(feat):
attrs = feat.attributeMap()
self.screen = QTextEdit()
self.screen.setReadOnly(1)
self.screen.show()
self.screen.setWindowTitle(self.tr("Identify Result"))
self.screen.setWindowIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__),"\project\icons\mIconNew.png")))
loc4 = QString("Map Coords :"+ str(p.x()) + ", " + str(p.y()))
self.screen.append(loc4)
loc1 = QString("\n" + "Feature ID : " + str(feat.featureId()))
self.screen.append(loc1)
for k in attrs:
if k == 0:
loc = QString("Plot Id" + ": " + str(attrs[k].toString()))
if k == 1:
loc = QString("Text Size" + ": " + str(attrs[k].toString() ))
if k == 2:
loc = QString("Text String" + ": " + str(attrs[k]))
elif k > 2:
loc = QString("Field" + " " + str(k) + ": " + str(attrs[k]))
self.screen.append(loc)
--
Regards
Arpita
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20100317/df5b7288/attachment.html
More information about the Qgis-developer
mailing list