Select to view content in your preferred language

Select by Attributes Using Python List

9637
11
09-08-2011 05:59 AM
BenYoungs
Deactivated User
All,

Is there an efficient way to select multiple features in a feature class using a Python list containing OIDs of the features?

What I have set up right now is the following:

for OID in OIDlist:
     query = 'OID = ' + OID
     gp.SelectByAttribute(layername, "ADD_TO_SELECTION", query)

That works, however it is painfully slow. Is there another approach that I can use (possibly avoiding the GP SelectByAttributes tool?) that would be more efficient?

My desired end result is a layer file that only contains the features with OIDs specified in the list.

Thanks in advance.
Tags (2)
0 Kudos
11 Replies
BenYoungs
Deactivated User
Chris,

You're definitely right on the merits of using local data for geoprocessing. However, I was trying to bypass that if possible because this tool will be running on potentially hundreds of feature classes.

I think this definitely still gives me something to work with, and I will take a look at the work-around you provided and see if that works for me.

Again, thanks to you both for the help.
0 Kudos
LeanneSulewski
Emerging Contributor
Thank you!  You guys solved a python issue I was having!!  Thanks a bunch!  You guys save me a ton of time!
0 Kudos