Selecting by attribute using Python and a listselecting by attribute and specific value replaceSubquery a list in select layer by attribute management using pythonQGIS create selection scriptUsing SelectLayerByAttribute with list of values in ArcPy?Selecting first items of same attribute value using PyQGIS?Selection by attribute from listSelecting layer by attribute in Python Toolbox of ArcPy?Selecting layers in PyQGISSelecting and updating attribute values using Python console in QGIS?Writing where_clause to Select Layer By Attribute for Python Add-in?

Why do (or did, until very recently) aircraft transponders wait to be interrogated before broadcasting beacon signals?

Parsing text written the millitext font

Can a Warforged suffer from magical exhaustion?

If the pressure inside and outside a balloon balance, then why does air leave when it pops?

How to generate list of *all* available commands and functions?

Why do Bhargava-Skinner-Zhang consider the ordering by height?

Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?

In American Politics, why is the Justice Department under the President?

Who is "He that flies" in Lord of the Rings?

Is Jesus the last Prophet?

Why would a home insurer offer a discount based on credit score?

Placement of positioning lights on A320 winglets

How much web presence should I have?

Create a cube from identical 3D objects

Should I list a completely different profession in my technical resume?

Does it make sense to use a wavelet that is equal to a sine of one period?

How to Convert an Object into Array in magento 2

Course development: can I pay someone to make slides for the course?

Realistic, logical way for men with medieval-era weaponry to compete with much larger and physically stronger foes

Professor Roman loves to teach unorthodox Chemistry

How can you estimate a spike story?

Why is my power MOSFET heating up when on?

What does this line mean in Zelazny's "The Courts of Chaos"?

Are the guests in Westworld forbidden to tell the hosts that they are robots?



Selecting by attribute using Python and a list


selecting by attribute and specific value replaceSubquery a list in select layer by attribute management using pythonQGIS create selection scriptUsing SelectLayerByAttribute with list of values in ArcPy?Selecting first items of same attribute value using PyQGIS?Selection by attribute from listSelecting layer by attribute in Python Toolbox of ArcPy?Selecting layers in PyQGISSelecting and updating attribute values using Python console in QGIS?Writing where_clause to Select Layer By Attribute for Python Add-in?






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








1















I have been using this script to select a feature using Python:



layer = iface.activeLayer()
layer.selectByExpression('"Declividad"= value', QgsVectorLayer.SetSelection)
selection = layer.selectedFeatures()


But now, I need to select the values for Declividad from a list.



For exemple: list = [10,11,12], so I want to select the values 10,11 and 12 for Declividad.



How could I do that?










share|improve this question






























    1















    I have been using this script to select a feature using Python:



    layer = iface.activeLayer()
    layer.selectByExpression('"Declividad"= value', QgsVectorLayer.SetSelection)
    selection = layer.selectedFeatures()


    But now, I need to select the values for Declividad from a list.



    For exemple: list = [10,11,12], so I want to select the values 10,11 and 12 for Declividad.



    How could I do that?










    share|improve this question


























      1












      1








      1








      I have been using this script to select a feature using Python:



      layer = iface.activeLayer()
      layer.selectByExpression('"Declividad"= value', QgsVectorLayer.SetSelection)
      selection = layer.selectedFeatures()


      But now, I need to select the values for Declividad from a list.



      For exemple: list = [10,11,12], so I want to select the values 10,11 and 12 for Declividad.



      How could I do that?










      share|improve this question
















      I have been using this script to select a feature using Python:



      layer = iface.activeLayer()
      layer.selectByExpression('"Declividad"= value', QgsVectorLayer.SetSelection)
      selection = layer.selectedFeatures()


      But now, I need to select the values for Declividad from a list.



      For exemple: list = [10,11,12], so I want to select the values 10,11 and 12 for Declividad.



      How could I do that?







      qgis pyqgis select-by-attribute






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 9 hours ago









      snaileater

      2,153614




      2,153614










      asked 9 hours ago









      caio villacacaio villaca

      446




      446




















          2 Answers
          2






          active

          oldest

          votes


















          3














          You could juse use an expression like:



          layer = iface.activeLayer()
          my_list = [10, 11, 12]
          values = ','.join(str(x) for x in my_list)
          layer.selectByExpression('"Declividad" IN (' + values + ')', QgsVectorLayer.SetSelection)





          share|improve this answer


















          • 1





            Oh! that did the trick :) thanks!

            – caio villaca
            9 hours ago


















          2














          You can try the IN operator :



          layer.selectByExpression('"Declividad" IN ('10','11','12')', QgsVectorLayer.SetSelection)


          Or do u need to dynamically reference the list name ?






          share|improve this answer























          • yep, I need it to read the values from the list...

            – caio villaca
            9 hours ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "79"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f325337%2fselecting-by-attribute-using-python-and-a-list%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          You could juse use an expression like:



          layer = iface.activeLayer()
          my_list = [10, 11, 12]
          values = ','.join(str(x) for x in my_list)
          layer.selectByExpression('"Declividad" IN (' + values + ')', QgsVectorLayer.SetSelection)





          share|improve this answer


















          • 1





            Oh! that did the trick :) thanks!

            – caio villaca
            9 hours ago















          3














          You could juse use an expression like:



          layer = iface.activeLayer()
          my_list = [10, 11, 12]
          values = ','.join(str(x) for x in my_list)
          layer.selectByExpression('"Declividad" IN (' + values + ')', QgsVectorLayer.SetSelection)





          share|improve this answer


















          • 1





            Oh! that did the trick :) thanks!

            – caio villaca
            9 hours ago













          3












          3








          3







          You could juse use an expression like:



          layer = iface.activeLayer()
          my_list = [10, 11, 12]
          values = ','.join(str(x) for x in my_list)
          layer.selectByExpression('"Declividad" IN (' + values + ')', QgsVectorLayer.SetSelection)





          share|improve this answer













          You could juse use an expression like:



          layer = iface.activeLayer()
          my_list = [10, 11, 12]
          values = ','.join(str(x) for x in my_list)
          layer.selectByExpression('"Declividad" IN (' + values + ')', QgsVectorLayer.SetSelection)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 9 hours ago









          JosephJoseph

          59.1k7103208




          59.1k7103208







          • 1





            Oh! that did the trick :) thanks!

            – caio villaca
            9 hours ago












          • 1





            Oh! that did the trick :) thanks!

            – caio villaca
            9 hours ago







          1




          1





          Oh! that did the trick :) thanks!

          – caio villaca
          9 hours ago





          Oh! that did the trick :) thanks!

          – caio villaca
          9 hours ago













          2














          You can try the IN operator :



          layer.selectByExpression('"Declividad" IN ('10','11','12')', QgsVectorLayer.SetSelection)


          Or do u need to dynamically reference the list name ?






          share|improve this answer























          • yep, I need it to read the values from the list...

            – caio villaca
            9 hours ago















          2














          You can try the IN operator :



          layer.selectByExpression('"Declividad" IN ('10','11','12')', QgsVectorLayer.SetSelection)


          Or do u need to dynamically reference the list name ?






          share|improve this answer























          • yep, I need it to read the values from the list...

            – caio villaca
            9 hours ago













          2












          2








          2







          You can try the IN operator :



          layer.selectByExpression('"Declividad" IN ('10','11','12')', QgsVectorLayer.SetSelection)


          Or do u need to dynamically reference the list name ?






          share|improve this answer













          You can try the IN operator :



          layer.selectByExpression('"Declividad" IN ('10','11','12')', QgsVectorLayer.SetSelection)


          Or do u need to dynamically reference the list name ?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 9 hours ago









          snaileatersnaileater

          2,153614




          2,153614












          • yep, I need it to read the values from the list...

            – caio villaca
            9 hours ago

















          • yep, I need it to read the values from the list...

            – caio villaca
            9 hours ago
















          yep, I need it to read the values from the list...

          – caio villaca
          9 hours ago





          yep, I need it to read the values from the list...

          – caio villaca
          9 hours ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f325337%2fselecting-by-attribute-using-python-and-a-list%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480