Error 999999 with Update Cursor - somebody please help!

1470
7
11-10-2011 08:14 AM
AmyMeehan
New Contributor
Could somebody please tell me what is going wrong with this program?  I keep getting an ERROR 999999 for the line with the cursor.  But I've checked my syntax, spelling, capitalization, etc. and I can't figure out why it won't work!! 

I am trying to loop through a list of feature classes, intersect each of them with a buffer polygon, and then join the tables for the resulting intersect layer with the buffer polygon table.  Then I need to set the "PERCENTAGE" field in each one to the bufferarea/habitat area * 100.  Since it is looping through the list of feature classes, I have to use variable names for the fields.  Is this what is clogging it up?

I have been struggling with this for a week!!!!

Hopefully this will keep the indentation, but here is the part of the program that is choking on the update cursor:


IntersectLyr = arcpy.MakeFeatureLayer_management(BufferPoly, "buffpolylyr")

fcList = arcpy.ListFeatureClasses("selfts_*", "Polygon")
for fc in fcList:
    desc = arcpy.Describe(fc)
    outFC = desc.baseName.strip("selfts_") + "_Intersect"
    in_features = [IntersectLyr, fc]
    #Perform Intersect between bufferpoly and selected features in each habitat feature class
    arcpy.Intersect_analysis(in_features, outFC)
    arcpy.AddField_management(outFC, "PERCENTAGE", "Double")
    des = arcpy.Describe(outFC)
    outFClyr = des.baseName + "lyr"
    arcpy.MakeFeatureLayer_management(outFC, outFClyr)
    arcpy.AddMessage("The Intersect Layer is: " + str(outFClyr))
    arcpy.AddJoin_management(outFClyr, "FID_ProjectRadius", IntersectLyr, "OBJECTID")
    fldList = arcpy.ListFields(outFClyr, "*.PERCENTAGE")
    for fld in fldList:
        percentfld = fld.name
        arcpy.AddMessage(fld.name)
    fldList2 = arcpy.ListFields(outFClyr, "*.Shape_Area")
    for fld in fldList2:
        if fld.name == "ProjectRadius.Shape_Area":
            arcpy.AddMessage(fld.name)
            buffareafld = fld.name
        else:
            arcpy.AddMessage(fld.name)
            areafld = fld.name
    cur = arcpy.UpdateCursor(Intersect)
    for row in cur:
        buffarea = row.getValue(buffareafld)
        habarea = row.getValue(areafld)
        row.percentfld = (buffarea/habarea)*100
        cur.updateRow(row)

del cur, row

A multitude of thanks in advance to anyone who can help!!

Amy Meehan
Maine Dept. Inland Fisheries and Wildlife
Tags (2)
0 Kudos
7 Replies
AmyMeehan
New Contributor
Ooops!  Error in the program I just posted (but not the one I am trying to solve).  Here is the correct program:

IntersectLyr = arcpy.MakeFeatureLayer_management(BufferPoly, "buffpolylyr")

fcList = arcpy.ListFeatureClasses("selfts_*", "Polygon")
for fc in fcList:
    desc = arcpy.Describe(fc)
    outFC = desc.baseName.strip("selfts_") + "_Intersect"
    in_features = [IntersectLyr, fc]
    #Perform Intersect between bufferpoly and selected features in each habitat feature class
    arcpy.Intersect_analysis(in_features, outFC)
    arcpy.AddField_management(outFC, "PERCENTAGE", "Double")
    des = arcpy.Describe(outFC)
    outFClyr = des.baseName + "lyr"
    arcpy.MakeFeatureLayer_management(outFC, outFClyr)
    arcpy.AddMessage("The Intersect Layer is: " + str(outFClyr))
    arcpy.AddJoin_management(outFClyr, "FID_ProjectRadius", IntersectLyr, "OBJECTID")
    fldList = arcpy.ListFields(outFClyr, "*.PERCENTAGE")
    for fld in fldList:
        percentfld = fld.name
        arcpy.AddMessage(fld.name)
    fldList2 = arcpy.ListFields(outFClyr, "*.Shape_Area")
    for fld in fldList2:
        if fld.name == "ProjectRadius.Shape_Area":
            arcpy.AddMessage(fld.name)
            buffareafld = fld.name
        else:
            arcpy.AddMessage(fld.name)
            areafld = fld.name
    cur = arcpy.UpdateCursor(outFClyr)
    for row in cur:
        buffarea = row.getValue(buffareafld)
        habarea = row.getValue(areafld)
        row.percentfld = (buffarea/habarea)*100
        cur.updateRow(row)

del cur, row
0 Kudos
AndrewChapkowski
Esri Regular Contributor
Can you repost your code inside the code tag for the formatting stays with it?

The icon looks like a # symbol.

Thanks
0 Kudos
AmyMeehan
New Contributor
IntersectLyr = arcpy.MakeFeatureLayer_management(BufferPoly, "buffpolylyr")

fcList = arcpy.ListFeatureClasses("selfts_*", "Polygon")
for fc in fcList:
    desc = arcpy.Describe(fc)
    outFC = desc.baseName.strip("selfts_") + "_Intersect"
    in_features = [IntersectLyr, fc]
    #Perform Intersect between bufferpoly and selected features in each habitat feature class
    arcpy.Intersect_analysis(in_features, outFC)
    arcpy.AddField_management(outFC, "PERCENTAGE", "Double")
    des = arcpy.Describe(outFC)
    outFClyr = des.baseName + "lyr"
    arcpy.MakeFeatureLayer_management(outFC, outFClyr)
    arcpy.AddMessage("The Intersect Layer is: " + str(outFClyr))
    arcpy.AddJoin_management(outFClyr, "FID_ProjectRadius", IntersectLyr, "OBJECTID")
    fldList = arcpy.ListFields(outFClyr, "*.PERCENTAGE")
    for fld in fldList:
        percentfld = fld.name
        arcpy.AddMessage(fld.name)
    fldList2 = arcpy.ListFields(outFClyr, "*.Shape_Area")
    for fld in fldList2:
        if fld.name == "ProjectRadius.Shape_Area":
            arcpy.AddMessage(fld.name)
            buffareafld = fld.name
        else:
            arcpy.AddMessage(fld.name)
            areafld = fld.name
    cur = arcpy.UpdateCursor(outFClyr)
    for row in cur:
        buffarea = row.getValue(buffareafld)
        habarea = row.getValue(areafld)
        row.percentfld = (buffarea/habarea)*100
        cur.updateRow(row)

del cur, row
0 Kudos
AndrewChapkowski
Esri Regular Contributor
Some suggestions:
- You should move your del statement inside your feature class list loop. 
- Make sure your environmental workspace is set: arcpy.env.workspace = r"path"
- use setValue() on your update cursor
- when you join a table, the field names change
- Try making the join permanent and using the update cursor (use copy features) on the newly created feature class.  I would also set arcpy.env.overwriteOuput = True.

Hope this helps.
0 Kudos
AmyMeehan
New Contributor
Thank you.  That was a portion of a much larger program.  The entire program works pretty well up until the update cursor.  I will try your suggestions (some of which I have already done in the program).

Thanks for your help!

Amy
0 Kudos
AmyMeehan
New Contributor
when you join a table, the field names change
- Try making the join permanent and using the update cursor (use copy features) on the newly created feature class.

When I do this, I lose the two different Shape_Area fields.  I need the Shape_Area field from the buffer layer and the Shape_Area field from the habitat layer to do the calculation in the update cursor. 

Amy
0 Kudos
Miguel_AngelSierra
New Contributor
Hi all, someone could help me solve this error:

>>> s = gp.insertcursor("C:\Student\Proyecto_Grado\Scratch\Output.mdb\TablaSalida")
>>> h = s.newrow()
>>> outCountField
'Count'
>>> listCount
2
>>> h.setvalue(outCountField,listCount)
Runtime error <type 'exceptions.RuntimeError'>: ERROR 999999: Error executing function.

I would greatly appreciate
0 Kudos