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:
We are going to need 8 Models(seen in the Contents Tab and the StackExchange Toolbox under the Catalog Tree) for this solution:
Combine_To_Master drives the whole process with parameters for:
- Input Folder (folder named Iterate_GDBs in this example)
- Workspace_Wildcard (filter applied to GDB names in the Workspace Folder)
- Dataset_Wildcard (filter applied to Dataset names in each GDB)
- FeatureClass_Wildcard (filter applied to Feature Class names in each Dataset)
- FeatureType (filter applied to Feature Class Iterator for geometry type isolation)
- OUTPUT_Master_Feature_Dataset (Full Path to a pre-existing Dataset within the OUTPUT GDB)
- 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:
and the Model:
It contains 2 sub-models:
- Create Combine Target (generates OUTPUT_Master_Feature_Class using schema from first valid feature class)
- 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:
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.
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:
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:
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:
Calculate Tool Code Block:
Calculate Tool Datatype:
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:
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:
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:
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.
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.