##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, "allarea_km", "double", 12,0) # 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" # get area expression = "float('!shape.area@squarekilometers!')" gp.CalculateField_management(fc, "allarea_km", expression, "PYTHON") #Validate the new feature class name for the output workspace. OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace) gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.