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?

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

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, privacy policy and cookie policy

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