7

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?

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

1 Answer 1

14

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

selection=[]

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

Hope this helps,

Your Answer

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

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