Wednesday, July 29, 2015

GIS Programming - Module 10 - Creating Custom Tools

This module examines how a stand-alone Python script that's been written for use with ArcGIS can be modified and turned into a script tool that can be accessed very conveniently from inside ArcMap. It's necessary to make just a few minor changes to the original script, and it can then obtain parameters that are specified by the ArcGIS user from the map environment.  The user does not even need to know anything about Python, and the new script tool can be incorporated into ModelBuilder and other scripts.

For our assignment, we created a new Toolbox from ArcCatalog and within that, a Script Tool that will clip shapefiles to the extent of a clip boundary shapefile.  The tool allows the user  to navigate to the data in its file location.

Figure 1 (below) shows the tool dialog that I created in ArcCatalog,
from the stand-alone Python script.


Figure 1. Clip Tool dialog box, ready for input by the user.

This dialog has spaces for the input path (with a default provided), single or multiple input features that will be clipped, the Clip feature, and the default output path.
It's also possible in the tool settings to add a description, shown on the right of this example, and Tool Help, including what the script looks like.






Figure 2. Dialog box, after being filled by the ArcMap user.

 The user fills in these blanks, as shown in Figure 2 (left) then clicks okay, and the script runs in the background, with no direct involvement by the user.




Figure 3.  Successful Results Message for the Clip Tool,
produced in the ArcMap environment












Although the user need not ever see the actual Python script, the script's progress can be monitored in the foreground of ArcMap,via results messages written into the original script, as shown in Figure 3, left.. These messages indicate the tool's progress (including any errors) to the ArcMap user.














Figure 4.  New shapefiles added to ArcCatalog and
the ArcMap display
Finally, after the tool runs, the resulting clipped features are stored in the Results folder, as seen in ArcCatalog, and can be added to the map display in ArcMap (both shown in Figure 4, left).
The light purple area is the clipping boundary shapefile, the State of Durango, Mexico,  Roads, railways, rivers and urban areas are the input files, and they are shown in the map display as colored lines, clipped to the extent of  the Durango shapefile.  

No comments:

Post a Comment