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)
1 Answer 1
The error you are showing is coming from c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py
and it would be easier to take a stab at its cause if we knew the precise line from your script - running it in IDLE is how I usually find that.
It may be that it is simply due to you having:
arcpy.env.workspace = "C:\Users\Chris\Desktop\interpolation\Interpolation.gdb"
instead of:
arcpy.env.workspace = r"C:\Users\Chris\Desktop\interpolation\Interpolation.gdb"
-
thanks for the thought, i'll put the r in and let you know. In reference to taking a stab at the arcpy\management.py error, I actually opened up the file and had intentions of going to line 6043 to get more info, but the code is obfuscated, or something, and I couldn't see more than the first 30 lines or so. Standby and I will adjust with the r. What does the r and u do before paths anyway?geokrowding– geokrowding2015年02月14日 21:11:25 +00:00Commented Feb 14, 2015 at 21:11
-
I would advise strongly against editing anything in
c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy
because it could invalidate your install.r
stands for raw and says to just read the rest of the string "as-is" without interpreting the backslashes as escape characters.u
is to do with Unicode characters.2015年02月14日 21:55:14 +00:00Commented Feb 14, 2015 at 21:55 -
noted, thanks. I was more or less wanting to poke around the see where it tripped. I appreciate the explanation on r/u, cheers.geokrowding– geokrowding2015年02月14日 22:16:12 +00:00Commented Feb 14, 2015 at 22:16
-
The errors from IDLE usually point me straight at where the problem lies.2015年02月14日 22:26:53 +00:00Commented Feb 14, 2015 at 22:26
-
So in going to IDLE to see what line or info might help it actually ran! Thanks for the nudgegeokrowding– geokrowding2015年03月19日 21:03:14 +00:00Commented Mar 19, 2015 at 21:03
lyr
variable being set anywhere.