arcpy.da.UpdateCursor using geometry

1790
1
04-12-2013 03:39 PM
BrittaSchroeder
New Contributor II
I am having a difficult time understanding geometry as a concept accessed by the da module.

For example, I created a new feature class using the clip geoprocessing tool. I want to update the "HECTARES" field, as well as add a "Shape_Area" field that is updated with Shape@Area geometry.

arcpy.Clip_analysis(fireLayer,refugeLayer,outLayer)
arcpy.AddField_management(outLayer,"Shape_Area", "DOUBLE")
updateRows = arcpy.da.UpdateCursor\
             (outLayer,["HECTARES","Shape@Area"])

for row in updateRows: #fields --> 0:Hectares, 1:ShapeArea
    HA = row[1]/10000 #Area in hectares
    row[0] = HA #assign value to each row of Hectares
    row[1] = ["Shape@Area"]
    updateRows.updateRow(row) #save it by using the updateRow function
del updateRows # unlock cursor
del row #remove cursor pointer 


This code will update my "HECTARES" field if I comment out the line
    row[1] = ["Shape@Area"]

which leads me to believe that while row[1] remains empty, it still has access to the Shape@Area geometry.

Thanks.
Tags (2)
0 Kudos
1 Reply
T__WayneWhitley
Frequent Contributor
In your field list, included are the field names you want to update- you have shape@area which is actually the value, not the field name, Shape_Area.  That's another thing too- if you have an fc, don't you already have an area field that is auto-updated?  Guess if you're just testing out techniques, that's fine, but probably should additionally check that you are not adding invalid fields, or attempting to add one that already exists.

Enjoy,
Wayne
0 Kudos