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!])
asked Jun 30, 2021 at 14:54

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.

answered Jun 30, 2021 at 15:18
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

answered Jul 1, 2021 at 1:18
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.