0

I have 5 geodatabases. All have a feature dataset that contains a point feature class called "Point" and a line feature class called "Polyline." I want to go through these feature datasets, take only the Polyline feature class and append it to a master feature class.

Is there a way to nest iterators?

I tried created submodels, but that didn't seem to work.

2

A Quick Model to demonstrate nested iteration:

For this cocktail, you're going to need 5 Input GeoDatabases(or more if you like), and 1 Output GeoDatabase. The Input_GDB's should have some Feature Datasets that contain some Feature Classes. The Output_GDB only requires a Feature Dataset.

A workspace similar to this:

Workspace Layout

We are going to need 8 Models(seen in the Contents Tab and the StackExchange Toolbox under the Catalog Tree) for this solution:

  1. Combine_To_Master
  2. Create_Combine_Target
  3. Iterate_Feature_Classes
  4. Iterate_Datasets
  5. Iterate_Workspaces
  6. Append_Feature_Classes
  7. Append_Datasets
  8. Append_Workspaces

Combine_To_Master drives the whole process with parameters for:

  1. Input Folder (folder named Iterate_GDBs in this example)
  2. Workspace_Wildcard (filter applied to GDB names in the Workspace Folder)
  3. Dataset_Wildcard (filter applied to Dataset names in each GDB)
  4. FeatureClass_Wildcard (filter applied to Feature Class names in each Dataset)
  5. FeatureType (filter applied to Feature Class Iterator for geometry type isolation)
  6. OUTPUT_Master_Feature_Dataset (Full Path to a pre-existing Dataset within the OUTPUT GDB)
  7. OUTPUT_Master_Feature_Class (String name used to generate target feature class in OUTPUT_Master_Feature_Dataset)* This name must be unique within the OUTPUT_Master_Feature_Dataset and NOT pre-Exist as this tool will NOT overite an existing OUTPUT_Master_Feature_Class.

Here's the UI: Combine To Master UI and the Model: Combine_To_Master Model

It contains 2 sub-models:

  1. Create Combine Target (generates OUTPUT_Master_Feature_Class using schema from first valid feature class)
  2. Append Workspaces (copies valid features to OUTPUT_Master_Feature_Class)

Create_Combine_Target iterates into the workspace to find the first valid Feature Class and uses that Feature Class as a template to create the OUTPUT_Master_Feature_Class schema in the Output_GDB Feature Dataset.

Append_Workspaces iterates over all the filtered workspaces,datasets,and feature classes and appends the valid feature classes to the OUTPUT_Master_Feature_Class created in the previous step.

The Create_Combine_Target Model looks like: Create Combine Target Model It contains sub-model Iterate_Workspaces and the built-in Create_Feature_Class Tool.

The important part here is that sub-model Iterate_Workspaces will call Iterate_Datasets which will call Iterate_FeatureClasses which will return the first valid feature class AND a boolean, FC_Found, as a pre-condition to the built-in Create_Feature_Class Tool. Additionally, it will set the Stop Flag to avoid unnecessary iteration after the first valid feature class has been found.

If we look at the Iterate_Workspaces model we will start to see how the iterators chain into this process definiton. Iterate Workspaces Model This model sets up the Workspace iterator to feed workspaces from the Iterate_GDB's folder filtered by the Workspaces_Wildcard into the Iterate_Datasets sub-model.

The Iterate_Datasets Model looks like: Iterate Datasets Model This model is similar to Iterate_Workspaces except it feeds datasets from valid workspaces filtered by Dataset_Wildcard into the Iterate_Feature_Classes sub-model.

And the Iterate_FeatureClasses Model looks like: Iterate FeatureClasses Model The only unique thing about this model is the Calculate Tool used to insepect the Feature_Class_Name in order to set the Stop Flag once a valid feature class has been found.

Claculate Tool Expression:

fc_found(r"%Feature_Class_Name%")

Calculate Tool Code Block:

def fc_found(fc_name):
  if len(fc_name)>0:
    return True
  else:
    return False

Calculate Tool Datatype:

Boolean

Once a valid feature class has been found, the Stop Flag will be set, FC_Found will be set to True, the feature class and FC_Found will be returned to the Iterate_Datasets Model.

The Iterate_Datasets Model will set its Stop Flag and return the feature class, along with FC_Found, to Iterate_Workspaces.

The Iterate_Workspaces Model will set its Stop Flag and return the feature class, along with FC_Found, to Create_Combine_Target.

The Create_Combine_Target Model will set its Stop Flag and pass the feature class to the built-in Create_Feature_Class Tool.

The Create_Feature_Class tool will generate the TARGET_FEATURE_CLASS and return it to Combine_To_Master.

The Combine_To_Master Model will pass the newly created feature class on to Append_Workspaces as the TARGET_DATASET parameter.

The Append_Workspaces Model looks like: Append Workspaces Model This model sets up a new Workspace iterator to feed workspaces from the Iterate_GDB's folder filtered by the Workspaces_Wildcard into the Append_Datasets sub-model.

The Append_Datasets Model looks like: Append Datasets Model This model is similar to Append_Workspaces except it feeds datasets from valid workspaces filtered by Dataset_Wildcard into the Append_Feature_Classes sub-model.

The Append_Feature_Classes Model looks like: Append Feature Classes Model This model is where the GLORIOUS MAGIC happens! Every feature class furnished by the iterator (filterd by Folder/GDB Name/Dataset Name/FeatureClass Name/FeatureType) is Appended to the TARGET_DATASET (which is really holding the OUTPUT_Master_Feature_Class!!)

Here's some sample maps that show the input / and output feature classes after execution of the Model.

Input Map: Map INPUT Layers Output Map: Map OUTPUT Layers

For anyone who is brave enough and still reading this, here are the:

Models and Sample GDB's

*Future Plans for this tool include, TimeStamping and Source Documenting the features as they are loaded into OUTPUT_Master_Feature_Class. Source Documenting will be spread across 4 columns named SOURCE_PATH, SOURCE_GDB, SOURCE_DATASET, and SOURCE_FEATURE_CLASS to allow for some interesting post-analysis.

1
  • Wow impressive, I am interested to have the toolbox and example data. Would you mind to put it in dropbox or other cloud storage please? – user97103 Sep 29 '19 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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