Esri APR Implementation, Tracking and Traceability, GIS Pipeline Practice

ModelBuilder App Adds Fields in Bulk to Datasets

January 1, 2017 — Brian Higgins

Happy New Year!  A bit nervous about this year.  For those who don’t know … this is the year in which the 1987 movie The Running Man was set.  Going to stay optimistic and continue to write blog posts nevertheless, including this one about ModelBuilder.

CodeFest Team Takes On Mass Production of Fields

Every year SSP conducts a CodeFest in December.  CodeFest (which I have written about previously) allows for developers to team up with project managers in a competitive setting.  The winner of the event gets a two-hour pass to Top Golf!

SSP recently completed a complex data model which included components of chilled water and steam, which I personally had never modeled before.  Having no standard model, many of the feature classes and field components had to be constructed by hand.

For those unfamiliar with building a large geodatabase in ArcCatalog, trust me when I state that the process is very manual. This can lead to inconsistencies and error if one is not careful.  Any automation tools that can be constructed not only can minimize that error, but also boost user productivity in database construction.

And there presents my idea for CodeFest.  I wanted to build a “Geodatabase Field Manager.” This application would enable the user to mass-produce fields (or verify the existence thereof) across all feature classes in a feature dataset.

For example, most geodatabases contain metadata or editor tracking fields (names may vary) as follows:

  • CreationUser – Tracks the user that produces the individual feature
  • DateCreated – Date the feature was produced
  • LastUser – Tracks the user that last modified a feature
  • DateModified – Date in which the last feature modification occurred

In the last constructed databases, the following fields were also added to every feature class:

  • LegacyClassName – Tracks the name of the source object in a migration
  • LegacyClassID – Tracks the unique ID of the source object in a migration

ModelBuilder Figure 1. CodeFest LogoMy CodeFest team — myself and two others— locked in to code a convenient method that would do this via a user interface.  At the end of the day, we had produced several miles of code. Not to mention this amazing “Geodatabase Field Manager” team logo, featured at right.  We didn’t win, but there is always next year.

Using ModelBuilder for Bulk Field Creations

But, I don’t give up that easily.  So I started playing with ModelBuilder.

ModelBuilder enables users to quickly and visually put together ArcGIS tasks.  These tasks can utilize the results of one step to source the next step.  So … let’s build a quick, useable tool!

  • By default, on the Stardard ArcGIS Toolbar on the far right, there is the ModelBuilder tool (Figure 2).  Add from the customize GUI, if necessary.

ModelBuilder Figure 2. ArcMap Standard Toolbar

  • Upon Clicking the tool, the Model GUI appears (Figure 3).
ModelBuilder Figure 3. Model GUI
  • The first thing we are going to add in to our model is an Iterator.  Iterators quickly enable code to cycle through a process and repeat.  In our process, we want to first cycle through all feature classes in a feature dataset.  To add an Iterator that does this, click the Insert menu, Iterators (from the drop-down menu), and then Feature Classes (from the next drop-down menu).  This is shown in Figure 4.
ModelBuilder Figure 4. Insert of an Iterator
  • Once this is done, the generic tool is added (Figure 5).
ModelBuilder Figure 5. Generic Tool Addition
  • We now must specify the source (where the tool is going to look) of the feature classes.  Double-click on the “Iterate Feature Classes” hexagon and the “Iterate Feature Classes” GUI appears (Figure 6).  The geodatabase (SSP_DATABASE.gdb) and feature dataset (ChilledWaterDataset) has be choosen as the source.  If we desired, we could restrict the source feature classes by entering a wildcard value or feature class type (point, line, polygon).  We want every feature class within the feature dataset, so these options are left blank.  Click the OK button to dismiss.
ModelBuilder Figure 6. Iterate Feature Classes GUI
  • As now shown in Figure 7, the shapes are now colored and have proper names.  The source of the feature classes are shown as the ChilledWaterDataset feature dataset.  The green circle shows cwPipe, which happens to be the first feature class in the feature dataset.
ModelBuilder Figure 7. Model with Colored Shapes
  • We now want to add the “Add Field” function to our model.  The easiest way to do this is to open ArcToolBox (highlighted on the Standard Toolbar).  Navigate to the Data Management Tools–>Fields–>Add Field.  Drag the Add Field Tool onto the model.  The result will appear as shown in Figure 7.
ModelBuilder Figure 8. Addition of the Add Field Tool
  • A connector (Tool Higlighted) must now be added from the feature class (currently cwPipe) to the Add Field function.  Click on the tool, then click on the feature class and lastly on the Add Field tool.  A small window will appear of which the Input Table function should be choosen.  The final results should look as shown in Figure 8.
ModelBuilder Figure 8. Addition of Connector
  • We now need to double-click on the Add Field rectangle to add the field specifics.  As shown in Figure 9, we have added the field titled CreationUser with the type of TEXT with a length of 20 characters.  What is also handy is the specification of the field alias.  In this case, we want to insert a space between the words.
ModelBuilder Figure 9. Declaration of Field Specifics
  • Upon clicking the OK button, we now have a completed (in terms of this demonstration) model (Figure 10).
ModelBuilder Figure 10. Completed Model
  • Prior to running, it is a good idea of verify the model.  Click the Validate Entire Model button which is the check mark that is highlighlighted in Figure 10.
  • Assuming that the model validates successfully, click the Run button (also highlighted in Figure 10).
  • A dialog box appears illustating the status of the model run (Figure 11).
ModelBuilder Figure 11. Model Run Status
  • Another good verification would be to spot check in ArcCatalog to make sure the field was added/verified in every feature class in the designated feature dataset (Figure 12).
ModelBuilder Figure 12. ArcCatalog Verification
  • To add additional fields to the feature dataset, double-click on the Add Field rectangle, make the necessary changes, and rerun.
  • The model can also be saved for future use.

Final Thoughts on ModelBuilder and Fields

This demonstration only scratches the surface of what ModelBuilder is capable of.  Please feel free to provide your success stories with ModelBuilder in the comments below.
In terms of CodeFest, too bad we can’t get Richard Dawson to give our team’s presentation next year to a tough SSP crowd.

We Wrote the Book

The Indispensible Guide to ArcGIS Online

Download It for Free

Brian Higgins

Solution Architect

What do you think?

Leave a comment, and share your thoughts

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.