I am using ArcGIS Pro 2.3.2

I am trying to automate the process of making a raster (IDW tool) in model builder by iterating through fields as z-value. I saw some other question asking the same, and it seems that it couldn't be done that easy in ModelBuilder, and that Python was the way to go.

I have this point feature of 200+ points that all have around 70 fields of Z-values (elements). In the snip below, you can see fields with elements, and also fields with ID's and other that I don't want to make a IDW raster out of.

IDW for Lithium

So for Lithium, it would produce this raster:

enter image description here

Now, how would I go about doing this process for all fields, except the ones without elements?

If it's easier, I wouldn't mind just deleting the non-element rasters afterwards, if I could maybe name the raster set after the field name perhaps.

closed as off-topic by PolyGeo Apr 12 at 21:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.


The tricky part is to only list the element fields and no other. You can do this in multiple ways, for example:

  • Manually listing the fields which are not element fields, example below. Or manually list all element fields
  • Use a wildcard with listfields, for example if all your element fields start with some letter
  • List fields with names shorter than 4 letters

Example (untested, I dont have spatial analyst, you will probably need to look at the syntax for IDW and adjust the parameters):

import arcpy
from os.path import join

fc = r'C:\data.gdb\featureclass' #Change
out_gdb = r'C:\outdata.gdb' #Change
not_elementfields = ['OBJECTID','SHAPE','RowID'] #Change

elementfields = [field.name for field in arcpy.ListFields(fc) if f.name not in not_elementfields]
#elementfields = [field.name for field in arcpy.ListFields(fc) if len(f.name)<4]

#Run code above first to get the listing correct, then run everything

for field in elementfields:
    print(f'Proccessing IDW for fieldname {field}')
    outIDW = arcpy.sa.Idw(in_point_features=fc, z_field=field, cell_size=5, power=0.5, 
                search_radius= RadiusVariable(12))

(This is also possible:

import pandas as pd

data = pd.read_csv('https://sciencenotes.org/PDFs/elementlist.csv', names = ['number','symbol','element'])
elements = list(data.symbol)

elementfields = [f.name for f in arcpy.ListFields(fc) if f.name.title() in elements] # title method will camelcase your field names, BE->Be, to match the csv file


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