Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to add data to an attribute table in ArcGIS 10 using the following code:

def make_floor_no( shapefile ):
    "Makes header for number of Floors (FLO) and calculates value"

    fieldName = "FLO"
    try:
        ARCPY.AddField_management(shapefile, fieldName, "DOUBLE")
    except:
        print "Field already there"  

    # loop through attribute table    
    Rows = ARCPY.SearchCursor( shapefile ) 

    for row in Rows:
        floors = round( row.getValue( 'HGT' ) / 3.0, 0)
        print str(floors)
        row.setValue( fieldName, floors )
        Rows.updateRow(row)            

However, I keep getting an error along the line

row.setValue( fieldName, floors )

I can't spot anything wrong with this, and have tried a few different options. Is there something wrong with my syntax?

The error message is as follows:

 File "Z:\ConstructionMaterial.py", line 100, in <module> make_floor_no( InputFile )
 File "Z:\ConstructionMaterial.py", line 71, in make_floor_no 
    row.setValue( fieldName, floors )
 File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\arcobjects.py", line 941, in setValue
    return convertArcObjectToPythonObject(self._arc_object.SetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.
share|improve this question

1 Answer 1

up vote 8 down vote accepted

Search cursors get you read-only rows objects. if you want to update you need to use the update cursor.

So change this

    Rows = ARCPY.SearchCursor( shapefile ) 

To this

    Rows = ARCPY.UpdateCursor( shapefile ) 
share|improve this answer
    
Thank you - that worked perfectly. –  djq Dec 5 '10 at 22:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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