[GIS] Iterate through features of a feature class and buffer them

arcgis-10.2arcpyerror-000358sqlwindows 7

I'm currently trying to iterate through the features of a feature class (using an update cursor, because the goal is to ultimately update the field) and buffer each individual segment. I eventually want to use the buffer in each iteration with different tools, but I can't get the initial Select by Attribute to work. Here's my code:

fc = "Original_Clip"
fcfield = "SEGMENTID"

strt_lyr = arcpy.MakeFeatureLayer_management(fc, "Street_lyr")
with arcpy.da.UpdateCursor(fc, fcfield) as cursor:
     for row in cursor:
        var_segment = row[0]
        print "Buffering segment " + str(var_segment)
        arcpy.SelectLayerByAttribute_management(strt_lyr, "NEW_SELECTION", '{} = \'{}\''.format(var_segment))
        arcpy.Buffer_analysis(strt_lyr, str(var_segment) + "Buff", "20 Feet") 

When I run this code, an error is thrown with the SelectLayerByAttributefunction, saying my where clause is invalid?

Runtime error Traceback (most recent call last): File "", line 15, in File "d:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6688, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).
I'm assuming I just have the SQL syntax wrong (I'm querying a file geodatabase btw), but maybe what I'm trying to do just isn't possible.

Best Answer

I've had problems like this with where clauses in SelectLayerByAttribute when I try to build the clause right in the function parameter list. I work around it by building the where clause in a string variable and using the variable in the function parameters instead.

Related Question