[Qgis-developer] Identify Feature programatically (PyQgis) ?

Martin Dobias wonder.sk at gmail.com
Tue Jan 20 07:09:27 PST 2015


Hi Joseph

If you just want to highlight a particular feature, you do not need to use
the identify tool. The following code will load a feature and highlight it
in canvas. It should work if you try it in QGIS python console.

l = iface.activeLayer()   # your layer
fid = 10   # your feature id

from PyQt4.QtCore import Qt
from qgis.gui import *
f = l.getFeatures(QgsFeatureRequest(fid)).next()
r = QgsRubberBand(iface.mapCanvas())
r.setColor(Qt.red)
r.setToGeometry(f.geometry(), l)
r.show()

If your layer is a polygon layer (instead of line layer), add second
argument to QgsRubberBand with value QGis.Polygon

Cheers
Martin


On Sat, Jan 17, 2015 at 4:08 AM, jKrienert <krienert at gmail.com> wrote:

> Hoping to activate the identify feature tool for a specific feature via
> PyQgis.
> I have asked the question in another forum (link below), but it seemed that
> planting a seed here might help reveal a solution.
> gis.stackexchange posting
> <
> http://gis.stackexchange.com/questions/130552/identifyfeature-use-via-pyqgis
> >
> After spending much time on the issue, I am concerned as to if even such a
> process is possible...
>
>
>
> --
> View this message in context:
> http://osgeo-org.1560.x6.nabble.com/Identify-Feature-programatically-PyQgis-tp5181980.html
> Sent from the Quantum GIS - Developer mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150120/7b16d2f5/attachment.html>


More information about the Qgis-developer mailing list