Anyone tell me why this code is returning this error? It creates the latTemp field, and I can see it after it crashes, but it will not calculate it.
ERROR:
CODE:
ERROR:
Code:
<class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid.
ERROR 000728: Field latSTR does not exist within table
Failed to execute (CalculateField).
Failed to execute (ConvertDMS2DD).
Failed at Mon Feb 25 11:25:18 2013 (Elapsed Time: 9.00 seconds)Code:
import arcpy, sys, os
arcpy.env.overwriteOutput = 1
# select the feature class
fc = arcpy.GetParameter(0)
# select the latitude field to convert
latField2 = arcpy.GetParameter(1)
latField = "%s%s%s" % ('!', latField2, '!')
arcpy.AddMessage("latField2 = " + str(latField2) +" latField = " +latField)
lonField2 = arcpy.GetParameter(2)
lonField = "%s%s%s" % ('!', lonField2, '!')
arcpy.AddMessage("lonField2 = " + str(lonField2) +" lonField = " +lonField)
# set lattitude output field
latFieldDD = "latDD"
# set longitude output field
lonFieldDD = "lonDD"
# set temp lattitude field, used to store lat field as string used in function
latTemp = "latSTR"
# set temp longitude field, used to store lon field as string used in function
lonTemp = "lonSTR"
latExp = "lat(%s%s%s)" % ('!',latTemp,'!')
codeblockLAT = """def lat(dms):
latdeg = float(dms[0:2])
latmin = float(dms[2:4])
latsec = float(dms[4:6])
latdd = latdeg + (latmin / 60) + (latsec / 3600)
return latdd"""
lonExp = "lon(%s%s%s)" % ('!',lonTemp,'!')
codeblockLON = """def lon(dms):
londeg = float(dms[0:3])
lonmin = float(dms[3:5])
lonsec = float(dms[5:7])
londd = (londeg + (lonmin / 60) + (lonsec / 3600)) * -1
return londd"""
#copy the lat numeric to a string
arcpy.AddField_management(fc, latTemp, "TEXT", "", "", 16)
arcpy.AddField_management(fc, latFieldDD, "FLOAT", 16, 6, 16)
arcpy.AddMessage("added lat fields: %s and %s" % (latTemp, latFieldDD))
#copy the lon numeric to a string
arcpy.AddField_management(fc, lonTemp, "TEXT", "", "", 16)
arcpy.AddField_management(fc, lonFieldDD, "FLOAT", 16, 6, 16)
arcpy.AddMessage("added lon fields: %s and %s" % (lonTemp, lonFieldDD))
# do calculations
arcpy.CalculateField_management(fc, latTemp, latField, "PYTHON")
arcpy.CalculateField_management(fc, latFieldDD, latExp, "PYTHON", codeblockLAT)
arcpy.DeleteField_management(fc, latTemp)
arcpy.CalculateField_management(fc, lonTemp, lonField, "PYTHON")
arcpy.CalculateField_management(fc, lonFieldDD, lonExp, "PYTHON", codeblockLON)
arcpy.DeleteField_management(fc, lonTemp)