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 am very new to programming (I started learning this semester) and would very much appreciate helop with one piece of a project. I have the following table, and I need to write a script compatible with Arc10 that will extract some statistics from it. Specifically, I need to obtain a total of all the areas, and then a percentage describing how much of the total area each class of land takes up. If someone knows of a tool or command I should use, that would be a lot of help, even without a script. Thank you in advance to anyone who wants to help an extremely raw beginner.

Id_1    LandClass   F_AREA

    0   Mixed Forest    15612315.78
    0   Softwood Forest 2161121.455
    0   Wetland         2255656.822
    0   Grassy          27009516.24
    0   Hardwood Forest 10345393.4
share|improve this question
I'm writing a python script for a class project, so I have to do everything using Python, especially since I'm creating a tool that will be (hopefully) useable by students who aren't familiar with Arc GIS at all. Thank you for your help, I'm finally making some progress again. –  user6572 Mar 27 '12 at 14:29

1 Answer 1

I'm going to assume that this table is within ArcMap because you calculated the area of each feature in the third column. To extract values from a table that resides in a current ArcMap document, you need to use cursors. These ArcPython objects loop through each row in a table and allow you read and/or write to that table. If you are only reading information, the loop will be much faster if you use a SearchCursor; if you want to edit table values, you'll have to use an UpdateCursor.

There are a lot of different ways to go with cursors, but the simplest thing to sum the total area of all features, store it in a variable, then run the division for each feature and store the % of the total in a new field called "Percent_Area" or something like that. I'm assuming you know basic Python.

import arcpy

#Below is the name of the table layer in ArcMap.
InputTable = "My Table"

#This searchCursor reads the total area of all features.
TotalArea = 0.0
TableCursor = arcpy.SearchCursor(InputTable)
for TableRow in TableCursor:
    TotalArea += TableRow.getValue("F_AREA")
del TableRow
del TableCursor
#At this point 'TotalArea' variable is the sum of all feature areas

#This updateCursor saves the % values for each feature
TableCursor = arcpy.UpdateCursor(InputTable)
for TableRow in TableCursor:
    CurrentArea = TableRow.getValue("F_AREA")
        # area for this feature
        # relative area percentage for this feature
del TableRow
del TableCursor

For such a small table and such a simple operation it would probably be easiest to just run Summary Statistics to get the total area and then do Field Calculator on a new field to calculate the percentage, but I'm assuming you are using Python for a reason.

share|improve this answer
Nice clear example. I added some code comments to help the python beginner this Q is aimed at. For better portability use arcpy.Describe() to retrieve the name of the Area field, example at Determining Shape Area Field Name –  matt wilkie Jul 28 at 17:43

Your Answer


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.