Sunday, July 24, 2016

GIS5103 - Module 10 - Creating Custom Tools

In this module we were tasked to create a custom clipping tool.   Turning your Python script into a tool is an easy way to share the functionality of your script with others.  

The first step was to create a Python script.   We were provided a template script to modify.   Secondly, a new toolbox had to be created.  After adding a script tool to the toolbox we setup the tool properties.   The our modified Python script was the script file and four parameters were created; input file location, clip boundary feature, input features, and output file location.  Setting up the Data Type and Values was an important step.  Full filepaths are required but quotation marks are not needed.  

Module 10 MultiClip Tool dialog box

Once the tool properties were set, we needed to edit our Python script to allow for users to input the parameters.   Using the GetParameter() and GetParameterAsText() functions caused some difficulty for me.   I needed to understand if the object being returned was a string or not.  Our input features parameter was a multivalue, meaning more than one value or a list could be provided.  The Python script used a "for" loop to iterate over each input feature in the list.  We also had to replace the Python script's original "print" statements with the AddMessage function.   Using AddMessage statements enabled messages to appear in the tool progress dialog box and results window.

Module 10 MultiClip Tool Results
For each input feature the name of the feature is printed.  After the Clip Analysis is performed the name of the newly created clipped feature is printed.

I chose to check to see if the tool also worked with a different boundary feature.   I created a map displaying both the Durango clipped features and the NuevoLeon clipped features.

Module 10 Final Map -
mex_rivers, mex_roads, mex_rails, and mex_urban input features clipped to both the Durango and NuevoLeon features.
Finally, I created a flow chart of the script used in the tool.

Module 10 MultiClip Script Flowchart
For this assignment, I had to use ArcGIS help resources to better understand the functions in the script and their respective arguments.   Seeing code samples was helpful.   I also noticed there was a difference sometimes in documentation between pro.arcgis.com and desktop.arcgis.com  

This assignment really helped me see the usefulness of tools.   It makes it so easy to replicate a tool among multiple features and also different parameters.

No comments:

Post a Comment