1

I have one shapefile that contains many fields and I'd like to write a simple script tool that allows me to run IDW for the fields I select. Is this possible?

For example.....

Input: 1 shapefile

Sample  field1  field2  field3  field4 .....
1       26.5    27.5    22.2    32.3  
2       19.1    12.2    45.3    33.3 
3       11.1    15.6    44.4    34.4 

Options:

field 1 ☑

field 2 ☑

field 3 ☑ .....

Output: field1_IDW, field2_IDW, field3_IDW .....

EDIT: The following code works properly

# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *

# Check out any necessary licenses
arcpy.CheckOutExtension("Spatial")

inPointFeatures = arcpy.GetParameterAsText(0)

fieldList = arcpy.GetParameterAsText(1)

# Define local variables
cellSize = 250.0
power = 2
searchRadius = RadiusVariable(12)

for fieldName in fieldList.split(';'):
    outIDW = Idw(inPointFeatures, fieldName, cellSize, power, searchRadius)
    # Save the output 
    outIDW.save("C:/temp/idwout_{0}.tif".format(fieldName))
2
  • ESRI has a blog about the subject here:blogs.esri.com/esri/arcgis/2011/08/25/…
    – Aaron
    Commented Oct 24, 2014 at 19:21
  • This subject refers to a model where you can select multiple values within a field, I believe. I'm trying to select multiple fields. Can the logic here be used to achieve that goal, too? Commented Oct 24, 2014 at 19:48

1 Answer 1

1

One option, here is the general code logic:

  1. Create a script tool with a Field multi value data type
  2. Within the python code, loop through the field list and define the index value as the field parameter within the IDW method

    fieldList = arcpy.GetParameterAsText(0)
    for fieldName in fieldList.split(';'):
        outIDW = Idw(inPointFeatures, fieldName, cellSize, power, searchRadius)
        # Save the output 
        outIDW.save("C:/temp/idwout_{0}.tif".format(fieldName))
    
8
  • Thanks very much for your response! Is there a way to automatically populate the field names in the data type or do they have to be entered manually? I'm editing my post with a screenshot. Commented Oct 24, 2014 at 19:46
  • Yes, you need to source the field data type to be obtained from parameter to the feature class within the script tool parameters tab.
    – artwork21
    Commented Oct 24, 2014 at 19:49
  • Thanks again. I now see a list of fields associated with my shapefile, but I am getting an error. Do you see a problem with my code (posted above)? I'm getting this error: SyntaxError: invalid syntax (script.py, line 2) Commented Oct 24, 2014 at 20:12
  • Can you add your error message to your question?
    – artwork21
    Commented Oct 24, 2014 at 20:13
  • Sorry - added. Error: SyntaxError: invalid syntax (script.py, line 2) Commented Oct 24, 2014 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.