I'm trying to use the updateCursor to insert a calculated value in the correct field. However, I keep on receiving an execution error. I think it is an easy fix, but I am new to arcpy and cannot figure out where I'm making a mistake.
Here's the code:
cursor = arcpy.UpdateCursor(outAgri)
for row in cursor:
arcpy.AddMessage("Field " + str(count) + " of " + str(loop))
agriFeat = arcpy.SelectLayerByAttribute_management(agri_lyr, "NEW_SELECTION", '"OBJECTID_1" = ' + "%s" %count)
count += 1
marginbound = arcpy.SelectLayerByLocation_management (margin_lyr, "BOUNDARY_TOUCHES", agriFeat, "", "NEW_SELECTION")
mCursor = arcpy.SearchCursor(marginbound, fields= "Margin_Type; Health_Index; Shape_Area")
##mFields = arcpy.ListFields(marginbound)
mcount = 0
gArea = 0
pArea = 0
rArea = 0
gHealth = 0
pHealth = 0
rHealth = 0
for row in mCursor:
if row.getValue("Margin_Type") == "G":
arcpy.AddMessage("Grass")
gAreaTest = row.getValue("Shape_Area")
gArea = (row.getValue("Shape_Area") + gArea)
gHealth = row.getValue("Health_Index")
if row.getValue("Margin_Type") == "P":
arcpy.AddMessage("Planted Hedges")
rArea = (row.getValue("Shape_Area") + rArea)
rHealth = row.getValue("Health_Index")
if row.getValue("Margin_Type") == "R":
arcpy.AddMessage("Remnant Hedges")
pArea = (row.getValue("Shape_Area") + pArea)
pHealth = row.getValue("Health_Index")
mcount += 1
tArea = (pArea + gArea + rArea)
fieldHealth = (((rArea/tArea) * rHealth) + ((gArea/tArea) * gHealth) + ((pArea/tArea) * pHealth))
arcpy.AddMessage("The Field health is " + str(fieldHealth))
row.setValue("Field_Health", fieldHealth)
cursor.updateRow(row)