Thursday, July 30, 2015

GISProgramming: Module 10 - Creating Custom Tools

Creating Custom Tools   
     Custom tools. As if automating geoprocessing tasks with Python couldn't get any better, you can integrate your scripts with ArcGIS toolboxes to make custom tools. The general process is as follows (if you already have a script in mind):
1) Create a toolbox in ArcMap in a logical location
     For this exercise, the toolbox went into a Scripts folder containing the script that'll be used to              make my custom tool.
2) Add the script to your toolbox, creating a new tool.
     It is prudent to make a copy of your script and give it a different name as you'll be modifying the        script to suit designated tool parameters in a later step. This allows you to retain the original                should anything go awry. Right click on this new toolbox, select Add > Script. Navigate through        all the options in the Add Script wizard. (Test the tool to make sure you get the desired result.)
3) Set parameters for your new tool
     This can be done in either of two ways. You can set the parameters through the Add Script wizard (initial dialog window) or through the Properties box of the tool (accessed through right clicking your tool). Once parameters are set within the tool
4)  Modify your script
     Set parameters in your script by replacing file paths and file names with the corresponding parameter index within the tool (using the .GetParameter() function). Replace any print statements with message statements (like the .AddMessage() function) to ensure the progress of the tool is being reported in the Results window and progress dialog box.


Example: A MultiClip Tool
     The general process explained above was used to create a custom MultiClip tool. I took a pre-existing script and modified it to meet parameters specified when creating the tool in ArcMap. This tool runs the Clip function on multiple layers simultaneously. I took several screenshots highlighting the tool interface, the results window, and the spatial result of running the tool.
The tool interface for a custom tool made in ArcGIS using a Python script.
Note the four tool parameters which have corresponding lines of code within the script.
The tool results window displaying messages displaying the progress of the tool. 
The spatial result of running this tool.
Several layers are clipped to a given spatial extent.  


No comments:

Post a Comment