I am still really new to Python and ArcPy. We have a pair of feature classes, one with an index grid and the other with project locations. We are trying to create a table that shows what index grid cells each project intersects.
I have a script that performs Intersect on the two feature classes, creates a new table (indexTable) , adds the two needed fields: Label (the project number) and PageName (the index grid), and populates Label using an InsertCursor. I know that I eventually need to use an UpdateCursor with an update string to update PageName, but I am at a loss on how to properly do it, since some of the projects intersect more than one grid cell.
Currently, I have a SearchCursor to get the data from the Intersect feature class, but it breaks with "SystemError: error return without exception set".
# UpdateCursor to add all index grid cells for each label
gridList = [r for r in arcpy.da.SearchCursor(intersectOut, ("Label", "PageName"))] # List from intersection
arcpy.AddMessage("Grid list = {}".format(gridList)) # For debugging
with arcpy.da.UpdateCursor(indexTable, ("Label", "PageName")) as uCursor:
for row in uCursor:
name_field = "Label"
expression = u'{} = {}'.format(arcpy.AddFieldDelimiters(intersectOut, name_field), row[0])
# expression = "Label = '" + row[0] + "'"
with arcpy.da.SearchCursor(intersectOut, ("Label", "PageName"), where_clause=expression) as sCursor:
gridString = ""
if gridString == "":
gridString = gridString + sCursor[1]
else:
gridString = gridString + ", " + sCursor[1]
arcpy.AddMessage(gridString)
# Before going to the next record in the site index table write this list to the appropriate field.
row[1] = gridString
uCursor.updateRow(row)
I also tried using list comprehension to go through gridList, based on row[0] of the UpdateCursor, but that just returns a series of empty lists--and I was unsure where to go from there in any case.
# UpdateCursor to add all index grid cells for each label
gridList = [r for r in arcpy.da.SearchCursor(intersectOut, ("Label", "PageName"))] # List from intersection
arcpy.AddMessage("Grid list = {}".format(gridList)) # For debugging
with arcpy.da.UpdateCursor(indexTable, ("Label", "PageName")) as uCursor:
for row in uCursor:
search = row[0]
arcpy.AddMessage(search)
filterList = [r for r in gridList if gridList[0] == search]
I know there has to be a way to do this, but I am at a loss.