Editing Example Python Scripts for Beginners

Discussion created by paul.nuim on Feb 1, 2013
Latest reply on Feb 4, 2013 by paul.nuim

I'm a student, I haven't used Python before but am currently working through getting myself up to date on it, I came across a sample python script on the Arc10 Help website that I would like to use.

My understanding is the code batch runs IDW tool on point data that is time enabled, I've tried playing around with the code for 4 days now and am getting no where with it.

Really what I would like to know is what do I have to modify to get it to work with my own data?

I've highlighted the parts of the code (below) that I think I need to modify for it to work with my data but can some one please let me know if there is other parts of the code I need to modify?

Please and thanks in advance:

import arcpy, datetime
# Check out the ArcGIS Spatial Analyst extension for using the IDW interpolation tool

# 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, "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