3

I am unable to find any info on how to use ModelBuilder to run a certain spatial analysis function on each column in a table.

I have a table to sample locations and at each location there are a series of measures (e.g. temperature, flow rate, number of certain species). For each of those attributes (columns in the table), I was to run the IDW function from the surface tools.

This would be easy if I had each attribute in a separate shp/feature class, but not very efficient. I tried Iterate Feature Selection, but was unable to pass the field name as the Z value in the IDW function.

This is for ArcGIS 10.1 (Basic and Spatial Analyst license)

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Mr.ecos
  • 471
  • 9
  • 16

1 Answers1

8

I believe you will need to build a small Python script and paste that into your Model. You would use the ArcPy module and build a field list on your layer:

fieldList = arcpy.ListFields("C:/Data/MyGIS.gdb/MyLayer")

and then you would iterate through the fieldList using a for loop, for example

for field in fieldList:
    #run your spatial analysis function on field
nmpeterson
  • 8,276
  • 33
  • 59
user12711
  • 1,620
  • 3
  • 16
  • 26
  • Thanks! The ListFields() is super handy. I took it out of model builder now and am trying to do it all in a Python script. I had figure there would be an iterator for that, but it now gives me a good reason to work with Py. – Mr.ecos Mar 18 '13 at 21:02
  • This just helped me out with the Global Moran's I tool. Worth adding that the field object in Arc has properties and tools may be after field.name rather than field. They may also throw an error depending on the field.type. – Oliver Burdekin Jul 24 '14 at 01:24
  • 1
    I am also trying to do the exact same thing but having a hard time to make it work, can you share how you did it in Py or model builder? – Uttam Paudel Jun 23 '13 at 05:15
  • Could you elaborate on the "run your spatial analysis function on field" bit please? What shall be the script be like in ArcPy? – Bowen Liu Oct 18 '17 at 14:29
  • 1
    @AndrewLebron, regarding your previous post, Kernel Density is another function in arcpy which can be run through python interpreter in ArcGIS. For example interim=arcpy.sa.KernelDensity("C:/Data/MyGIS.gdb/MyLayer",field.name,100,500,'SQUARE_KILOMETERS','EXPECTED_COUNTS') will produce kernel density raster and assign to a temporary (as long as not saved) raster. Then you can save this as interim.save(("C:/Data/MyGIS.gdb/MyLayer_Kernel_%s" %field.name). – fatih_dur Oct 19 '17 at 06:17
  • Thanks @fatih_dur for the answer. The first code worked but I couldn't get the second one to work. And I have a question about the first one as well: the 3rd and 4th input (100 and 500) shall be the cell size and search radius right? I really don't know what to put for the search radius. The default (leaving it blank ) when running the tool works just fine. How can I do it when using Arcpy, as in leave it blank, fill in the default. – Bowen Liu Oct 19 '17 at 15:25
  • @fatih_dur and for the second code, I couldn't get it to work. Every time I put in %field.name part (like %Employment 01) it will say that it is not defined. When I just put in the interim.save(File Location), it says: Output raster format UNKNOWN is unsupported. Could you help me here please? BTW, how shall I iterate in this way? Shall I do the fieldList first and then make the code interim=arcpy.sa.KernelDensity("File location",FieldList,100,500,'S‌​QUARE_KILOMETERS','E‌​XPECTED_COUNTS')? Thanks again. – Bowen Liu Oct 19 '17 at 15:42
  • @AndrewLebron, I think your problem has been resolved. For th records, you can look at this thread, https://gis.stackexchange.com/questions/14374/interpretation-of-arcgis-kernel-density-legend-parameters, for more information about the optional aprameters of kernel density. And the second part, I am sorry about that, I did not pay attention to arcpy.ListFields, which returns all fields. You do not need to change %field.name since field variable here is arcpy.Field object and name is its attribute, which returns the object's name. – fatih_dur Oct 19 '17 at 22:22
  • [CONTINUED] If you need to return specific fields for your analysis, you need to specify them, such as fieldList = [f for f in arcpy.ListFields("C:/Data/MyGIS.gdb/MyLayer" if f.name.upper().startswith("C"))] – fatih_dur Oct 19 '17 at 22:24