Getting particular feature using expression in PyQGIS? [closed]

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















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.










share|improve this question















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
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • 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

















1















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.










share|improve this question















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
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • 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













1












1








1








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
If this question can be reworded to fit the rules in the help center, please edit the question.







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
If this question can be reworded to fit the rules in the help center, please edit the question.












  • 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






  • 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










1 Answer
1






active

oldest

votes


















3














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?





share|improve this answer































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    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?





    share|improve this answer





























      3














      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?





      share|improve this answer



























        3












        3








        3







        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?





        share|improve this answer















        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?






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 15 at 8:27

























        answered Mar 15 at 7:12









        TarasTaras

        2,3003729




        2,3003729












            WC,C,QYWs3gw74fagfxTbJmTyt
            pFsms pMbNWU1nql4gBYEzGYjULRfSfOtoG qBB keHQwLMY58Mq 5x2gF,vkgERQBpRkUB UwtHzB4IpNU5ncX NMH4,Znu2k8R5jY

            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            How many registers does an x86_64 CPU actually have?

            Displaying single band from multi-band raster using QGIS