# Calculate Percentage Area based on Risk

Question asked by dellis78 on May 21, 2012
Latest reply on May 22, 2012 by dellis78
Hi,

I'm trying to calculate the percentage of area (EXTENT_HA) based on RISK.
So far I have this code which doesn't seem to work for me. Its failing within the SearchCursor.
I'd be really grateful for any assistance or ideas.

Regards

Deidre

import arcpy

#Below is the name of the Table layer in ArcMap.
InputTable = "C:\\NCRAT\\data\\tmp\\EEC_Stats.dbf"

#This searchCursor reads the total area of all features.
TotalArea = 0.0
TableCursor = arcpy.SearchCursor(InputTable)
for TableRow in TableCursor:
TotalArea += TableRow.getValue("EXTENT_HA")
del TableRow
del TableCursor

#This updateCursor inputs the % values for each feature
TableCursor = arcpy.updateCursor(InputTable)
for TableRow in TableCursor:
CurrentArea = TableRow.getValue("EXTENT_HA")
TableRow.setValue("PERCENT",CurrentArea/TotalArea*100.0)
TableCursor.updateRow(TableRow)
del TableRow
del TableCursor

if __name__ == '__main__':
inputTable = arcpy.GetParameterAsText(0)
if len(inputTable) == 0:
inputTable =  "C:\\NCRAT\\data\\tmp\\EEC_Stats.dbf"

arcpy.AddMessage('Starting operation on: %s' % InputTable)

arcpy.AddMessage('Completed operation on: %s' % InputTable)