AnsweredAssumed Answered

arcpy.SelectLayerByAttributes Where Clause

Question asked by jborgion Champion on Nov 15, 2017
Latest reply on Nov 16, 2017 by jborgion

In post earlier today, (Another da.SearchCursor Issue ) through an oversight on my part I couldn't execute a select layer by attributes function. Silly me....  At rate, I've moved past that issue but now faced with constructing a where clause that involves membership in a dictionary.


Essentially, I've constructed a dictionary of street types that looks something like this:

typeDict = {"AVE":1,"BLVD":2,"CIR":3}  #etc, etc

 As best as I can tell, the way to  see if a given string is a member of a dictionary, one can :

>>> typeDict
{'BLVD': 2, 'AVE': 1, 'CIR': 3}
>>> "AVE" in typeDict
>>> "ST" in typeDict
>>> "ST" not in typeDict
>>> if "somevalue" not in typeDict:
...     print "nope"

Okay, easy enough. The problem is constructing a valid "where clause' for the SelectLayerByAttribute() when considering membership in a dictionary.  I've tried dozens of {}.format() approaches but the red font on my screen looks something like the U.S. spend deficit.  I need some advice to successfully select a record or records based on the dictionary:


intable = "C:\Path\To\File.gdb\Table
typeDict = {"AVE":1,"BLVD":2,"CIR":3}  #etc, etc

fields = ["Type","StreetName"]
where = "StreetName >= 'A'    #just concerned with named streets, no numbers

with arcpy.da.SearchCursor("view",fields,where) as cursor:
    for row in cursor:
       Select = #need to format a where clause that
                # evalutes row[0] not in typeDict


James Crandall

Joshua Bixby

Dan Patterson


(I should just create a signature block with you guys in it; maybe I can convince my boss to put you on retainer....)