I have a script which reclassifies a tif file, adds a new field to the tiff, and is supposed to parse the date from the filename and add it to the new date field. Everything works as it should, except parsing the date. When the script runs this line, python crashes, either runnig the script through ArcCatalog or python command line:
arcpy.ConvertTimeField_management("C:\Users\OuelletteMS\Desktop\Ice_Data_from_JohnIacozza\1978\wa_19780629_reclass.tif", 19780629, "yyyyMMdd", "Date")
This example is using variable values as they are assigned by the script (print the variables, copy/paste and add quotes). The full script is below.
I get no error messages, and commenting out this one line shows that everything else works. I got this line as a snippet after a successful run of the tool in ArcMap. What am I missing?
I'm using ArcGIS 10.1 SP1 and Python 2.7
import arcpy, os, sys
from arcpy import env
arcpy.CheckOutExtension("Spatial")
# Allow for file overwrite
arcpy.env.overwriteOutput = True
# Set the workspace directory
path = "C:\Users\OuelletteMS\Desktop\Ice_Data_from_JohnIacozza"
env.workspace = path
# Get the list of the featureclasses in the workspace directory
listFCs = arcpy.ListFiles("wa_197806*.tif")
# Loop through each file and perform the processing
for fc in listFCs:
print str("processing " + fc) # displays the file that is currently being handled
shpname = str(fc) # converts filename to a string
yearVal = shpname[3:7] # year processed
newName = shpname[0:11] + "_reclass.tif" # name for reclassified raster
newPath = path + "\\" + yearVal # sets the path for the reclassified file
outfile = newPath + "\\" + newName # specifies reclassified raster path
vf = "Value" # sets value field to be used
strDate = shpname[3:11] # extracts characters 3 through 11 from the file name
# Check to see if a directory for that year exists. If not, make one
try:
os.makedirs(newPath)
except OSError:
if not os.path.isdir(newPath):
raise
# Reclassify raster
arcpy.gp.Reclassify_sa(fc,vf,"1 5 1;6 99 0;NODATA 0",outfile,"NODATA")
# Adds and populates date field
field2 = "Date" # Field for storing the date as a date
arcpy.AddField_management(outfile,field2,"DATE")
# arcpy.ConvertTimeField_management(outfile, strDate, "yyyyMMdd", field2)
# Cleanup
del listFCs, fc, shpname, yearVal, newName, newPath, outfile, vf, strDate, field2
#
arcpy.CheckInExtension("Spatial")
print "done"