nevau

Calc fields in python

Discussion created by nevau on Oct 30, 2011
Latest reply on Oct 30, 2011 by nevau
Can someone tell me why these two calcs don't work? the "speed" one completes, but doesn't do anything. The one that calculates distance based on shapelength errors. Not sure if you can script calculate length based on shapelength in version 10.


# Description: Calculates speed and distance
#arcmap 10

 
# Import system modules
import arcpy
from arcpy import env
 
# Get user-supplied input
InputFC = arcpy.GetParameterAsText(0)

try: 
    # Calculate Speed based on time and distance
    arcpy.CalculateField_management(InputFC, "Speed", "[Time] / [Distance]", "VB") 

except:
 errMsg = arcpy.GetMessages(2)
 arcpy.AddError("Unexpected error: cannot calculate Speed" + errMsg)

try: 
    # Calculate Speed based on time and distance
    arcpy.CalculateField_management(InputFC, "Distance", "float(!SHAPE.LENGTH@kilometers)", "PYTHON")

except:
 errMsg = arcpy.GetMessages(2)
 arcpy.AddError("Unexpected error: cannot calculate Distance" + errMsg)

Outcomes