1

I'm trying to create an individual buffer feature class for each column of an input feature class, where there is a field that contains the buffer distance.

I think there is a problem with my SQL statement because in the inner loop to access the field with the buffer length I get this error:

for buf in loop2:

RuntimeError: A column was specified that does not exist.

Any suggestions? Note I also tried: query = ' "UNIQUEID" = ' + str(id[0])

Here is my code:

###loop through field value of nest number, AKA "UNIQUEID"

fc1 = BEN_input
field1 = "UNIQUEID"

with arcpy.da.SearchCursor(fc1, (field1)) as loop1:

    for id in loop1:

        #extract out individual nest
        query = "UNIQUEID" + "="  + str(id[0])

        arcpy.MakeFeatureLayer_management(BEN_input, "BEN", query)

        ##clip water to buffer size

        #access buffer size
        fc2 = "BEN"
        field2 = "best_buf"

        with arcpy.da.SearchCursor(fc2, (field2)) as loop2:
            for buf in loop2:
                water_buf_size = buf

        #buffer nest
        arcpy.Buffer_analysis(BEN, "BEN_buf", water_buf_size)
3

I always encourage to use field delimiters to access the fields in a right way:

field_name = "UNIQUEID"
input_value = 5
sql_exp = """{0} = {1}""".format(arcpy.AddFieldDelimiters('c:/data/file_gdb.gdb', field_name),input_value)
print sql_exp

>>> 'UNIQUEID=5'

Another way to do this is to use the str.format():

sql_exp = """{0} = {1}""".format(field_name,input_value)
>>> 'UNIQUEID = 5'
0

Your variable water_buf_size is outside the scope of the Buffer_analysis. You need create the variable outside the SearchCursor, then assign the variable within the SearchCursor so it can then be accessed for the Buffer_analysis....also I would add a where clause to the search cursor where water_buf_size is not null so you only get the features that have a value.

  • Not only is water_buf_size outside scope, it's set zero, one, or more times to a row, without actually ever being used. – Vince Jun 3 '15 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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