How to iterate a single selection over multiple fields (ModelBuilder or Python)

624
1
08-13-2013 06:29 AM
EliKnaap
New Contributor
I have a file that contains point data for several thousand residential locations. The file contains locations spread across a 15 year span, and the attribute table contains binary fields indicating whether a household was occupied in a particular location in a given year (2000, 2001, 2002, etc). There are also a few fields that include neighborhood characteristics for each location.

A simplified version of the table looks something like this:
("Loc*" indicates whether a household was present at that location for the given year and "data" represents a field for which I need summary statistics)
[TABLE="class: grid"]ID
Loc00Loc01Loc02Loc03Data23410003472351110124352360111354
[/TABLE]

I am trying to create a time series of the average neighborhood characteristics of these residences by year. Basically, I am trying to iterate a selection over each Location field, selecting only the points occupied during a single year (Loc*=1) then compute the mean value for a few data columns and save those values in a table.

I have not been able to automate this with ModelBuilder because the Select by Attributes tool does not perform sequential iteration like I need. Instead, it uses grouping variables to create every unique combination of location (e.g. Loc00=1,Loc01=0, etc). Trying to use a list of values for the Select by Attribute tool (as opposed to an Iterator) does not work either because the model simply performs each selection in sequence before calculating any statistics (I've tried setting every precondition possible)

Does anyone know if it is possible to create a single SQL selection that will iterate over a specified set of fields?
0 Kudos
1 Reply
MichaelStead
Occasional Contributor III
I am always making this stuff up as I go along, but if you are still trying to do this here is a script I built today that iterate through fields and creates a TIN for each and does some other stuff. I didn't want it to use the OBJECTID field or the northing and easting so it is seperated into 2 blocks....there is almost certainly a more elegant way to do that part.... basically you make a list of the fields and iterate through the list

import arcpy, arcgis, os
from arcpy import env
from arcpy.sa import *

InTable = arcpy.GetParameterAsText(0)
InPoints = arcpy.GetParameterAsText(1)

fieldList = arcpy.ListFields(InTable)
for field in fieldList:
        f_name = field.name
        if not (f_name == "easting" or f_name == "northing" or f_name == "OBJECTID"):
                arcpy.MakeXYEventLayer_management(InTable, "easting", "northing", "temp", "", "")
                para_in = "temp" + " " + f_name + " masspoints"
                arcpy.AddMessage(para_in)
                arcpy.CreateTin_3d("NewTIN", "", para_in, "constrained_delaunay")
                arcpy.TinRaster_3d ("NewTIN", f_name, "FLOAT", "LINEAR", "CELLSIZE 20", "")
                ExtractMultiValuesToPoints(InPoints, [f_name], "BILINEAR")
        else:
                arcpy.AddMessage(f_name)
0 Kudos