Modelbuilder - iterative function

443
2
09-17-2018 04:28 PM
chadhickman
Occasional Contributor III

So I am in the process of creating a model in ArcGIS and I am stuck on one particular point. I have about a dozen feature classes that I need to be “extracted” using the feature class to feature class tool, but I only want a subset of each feature class. The subset I am waiting are features that lie in a particular county. I am hoping to extract the subset in each feature iteratively so I dont have to run the same tool a dozen times. 

I have successfully ran the model extracting the subset for 1 feature class using an SQL query but I have not been able to perform this action to run itervatively across the GDB. Does anyone have any suggestions to get this process to work?

Thanks

0 Kudos
2 Replies
MarisaClaggett
Occasional Contributor II

Hi Chad,

I would recommend trying this workflow with python as it gives you access to more control over how the script is run as well as the for loop iterator.

For example:

import arcpy

workspace = "C:\fakefolder\fakegdb.gdb"

arcpy.env.workspace = workspace

for layer in workspace:

      list = [ ] 

      list.append(layer)

for fc = list:

      desc = arcpy.Describe(fc)

      name - desc.name

      layer = arcpy.MakeFeatureLayer_management(fc,  "layer_{}".format(name))
      select = arcpy.SelectLayerByAttribute_management(test, "NEW_SELECTION","country = 'france'")
      arcpy.FeatureClassToFeatureClass_conversion(select,workspace, "test_{}".format(name))
      print ("Done!")

This will select and export layers where the field value for 'country' equals the one that you need. The outputs will have unique names based on what their names currently are in your geodatabase.

If you need to use Model Builder, feel free to attach your model and I'd be more than happy to take a look.  Thanks!

- Marisa

ChrisDonohue__GISP
MVP Alum

On the Modelbuilder side, one of the issues that may be occurring is that the process is actually running through and extracting all the features, but what is output shows only the results for one feature class.  This occurs if unique output names are not specified; instead what happens is the same output gets overwritten again and again.  To resolve this, use In-Line Variable Substitution to allow for the creation of uniquely-named output.

Inline variable substitution—ArcGIS Pro | ArcGIS Desktop 

Chris Donohue, GISP