0

I want find (and possibly select) all features from a multi-polygon that contain the names 'Angelica' and 'Anthoxanthum' in the attribute table. In this case it would be feature 1 and 6.

Is there a way to do it with a SQL query or some other tool?

I tried the 'Find tool' and the 'Select by Attribute' tool but my attribute table contains hundreds of columns.

enter image description here

The goal is to find (and select) every feature in which the two names 'Angelica' and Anthoxanthum' occur.

Update: As suggested by @ycartwhelen and @FelixIP

    import arcpy
        
    fc = 'D:/data/myshpefile'
    fields = ['_Art_1', '_Art_2', '_Art_3']
            
    set2test = set(['Pfeifengras','Herzblatt']) 
    def queryMany(listOfSents):   bigSet = set()   

for s in listOfSents:  
   bigSet.update(set(s.split(" ")))   
   return not len(set2test.difference(bigSet))  
    
    queryMany([ !_Art_1!,    !_Art_2!,  !_Art_3!,   (.....)     !_Art_82!])

2 Answers 2

2

You could write a python script which uses a loop and search cursor to iterate through all your features. The search cursor could return all the attributes for a given feature as a list, and then you could use an if statement to check if your string is in the list (if "angelica" in attr_list: do something).

Where the if statement evaluates true you have a couple options. One would be to use an insert cursor to build a new feature layer of the "selected" features. Another would be to store the object IDs in a list, and then after the loop is complete do a Select by Attribute based where object ID is in that list of IDs.

0
1

You can use function below in your script as you iterate through records. It returns True if both words found:

set2test = set(['rabbit','puppy'])

def queryMany(listOfSents):
  bigSet = set()
  for s in listOfSents:  bigSet.update(set(s.split(" ")))
  return not len(set2test.difference(bigSet))

#----------------

queryMany([ !A!, !B!, !C!])

enter image description here

Function creates a set of words from multiple fields and checks if both of interest are present.

Don't forget to include OID@ field in your cursor. This way you can append initially empty list and apply layer.setSelectionSet method to trigger selection.

CREDITS

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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