Getting particular feature using expression in PyQGIS? [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How to get a particular feature using an expression in PyQGIS?
For example, there are 100 houses (with 100 entries in Attributes Table). I want to get only one house with field name ("name"=="John's House"
) and make get selected that feature in the map view.
pyqgis select-by-attribute
closed as off-topic by ahmadhanb, Jochen Schwarze, wetland, BERA, whyzar Mar 15 at 13:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – ahmadhanb, Jochen Schwarze, BERA, whyzar
add a comment |
How to get a particular feature using an expression in PyQGIS?
For example, there are 100 houses (with 100 entries in Attributes Table). I want to get only one house with field name ("name"=="John's House"
) and make get selected that feature in the map view.
pyqgis select-by-attribute
closed as off-topic by ahmadhanb, Jochen Schwarze, wetland, BERA, whyzar Mar 15 at 13:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – ahmadhanb, Jochen Schwarze, BERA, whyzar
What have you tried by so far?
– Taras
Mar 15 at 7:09
2
Possible duplicate one more time: gis.stackexchange.com/questions/131158/…. Please take a few minutes to search the web or GIS Stack Exchange before you ask a question.
– Stefan
Mar 15 at 8:20
Thanks, @Stefan, I do not know why but I have not seen that thread
– Taras
Mar 15 at 8:26
Possible duplicate of How to select features using an expression with pyqgis?
– wetland
Mar 15 at 10:22
2
@wetland Possible duplicate of my comment ;).
– Stefan
Mar 15 at 11:02
add a comment |
How to get a particular feature using an expression in PyQGIS?
For example, there are 100 houses (with 100 entries in Attributes Table). I want to get only one house with field name ("name"=="John's House"
) and make get selected that feature in the map view.
pyqgis select-by-attribute
How to get a particular feature using an expression in PyQGIS?
For example, there are 100 houses (with 100 entries in Attributes Table). I want to get only one house with field name ("name"=="John's House"
) and make get selected that feature in the map view.
pyqgis select-by-attribute
pyqgis select-by-attribute
edited Mar 22 at 9:06


Taras
2,3003729
2,3003729
asked Mar 15 at 7:05
DevenepaliDevenepali
302
302
closed as off-topic by ahmadhanb, Jochen Schwarze, wetland, BERA, whyzar Mar 15 at 13:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – ahmadhanb, Jochen Schwarze, BERA, whyzar
closed as off-topic by ahmadhanb, Jochen Schwarze, wetland, BERA, whyzar Mar 15 at 13:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – ahmadhanb, Jochen Schwarze, BERA, whyzar
What have you tried by so far?
– Taras
Mar 15 at 7:09
2
Possible duplicate one more time: gis.stackexchange.com/questions/131158/…. Please take a few minutes to search the web or GIS Stack Exchange before you ask a question.
– Stefan
Mar 15 at 8:20
Thanks, @Stefan, I do not know why but I have not seen that thread
– Taras
Mar 15 at 8:26
Possible duplicate of How to select features using an expression with pyqgis?
– wetland
Mar 15 at 10:22
2
@wetland Possible duplicate of my comment ;).
– Stefan
Mar 15 at 11:02
add a comment |
What have you tried by so far?
– Taras
Mar 15 at 7:09
2
Possible duplicate one more time: gis.stackexchange.com/questions/131158/…. Please take a few minutes to search the web or GIS Stack Exchange before you ask a question.
– Stefan
Mar 15 at 8:20
Thanks, @Stefan, I do not know why but I have not seen that thread
– Taras
Mar 15 at 8:26
Possible duplicate of How to select features using an expression with pyqgis?
– wetland
Mar 15 at 10:22
2
@wetland Possible duplicate of my comment ;).
– Stefan
Mar 15 at 11:02
What have you tried by so far?
– Taras
Mar 15 at 7:09
What have you tried by so far?
– Taras
Mar 15 at 7:09
2
2
Possible duplicate one more time: gis.stackexchange.com/questions/131158/…. Please take a few minutes to search the web or GIS Stack Exchange before you ask a question.
– Stefan
Mar 15 at 8:20
Possible duplicate one more time: gis.stackexchange.com/questions/131158/…. Please take a few minutes to search the web or GIS Stack Exchange before you ask a question.
– Stefan
Mar 15 at 8:20
Thanks, @Stefan, I do not know why but I have not seen that thread
– Taras
Mar 15 at 8:26
Thanks, @Stefan, I do not know why but I have not seen that thread
– Taras
Mar 15 at 8:26
Possible duplicate of How to select features using an expression with pyqgis?
– wetland
Mar 15 at 10:22
Possible duplicate of How to select features using an expression with pyqgis?
– wetland
Mar 15 at 10:22
2
2
@wetland Possible duplicate of my comment ;).
– Stefan
Mar 15 at 11:02
@wetland Possible duplicate of my comment ;).
– Stefan
Mar 15 at 11:02
add a comment |
1 Answer
1
active
oldest
votes
layer = iface.activeLayer()
layer.selectByExpression('"name"='John's House'', QgsVectorLayer.SetSelection)
selection = layer.selectedFeatures()
print(len(selection))
References:
- PyQGIS developer cookbook | 5.3 Selecting features
- How to select features using an expression with pyqgis?
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
layer = iface.activeLayer()
layer.selectByExpression('"name"='John's House'', QgsVectorLayer.SetSelection)
selection = layer.selectedFeatures()
print(len(selection))
References:
- PyQGIS developer cookbook | 5.3 Selecting features
- How to select features using an expression with pyqgis?
add a comment |
layer = iface.activeLayer()
layer.selectByExpression('"name"='John's House'', QgsVectorLayer.SetSelection)
selection = layer.selectedFeatures()
print(len(selection))
References:
- PyQGIS developer cookbook | 5.3 Selecting features
- How to select features using an expression with pyqgis?
add a comment |
layer = iface.activeLayer()
layer.selectByExpression('"name"='John's House'', QgsVectorLayer.SetSelection)
selection = layer.selectedFeatures()
print(len(selection))
References:
- PyQGIS developer cookbook | 5.3 Selecting features
- How to select features using an expression with pyqgis?
layer = iface.activeLayer()
layer.selectByExpression('"name"='John's House'', QgsVectorLayer.SetSelection)
selection = layer.selectedFeatures()
print(len(selection))
References:
- PyQGIS developer cookbook | 5.3 Selecting features
- How to select features using an expression with pyqgis?
edited Mar 15 at 8:27
answered Mar 15 at 7:12


TarasTaras
2,3003729
2,3003729
add a comment |
add a comment |
What have you tried by so far?
– Taras
Mar 15 at 7:09
2
Possible duplicate one more time: gis.stackexchange.com/questions/131158/…. Please take a few minutes to search the web or GIS Stack Exchange before you ask a question.
– Stefan
Mar 15 at 8:20
Thanks, @Stefan, I do not know why but I have not seen that thread
– Taras
Mar 15 at 8:26
Possible duplicate of How to select features using an expression with pyqgis?
– wetland
Mar 15 at 10:22
2
@wetland Possible duplicate of my comment ;).
– Stefan
Mar 15 at 11:02