try: <some code here> except e as Exception: arcpy.AddMessage('some error message ' + e.message
import arcpy, datetime # Check out the ArcGIS Spatial Analyst extension for using the IDW interpolation tool arcpy.CheckOutExtension("spatial") # Get the layer time properties lyr = arcpy.mapping.Layer(r"C:\Project\Data\Time\TimeLayer.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:\Project\Output\Output.gdb\outputMosaicDataset" 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:\Project\Output\Output.gdb\raster" + str(i) print outRaster arcpy.gp.Idw_sa(tempFeatureLyr, "Temperature", 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","#")
arcpy.sa.Idw()
Runtime error <type 'exceptions.AttributeError'>: 'Layer' object has no attribute 'time'
import arcpy, datetime # Check out the ArcGIS Spatial Analyst extension for using the IDW interpolation tool arcpy.CheckOutExtension("spatial") # Get the layer time properties lyr = arcpy.mapping.Layer(r"C:\Users\Paul\Documents\ArcGIS\Python Time\Time Data\Time_Enabled.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\Paul\Documents\ArcGIS\Python Time\Time Data\Time_Enabled.shp" 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\Paul\Documents\ArcGIS\Python Time\Time Data\Time Data.gdb\raster" + str(i) print outRaster arcpy.sa.Idw(tempFeatureLyr, "Temp", 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","#")
FID Shape * OBJECTID Station startTime endTime Temp latitute longitude 0 Point 1 GPEP #1 01/01/2011 02/01/2011 8.9 53.306238 -6.222935 1 Point 2 GPEP #1 02/01/2011 03/01/2011 8.7 53.306238 -6.222935 2 Point 3 GPEP #1 03/01/2011 04/01/2011 8.5 53.306238 -6.222935 3 Point 4 GPEP #1 04/01/2011 05/01/2011 8.1 53.306238 -6.222935 4 Point 5 GPEP #1 05/01/2011 06/01/2011 9.2 53.306238 -6.222935 5 Point 6 GPEP #1 06/01/2011 07/01/2011 10.8 53.306238 -6.222935 6 Point 7 GPEP #1 07/01/2011 08/01/2011 12.2 53.306238 -6.222935 7 Point 8 GPEP #1 08/01/2011 09/01/2011 12.8 53.306238 -6.222935 8 Point 9 GPEP #1 09/01/2011 10/01/2011 14.1 53.306238 -6.222935 9 Point 10 GPEP #1 10/01/2011 11/01/2011 16.7 53.306238 -6.222935 10 Point 11 GPEP #1 11/01/2011 12/01/2011 17.3 53.306238 -6.222935 11 Point 12 GPEP #1 12/01/2011 13/01/2011 17.7 53.306238 -6.222935 12 Point 13 GPEP #1 13/01/2011 14/01/2011 17.7 53.306238 -6.222935 13 Point 14 GPEP #1 14/01/2011 15/01/2011 17.9 53.306238 -6.222935 14 Point 15 GPEP #1 15/01/2011 16/01/2011 19.1 53.306238 -6.222935 15 Point 16 GPEP #1 16/01/2011 17/01/2011 19.1 53.306238 -6.222935 16 Point 17 GPEP #1 17/01/2011 18/01/2011 18.8 53.306238 -6.222935 17 Point 18 GPEP #1 18/01/2011 19/01/2011 18.1 53.306238 -6.222935 18 Point 19 GPEP #1 19/01/2011 20/01/2011 18.7 53.306238 -6.222935 19 Point 20 GPEP #1 20/01/2011 21/01/2011 17.1 53.306238 -6.222935 20 Point 21 GPEP #1 21/01/2011 22/01/2011 17.1 53.306238 -6.222935 21 Point 22 GPEP #1 22/01/2011 23/01/2011 18 53.306238 -6.222935 22 Point 23 GPEP #1 23/01/2011 24/01/2011 18 53.306238 -6.222935 23 Point 24 GPEP #1 24/01/2011 01/01/2011 17.3 53.306238 -6.222935 24 Point 25 GPEP #2 01/01/2011 02/01/2011 10.8 53.292258 -6.138301 25 Point 26 GPEP #2 02/01/2011 03/01/2011 10.6 53.292258 -6.138301 26 Point 27 GPEP #2 03/01/2011 04/01/2011 10.2 53.292258 -6.138301 27 Point 28 GPEP #2 04/01/2011 05/01/2011 10.1 53.292258 -6.138301 28 Point 29 GPEP #2 05/01/2011 06/01/2011 10.5 53.292258 -6.138301 29 Point 30 GPEP #2 06/01/2011 07/01/2011 11.4 53.292258 -6.138301 30 Point 31 GPEP #2 07/01/2011 08/01/2011 11.8 53.292258 -6.138301 31 Point 32 GPEP #2 08/01/2011 09/01/2011 12.4 53.292258 -6.138301 32 Point 33 GPEP #2 09/01/2011 10/01/2011 12.9 53.292258 -6.138301 33 Point 34 GPEP #2 10/01/2011 11/01/2011 14.5 53.292258 -6.138301 34 Point 35 GPEP #2 11/01/2011 12/01/2011 16.4 53.292258 -6.138301 35 Point 36 GPEP #2 12/01/2011 13/01/2011 17.2 53.292258 -6.138301 36 Point 37 GPEP #2 13/01/2011 14/01/2011 16.7 53.292258 -6.138301 37 Point 38 GPEP #2 14/01/2011 15/01/2011 17.3 53.292258 -6.138301 38 Point 39 GPEP #2 15/01/2011 16/01/2011 16.8 53.292258 -6.138301 39 Point 40 GPEP #2 16/01/2011 17/01/2011 17.1 53.292258 -6.138301 40 Point 41 GPEP #2 17/01/2011 18/01/2011 17.1 53.292258 -6.138301 41 Point 42 GPEP #2 18/01/2011 19/01/2011 16.8 53.292258 -6.138301