Hi,
Sorry it took so long to say thank you. After working through the tables and the code I finally got it to run properly without any errors. It was amazing. Thank you. I put together this code for the IDW so that someone can select several different fields from the same table and run IDW on the data for that set of points. It's really crude but it works I suppose. Again I want to thank you for all your help. If you have any suggestions on the stuff at the bottom let me know.
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
env.workspace = "C:/Users/Anne/Desktop/Python/finalproj"
#Set Variables
points = "Export_Output.shp"
zfield1 = "pH"
zfield2 = "Pphate"
zfield3 = "K"
zfield4 = "CA"
zfield5 = "Mg"
#First Run
outidw1 = Idw(points, zfield1)
outidw1.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10ph")
#Second Run
outidw2 = Idw(points, zfield2)
outidw2.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10pphate")
#Third Run
outidw3 = Idw(points, zfield3)
outidw3.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10ll")
#Fourth Run
outidw4 = Idw(points, zfield4)
outidw4.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10ca")
#Fifth Run
outidw5 = Idw(points, zfield5)
outidw5.save("C:/Users/Anne/Desktop/Python/finalproj/data/outputs/ab10mg")
Hi Anne,Glad to hear you worked it out. I would like to tell you something on using dictionaries and looping through data. In your sample where you calculate the IDW for 5 fields, you could have used a dictionary containing the input field names and output raster names.import arcpy, os
arcpy.CheckOutExtension("Spatial")
ws_out = "C:/Users/Anne/Desktop/Python/finalproj/data/outputs"
env.workspace = ws_out # set it to your output workspace
arcpy.env.overwriteOutput = True
#Set Variables
points = "C:/Users/Anne/Desktop/Python/finalproj/Export_Output.shp"
# dictionary with fieldnames and output raster names
d = {'pH': 'ab10ph', 'Pphate': 'ab10pphate', 'K': 'ab10ll',
'CA': 'ab10ca', 'Mg': 'ab10mg'}
# loop through the dictionary
for fieldname, rasname in d.items():
# are you sure you want to accept default cellsize, power and search radius?
outidw = arcpy.sa.Idw(points, fieldname)
outidw.save(rasname) # no path included, so saved to (output) workspace
# return the sa license
arcpy.CheckInExtension("Spatial")
In case you want to use the field name in the output raster name you could a list as well:l = ['pH', 'Pphate', 'K', 'CA', 'Mg']
ras_prefix = 'ab10'
for name in l:
outidw = arcpy.sa.Idw(points, name)
outidw.save('{0}{1}'.format(ras_prefix, name))
Another thing to remember is that you are not specifying any cellsize, power and search radius settings. If you have your environment settings setup correctly and your points are also located outside your study area, this might give appropriate results. If your area is cutoff (since it will by default take the extent of the points) you may want to define things like arcpy.env.snapRaster and arcpy.env.extent.Kind regards,Xander