How to Enhance Your ArcGIS Workflow with ModelBuilder & Custom Scripts

Automated processes in Geographic Information Systems (GIS) are commonplace for many repeatable workflows because of their consistency and time saving across multiple runs.

Automation can be used in everything from simple data maintenance, to geoprocessing workflows, to output maps and templates. One of the easiest ways to do this within ArcGIS® Pro is through the use of ModelBuilder™ and the Python™ libraries, ArcPy™ and Python™ CIM. 

ModelBuilder is “….a visual programming language for building geoprocessing workflows” that allows for a diagram to place a sequence of steps and tools, including tools that contain custom scripts. ModelBuilder can be used as a drag-and-drop for these tools and the user can inter-connect them in order to build and see a visual workflow of the process. However, if the process that is being automated requires a map output, then the pre-built tools that can be used within ModelBuilder are limited. 

The best way to overcome these limitations is to create a custom scripting tool in Python, combining ArcPy and Python CIM. ArcPy is a “… Python site package that provides a useful and productive way to perform geographic data analysis, data conversion, data management, and map automation with Python.” The Python CIM is “…a map content specification used to persist and transfer cartographic descriptions of GIS datasets” by allowing access to internal components of a project or layer file within ArcGIS Pro. More info about the Python CIM can be found here.  

The following is a quick tutorial of using both ModelBuilder and Python to help automate a workflow for analyzing EPA Facility Registered Services (FRS) sites that are in different HUC-12 USGS Watershed boundaries and then displaying them on a pre-designed template.

Note: This tutorial assumes the reader has appropriate license levels and understanding of both ModelBuilder and the Python programming language. 

 The watershed dataset was downloaded from here and the EPA FRS dataset was downloaded from here.

Set Up Map and Template

The first step is to set up an ArcGIS Pro project that includes a map with the appropriate starting dataset and the template that will be used for the map output. The map just needs to have the datasets required to run the analysis. The template will need to have all the required elements for the final map output.

The following template is the template used in this project, and includes a map, legend, title text box, and two other text boxes for information on the watershed and EPA sites (Figure 1). The legend is set to not add new items to the legend when added to the map.

Because the two text boxes will contain dynamic text that will change on each run depending on the analysis, the text elements were renamed to be more easily identified within the script (i.e., the text box for the watershed information was renamed WSHDInfo). 

ModelBuilder

The next step is to build the model. Figure 2 contains an overview of the model.

The study site is a user interaction point within a given watershed. The point then selects the watershed, exports the single watershed as its own layer, and then from that watershed selects and summarizes the EPA facilities within the watershed. Then the Python script for automating the map output is added as a geoprocessing tool.

A more in-depth tutorial on how a similar model was set up can be found at this link.

Python Script

The custom script for the map-making process uses a combination of the ArcPy library and the Python CIM. This section goes over portions of the script and breaks them down on how they are utilized in the final script. 

ArcPy

The first major portion of the script is to use ArcPy to set the symbology of the two layers, the watershed layer and the clipped EPA facilities. Figure 3 sets the symbology for the selected watershed layer, including the outline with the name from the symbol from the gallery, the color, the size, and width. 

Figure 4 is a portion of the code to set the symbology for the EPA sites layer, in which the points are symbolized on the site type. The code is similar to the single symbol code used for the watershed, but is based on unique values instead, so the renderer has to be updated to reflect the change. Then the field to symbolize EPA site point type is set, and as the cursor loops through the field—if the attribute in the field matches the group label—that symbol is applied.”

The next set of code is used to take attribute information from the selected watershed layer and the EPA sites layer and use that to fill out the text boxes on the map template. Figure 5 is the code.

The first section of the code works by looking at the attribute information in the selected watershed layer – such as the watershed name, size (in acres), and HUC-12 code – and applies the information to a placeholder text for the watershed text element. 

The second section of the above code loops through the EPA FRS summary within the attribute table layer, and gets the count for each EPA facility site type and applies the information to a placeholder text for the EPA text element. 

Lastly, the placeholder text is added to the actual elements in the map template. 

Python CIM

The last portion of the code is to use Python CIM to access the legend properties. The two layers are added as items to the legend using ArcPy. Next, the Python CIM is called upon to set the style for each layer in the legend. This is included to make sure that the the layer name and labels were visible, but nothing else is. 

Final Output

The following video shows the model and script working:

The final output map from the model run in the video (Figure 7):

Considerations and Conclusions

There are some considerations when using both ModelBuilder and custom scripts for automation, especially with map outputs. The first is certain elements on the map may need manual input such as label placement or drawing lines of interest on a map.

The second is that by using Python CIM, you are effectively accessing the back end of ArcGIS Pro, and changing certain settings can cause a Pro project to behave erratically. More information on examples of what causes this and what to look for have been listed by ESRI. 

However, the methods outlined in the article are a powerful tool to start automating analysis and map outputs for consistency and time saving, and can be easily modified based on your project’s needs. 

Interested in more from GEO Jobe? Explore these other MapThis! articles:


About Our Company

GEO Jobe is a leading GIS software and geospatial solutions provider, serving over 10,000 organizations globally. GEO Jobe is best known for developing the most popular applications in the ArcGIS Marketplace, including Admin Tools for ArcGIS, Backup My Org, Clean My Org and Scheduler for ArcGIS.

GEO Jobe offers U.S.-based 24/7 Support solutions for organizations using Esri’s ArcGIS© System. GEO Jobe also offers professional services focused on Esri’s ArcGIS© System, including custom software development, enterprise solution implementation, data science and UAV data collection.

Founded in 1999, GEO Jobe is in its 25th year of operation, has been an Esri business partner since 2002 and is currently a Platinum Partner.

Avatar photo

Solutions Engineer