ValidateFieldName method |
|
Release 9.3
Last modified January 19, 2010 |
![]() ![]() ![]() Print all topics in : "Properties and Methods" |
Note:
This topic was updated for 9.3.1.
Takes a string (field name) and a workspace path and returns a valid field name based on name restrictions in the output geodatabase. All invalid characters in the input string will be replaced with an underscore (_). The field name restrictions depend on the specific database used (Structured Query Language [SQL] or Oracle).
Part | Description |
object | The instantiated geoprocessing object |
inputFieldName | The field name to be validated |
Workspace | Optional. The workspace in which the field can be found |
# Create a new numeric field containing the ratio of polygon area to # polygon perimeter. Two arguments, a feature class and field name, # are expected. import arcgisscripting import os gp = arcgisscripting.create(9.3) # 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 len(gp.ListFields(input,"Shape_area")) > 0 and len(gp.ListFields(input,"Shape_length")) > 0: # 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)