Hi ,
So I am using a search cursor to run through each row and multi buffer - having a few dramas and I cant seem to get my head around it!
I assume its to do with how I am calling row into the buffer ?
import arcpy from arcpy import env arcpy.env.overwriteOutput = True file_workspace = "r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb" env.workspace = file_workspace Holdings = r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb\Data\Holdings' ofc = r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb' distances = [1000, 4000] unit = "Meters" arcpy.MakeFeatureLayer_management(Holdings,'Holdings_Layer') with arcpy.da.SearchCursor(Holdings, ['Holding_Reference_Number'])as Holdings_Ref_cursor: for x in Holdings_Ref_cursor: print x[0] Poyl_name = row[0] arcpy.SelectLayerByAttribute_management('Holdings_Layer', 'NEW_SELECTION', '"' + Holdings + '" = \'' + Poyl_name + '\'') arcpy.MultipleRingBuffer_analysis('Holdings_Layer', 'ofc', distances, unit, "", "ALL") #arcpy.Buffer_analysis("Holdings_Layer", ofc, var_Buffer, "FULL", "ROUND", "ALL", "") print 'Buffer complete' print('Buffer Complete')
Solved! Go to Solution.
That's because you've called 'x' what most examples call 'row' (it would normally be more like "for row in cursor:"). It doesn't matter, it's just a variable name, but if you call it 'x', then you need to reference 'x' (i.e. x[0] is the Holding_Reference_Number). Or, you can't set x[0] to row[0], because row doesn't exist. Also, you've got a new error coming up in the select - there's an extra apostrophe right after x[0].
What's the error message?
As it is now, it looks like the line Poyl_name = row[0] is commented out (although I don't see the '#'), so there is no variable called Poyl_name. If it's not commented out, then it's trying to use row[0], while you've already called it x[0].
Sorry I forgot to add the error.
So I have made some changes but still getting that the row is not defined ..
import arcpy from arcpy import env arcpy.env.overwriteOutput = True file_workspace = "r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb" env.workspace = file_workspace Holdings = r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb\Data\Holdings' ofc = r'N:\GIS\Projects\AA_Leith_Hawkins_TestBed\Search_Cursor\Search_Cursor.gdb' distances = [1000, 4000] unit = "Meters" arcpy.MakeFeatureLayer_management(Holdings,'Holdings_Layer') with arcpy.da.SearchCursor(Holdings, ['Holding_Reference_Number'])as Holdings_Ref_cursor: for x in Holdings_Ref_cursor: print x[0] x[0] = row[0] arcpy.SelectLayerByAttribute_management('Holdings_Layer', 'NEW_SELECTION', '"' + Holdings + '" = \' + x[0]' + '\'') arcpy.MultipleRingBuffer_analysis('Holdings_Layer', 'ofc', distances, unit, "", "ALL") #arcpy.Buffer_analysis("Holdings_Layer", ofc, var_Buffer, "FULL", "ROUND", "ALL", "") print 'Buffer complete' print('Buffer Complete')
That's because you've called 'x' what most examples call 'row' (it would normally be more like "for row in cursor:"). It doesn't matter, it's just a variable name, but if you call it 'x', then you need to reference 'x' (i.e. x[0] is the Holding_Reference_Number). Or, you can't set x[0] to row[0], because row doesn't exist. Also, you've got a new error coming up in the select - there's an extra apostrophe right after x[0].
Thanks makes sense ill implement