[GIS] Using ModeBuilder to populate a table with the feature count of multiple feature classes

arcgis-10.1arcgis-desktopfile-geodatabaseiteratormodelbuilder

Specs: I'm using ArcInfo 10.1 and have all extensions available to me.

I have a folder with many file geodatabases.

Each file geodatabase contains 2 feature classes. One is a point fc and the other is a polygon fc.

I'm trying to figure out how to calculate the total number of polygons stored in all geodatabases in this folder. I'm happy for this number to go anywhere i.e .txt, .csv, .xls, even just a box somewhere so I can write it down.

I think I'm nearly there with ModelBuilder, but I'm stuck at what I believe is the last step.

My logic:

1 – Use an iterator to iterate through all the fgdb's in the folder.

2 – Use an iterator to iterate through the feature classes in the fgdb looking only at the polygon feature type.

3 – Use the Get Count tool to count the number of rows in the feature class.

4 – This is where I'm stuck. I think I want to be using the Collect Values tool to collect all off the returned polygon counts, but I can't figure out how to extract and sum the values from here. Am I thinking about this in completely the wrong way?

Iterate Workspace

Iterate Feature class

Best Answer

You are close.
In both models you will need to add the model only tool Calculate Value. The output of that tool should also be an output parameter of the inner model.
You can't use the output of collect values as the input directly so set it as the precondition.
Then set the expression of Calculate Value to:

    sum_counts('%Row Counts%')

%Row Counts% is the name of the output from Collect Values (defaults to output_value). Be sure to include the quotes.

And, the code block should be:

    def sum_counts(counts):
        if counts.find(';') == -1:
            if counts <> '#': return int(counts)
            else: return 0
        else:
             return sum(map(int, counts.split(';')))

The output value from the Calculate Value tool in your upper model should be the total count: Iterate Folder enter image description here

P.S. I'd recommend a Python script for this sort of thing. If you haven't checked it out much, it would be worth the time.