While trying to run the ArcGIS provided python script to interpolate a bunch of rasters on a time-enabled point feature class file I get the following error:
Runtime error Traceback (most recent call last): File "", line 34, in File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6043, in MakeFeatureLayer raise e ExecuteError: ERROR 000840: The value is not a Feature Layer.
My code is this (line 34 is talking about making a feature class, and I cannot for the life of me figure out what it's referring to):
import arcpy, datetime # Check out the ArcGIS Spatial Analyst extension for using the IDW interpolation tool arcpy.CheckOutExtension("spatial") arcpy.env.workspace = "C:\Users\Chris\Desktop\interpolation\Interpolation.gdb" # Get the layer time properties lyr = arcpy.mapping.Layer(r"C:\Users\Chris\Desktop\interpolation\points.lyr") lyrTime = lyr.time # Calculate the number of iterations based on the time extent and timestep interval startTime = lyrTime.startTime endTime = lyrTime.endTime timeExtent = endTime - startTime timeStepInterval = lyrTime.timeStepInterval iterations = timeExtent.days / timeStepInterval.interval # Get the time field containing the time values associated # with the data in the time-enabled layer startTimeField = str(lyrTime.startTimeField) # Specify the output mosaic dataset to which the interpolated rasters will be added outputMosaicDataset = r"C:\Users\Chris\Desktop\interpolation\Interpolation.gdb\rasta" i = 0 while i <= iterations: # Formulate the time query and increment the time by the timeStepInterval currentTime = str(startTime + (i*timeStepInterval)) timeQuery = "\"" + startTimeField + "\"" + " = date '" + currentTime + "'" # Create an in-memory feature layer containing points that are valid at each timestep tempFeatureLyr = "tempTimeLayer" + str(i) arcpy.MakeFeatureLayer_management(lyr, tempFeatureLyr, timeQuery) # Create an interpolated raster surface using the points valid at each timestep outRaster = r"C:\Users\Chris\Desktop\interpolation\Interpolation.gdb\output" + str(i) print outRaster arcpy.gp.Idw_sa(tempFeatureLyr, "avg_hrly", outRaster) # Add the newly created raster surface to a Mosaic Dataset arcpy.AddRastersToMosaicDataset_management(outputMosaicDataset, "Raster Dataset", outRaster) i = i + 1 # Calculate the statistics on the output Mosaic Dataset for # classifying your data after new rasters are added arcpy.CalculateStatistics_management(outputMosaicDataset,"1","1","#")
The error (near top of this post) points to line 34, which reads:
arcpy.MakeFeatureLayer_management(lyr, tempFeatureLyr, timeQuery)
I have checked lyr.isFeatureLayer and it's
True, timeQuery returns the next time slice in a proper string format that i have verified in the SQL builder, and tempFeatureLyr =
'tempTimeLayer1'...but it does not create it. As in, I do not see tempTimeLayer1 layer in the Table of Contents, though
tempTimeLayer0 IS. So, it's not being created, though its name (tempTimeLayer1) is ready to go...
Here is the site I got the help from, example 3: LayerTime(arcpy.mapping)