ListFields method |
|
|
Release 9.1
Last modified August 19, 2005 |
Print all topics in : "Properties and Methods" |
List all the fields in the specified table, feature class, or shapefile. Specifying search conditions (wildcard) and a field type will limit the results. This method and ListIndexes are the only two List methods that don’t require the user to preset the workspace.
| Part | Description |
| object | The instantiated geoprocessing object |
| pInputValue | The name, and/or path, of the table whose fields are to be listed |
| wild card | Optional. Combination of * and characters that will help limit the results. The asterisk (*) is the same as saying ALL. If no wildcard is specified then all fields will be returned. |
| FieldType | Optional. Keyword FieldType that will limit the returned fields. Valid FieldTypes for this method are:
|
import win32com.client, sys, os
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
# Check the number of arguments.
if len(sys.argv) < 2:
print "Script requires two arguments, feature class and field name"
else:
try:
# Get the input feature class and make sure it contains polygons.
input = sys.argv[1]
dsc = gp.Describe(input)
if dsc.ShapeType != "polygon":
raise "ShapeError"
# Get the new field name and validate it.
fieldname = sys.argv[2]
fieldname = gp.ValidateFieldName(fieldname, os.path.dirname(input))
# Make sure shape_length and shape_area fields exist.
if gp.ListFields(input,"Shape_area").Next() and gp.ListFields(input,"Shape_length").Next():
# Add the new field and calculate the value.
gp.AddField(input, fieldname, "double")
gp.CalculateField(input,fieldname, "[Shape_area] / [Shape_length]")
else:
raise "FieldError"
except "ShapeError":
print "Input does not contain polygons"
except "FieldError":
print "Input does not shape area and length fields"
except:
print gp.GetMessages(2)