Merge results of iteration output from collect values

5082
6
Jump to solution
09-14-2017 04:56 PM
Joseph_Kinyon
Occasional Contributor II

I am trying to merge feature classes in a file geodatabase into new feature class in a file geodatabase so that I can then dissolve by an attribute.

Context:

I have a feature class that has the fooprints (polygons) of feature classes (lines) I want to merge.
The complete set of the line feature classes are located in 4 different file geodatabases (due to size of total dataset, the contractor delivered the whole county of 1 foot interval contour lines to the client divided this way).
Each polygon feature is a footprint that represents a feature class of contour lines.
Each polygon footprint feature has the direct path to the line feature class stored as a string/text as an attribute.

Model:

My model takes the feature class of Footprints (input parameter) that cover an area of interest and iterates through those polygon footprint features.
The footprint feature class input has a feature and database friendly name that is parsed out to use as a variable to name the merged output feature class as a parameter called Footprint Name.
The iteration of the features is done using the Iterate Field Values tool in ModelBuilder.
The output Contour Path is a string and is the complete path to each line feature class I want to merge (contour lines).
The value of each iteration is added to a multivalue by the Collect Values tool and ouput  to List of Contour FC Paths, which is also set as a model parameter.

This works.
Screenshot of model attached is called Modelshot
Screenshot of output attached is called ListModel

Problem:
I can't seem to get the merge tool to take this list and execute a merge.

From what I have read the Collect Values tool is the correct tool to use to capture the results of an iteration for a merge but the output is not visible to the Merge tool either in the model or as the output of a submodel.

I've tried making feature layers and collect those to give to the merge tool without success.

I do not want to copy and then add those copied feature classes to the merge because the feature class already exists and remaking it is a performance issue and a waste of drive space/time that I am specifically avoiding with this model.
I have all the paths, I want to automate merging those feature classes into a single feature class which I will then dissolve by the elevation attribute and calculate indexes for labeling using another model.

How do I hook up this list of feature class paths to the merge tool in ModelBuilder?

1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

Your problem is that the path list you are getting is seen by ModelBuilder as a list of text strings. The merge tool's parameter validation is looking for a list of feature classes.  All model elements are text representations of objects, and then the MB environment gives those objects data types. Sometimes you need to convert the data type. 

A straightforward way to do this is to use the Calculate Value tool right before Collect Values:

Expression: r"%Contour Path%"

Code Block: (empty)

Data Type: Feature Class

Use the connector tool to connect Contour Path to the Calculate Value tool as a precondition so it will run on each iteration. Rename the Calculate Value output from Value to Contour Feature Class and connect it to your Collect Values tool. Validate everything. I think when you do this you will be able to connect the feature class list output to the Merge tool in the master model ListModel.

Hope this helps!

View solution in original post

6 Replies
curtvprice
MVP Esteemed Contributor

Your problem is that the path list you are getting is seen by ModelBuilder as a list of text strings. The merge tool's parameter validation is looking for a list of feature classes.  All model elements are text representations of objects, and then the MB environment gives those objects data types. Sometimes you need to convert the data type. 

A straightforward way to do this is to use the Calculate Value tool right before Collect Values:

Expression: r"%Contour Path%"

Code Block: (empty)

Data Type: Feature Class

Use the connector tool to connect Contour Path to the Calculate Value tool as a precondition so it will run on each iteration. Rename the Calculate Value output from Value to Contour Feature Class and connect it to your Collect Values tool. Validate everything. I think when you do this you will be able to connect the feature class list output to the Merge tool in the master model ListModel.

Hope this helps!

Joseph_Kinyon
Occasional Contributor II

Thanks Curtis, that makes sense and was my hunch for making a feature layer. This is the elegant solution I was hoping for and will try that this morning.

Joseph Kinyon

0 Kudos
AbdullahAnter
Occasional Contributor III

I asked same question before. Could you see the Thread?

https://community.esri.com/thread/176035 

Joseph_Kinyon
Occasional Contributor II

Yes, thank you!

I read that whole thread a number of times for the past 2 weeks looking at what I could glean for my needs because it seemed so close and came up in every search.

Very similar, you were seeking solutions for merging feature classes in ModelBuilder

In the end this is also what I wanted, to merge a group of feature classes.

But after much trial and error my problem appeared to be different from yours that kept mine from working.

I was iterating values inside a feature class and needed to feed that list of attribute values containing the direct path to the Merge tool, this is an important subtle difference

Append substitution was your solution, but was not the solution I needed so I posted a new question with a hunch that the data types were wrong.

Curtis' reply got to the nut of the issue of my  model's problem by clarifying that the data type of data the Merger tool needs/validates is a Feature Class --not just the path to the Feature Class.

So doing a conversion so the attributes added to the collect features  was the solution, which was the detail I was unable to find through my searches about the Merge tool input data type requirements in ModelBuilder.

Putting this model with the suggested calculation into a submodel and then adding it the new model merging the submodel's output parameter made it work like a charm.

I will post a follow up for others who may encounter this issue.

Joseph_Kinyon
Occasional Contributor II

As Curtis explained in a previous comment, I inserted the Calculate Value into the sub-model.
The sub-model iterates the field values of the feature class and gives the feature class path stored as text in an attribute.
The Calculate Value tool takes those paths and makes the output a Feature Class>

The Collect Values tool gathers the calculated value of the output of the iteration and that is the output and model parameter called "List of Contour FC Paths" below.
The Calculate Value settings are below that.
Iterate sub model

calculate value settings

The sub-model was added to the Merge Contour Tiles model, the results merged and then dissolved.
It is necessary to put the collect values as the end of the submodel because

if you put the merge in the submodel it will iteratively merge each output,
making the Collect Values an un-useful annoyance.

After the Merge the contour lines were dissolved by elevation attribute, which is an integer.
Not shown is the next step of adding index fields using/calculating the even remaindered intervals

using the Modulus or Mod() function.

sub model snap shot 

I have a script for generating the area of interest from the extent of a map.
This extent polygon is then used to select the footprints from the index of tiles feature class.

The selection becomes the input for this model.

The output of the model is a contour line feature class subset only to the property for which the user is making a map.

Many thanks to Abdullah Anter (with D. Patterson and D. Wiens replies) for his prior thread which helped greatly

in my task of identifying my problem.

Cheers Curtis, it worked!

Joseph_Kinyon
Occasional Contributor II

Epilogue:

There were two final steps to my goal:

One is to finish the model with calculations on the table of the Feature Class for each resulting Dissolve.
The challenge was to add a field, make a calculation, add the results of the calculation to the newly added field.

The calculation was to add the word "index" to it's corresponding index field based on the results of the MOD (modulo) function % in Python. The MOD function determines the remainder of a division, if my desired interval number divides evenly into the original integer then the remainder should be 0 (zero). I then set about making an index for 5, 10, 20, 40 and 100 foot intervals based on the field FEET which is in 1 foot intervals (a very dense contour set derived from last returns of LIDAR with over 8 returns per meter). These indices make it easy for a user to take the base set of contours created and set a simple definition query for the desired interval they wish to symbolize for their layers in ArcMap 10.5.
This was my final functional requirement, that the user could add only the contour lines for the area their map covered (usually 2-10 parcels) and quickly symbolize them with the best performance for drawing the contour lines possible.

Below are snapshots of the final model and the code behind the field calculator used to Calculate Field.

The second goal is to step through a Dataset of Feature Classes containing Footprints of the Extents for maps (calculated from a script in layout view) and iterate the model for each Footprint as a submodel. This is simple enough and not shown.

 Model with Add Field and Calculated Field used in iterator

Python code block used in Field Calculator showing MOD function results added to newly created field