how to calculate areas of polygons using gp.describe

Discussion created by helenak on Jun 24, 2012
Latest reply on Jun 26, 2012 by mdenil
System: ArcGIS 9.3

I am trying to calculate areas of polygons of ten shapefiles, using gp.describe.area.
However, the code is wrong.
Please kindly help and thank you in advance.

##Script Name: Calculate areas
##Description: of polygons of a shapefile
##Created By: Elaine Kuo
##Date: 24/06/2012

#Import standard library modules
import arcgisscripting
import os

#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

#Set the workspace.
gp.Workspace= "H:/temp/test"

#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "H:/temp"

#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()

# Loop through every item in the list that was just generated
for fc in fcs:

    # Break out the name, no path or extension, using the describe object.
    desc = gp.describe(fc)
    featureName = desc.name

    # Add a field to this shapefile, of type LONG
    gp.AddField (fc, "all_r_km", "double", 6,6)   

    #   Get a list of the fields in the featureclass
    fields = gp.ListFields(fc, "C*", "String")
    # Loop through every item in the list that was just generated 
    for field in fields:

        gp.toolbox = "Data Management"

        # Select records to be deleted (C*, i.e. C7658)
        # Make temporary featureclasses
        query = "\"%s\" = 'S'" % field.Name

        # get latitude of north and south limits
        area = gp.describe("outputS.shp").area
        all_r_km = area      
        gp.CalculateField_management("outputS.shp", "all_r_km",str(all_r_km))
    #Validate the new feature class name for the output workspace.
    OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)

    # clear memory of temporary shapefiles

print gp.GetMessages()