In QGIS there is an option to select features of a selected layer using a "identify feature" tool. Then the feature get highlighted in a different color and attribute dialog is poping up. like that i want to highlight the multiple features programatically.

Ex: I have a set of vector layers which consists of number of roads as features. I need to select few roads by looking at its attributes and highlight.

Is there any way of achieving this using python code?

  • hi guys, can we achieve this through a qgis python plugin?
    – keth
    Commented Feb 19, 2014 at 19:04

1 Answer 1


After few days of playing with QGIS, finally found a solution. There is a method in QgsVectorLayer class called setSelectedFeatures (const QgsFeatureIds &ids).


for feature in layer.getFeatures():
    geom = feature.geometry()
    roadNo = feature.attribute("Road_no")
    if roadNo == row[0].strip():

Hope this helps,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.