0% found this document useful (0 votes)
12 views

Exercise 6 - Script Tool

This document discusses creating an ArcGIS script tool from an existing Python script. It describes defining parameters, creating a new toolbox and script tool, and adding documentation to the tool. The tool created calculates the cost distance between features using a cost raster surface.

Uploaded by

Tono Surf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Exercise 6 - Script Tool

This document discusses creating an ArcGIS script tool from an existing Python script. It describes defining parameters, creating a new toolbox and script tool, and adding documentation to the tool. The tool created calculates the cost distance between features using a cost raster surface.

Uploaded by

Tono Surf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1

Exercise 6: Creating an ArcGIS script tool


In Exercise 3, you finished a Python script that was a workflow for generating an output table that contained the cost distance between the points in two feature
classes. You already know how useful this tool is, but a colleague has asked for the workflow to be shared so they can run it as well. Since this colleague is not
familiar with Python, but has experience with ArcGIS geoprocessing tools, we need to create a script tool from the Python script so this function can be easily
shared and used by others in ArcGIS.

Define parameters in the script


There are a few necessary changes that must be made to the Python script before it can be made into a script tool. Namely, the hardcoded paths to the inputs
and outputs must be changed to arguments so they can be connected to script tool parameters. This is one of the big advantages of working with script tools;
instead of having to go into the Python script and change the hardcoded paths to all the datasets whenever any of the inputs or outputs is changed, key
variables can be made into arguments so they are defined by what comes from the script tool dialog.

 Open PythonWin
 File>Open to the folder …Python_ArcGIS\exercises\exercise6_scripttools\scripts
 Open the Python script CostDistanceMatrix.py
 The input and outputs are defined at the bottom of the script. Scroll to the bottom, and replace the hardcoded inputs with arguments.

Create a new toolbox and script tool


Like all geoprocessing tools, script tools are stored in a toolbox. There are a number of steps for creating script tools, like setting up basic properties, pointing to
a source file, defining parameters and what kind of data they can accept on the tool dialog, and writing documentation.
2

 Navigate to folder …Python_ArcGIS\exercises\exercise6_scripttool


 Double-click CostDistanceMatrix.mxd to open it in ArcMap.
 In the Catalog window, right-click the Home folder and select New>Toolbox
 Name the toolbox CostDistanceTools
 Right-click the toolbox and select Add>Script
 In the first Add Script dialog, enter the following settings
o Name: CostDistanceMatrix
o Label: Cost Distance Matrix
o Description: Creates a new table that contains the cost distance between every feature in the Origin Features and every feature in the
Destination Features. The cost distance that is calculated across the Cost Raster surface is along the least-cost path between each pair of Origin
and Destination Features.
o Store relative path names: CHECKED
 Click Next.
 Browse to the source Python script, CostDistanceMatrix.py, at …Python_ArcGIS\exercises\exercise6_scripttools\scripts
 Click Next.
 This script tool will have four parameters; three inputs and one output. Enter the following parameters and the corresponding settings
o Display Name: Origin Features, Data Type: Feature Layer, Type: Required, Direction: Input
o Display Name: Destination Features, Data Type: Feature Layer, Type: Required, Direction: Input
o Display Name: Cost Raster, Data Type: Raster Layer, Type: Required, Direction: Input
o Display name: Output Cost Distance Table, Data Type: Table, Type: Required, Direction: Output
 Click Finish.

Documentation
As the creator of the script tool, you are in the best and most knowledgeable position to give guidance to others about how to use your tool. The best way to
convey key information about using the tool is to complete tool documentation through the Item Description editor.

 In the Catalog window, right-click the Cost Distance Matrix script tool and select Item Description. The Item Description window will open
 Click the Edit button to begin entering help content for this tool
3

 In the Item Description, you can add a graphic, search tags, summary information, usage tips, parameter syntax, code examples, and credits.
o The text file CostDistanceMatrix_help.txt at …Python_ArcGIS\exercises\exercise6_scripttools contains content for each of these sections, if you
wish to fill it out.
 Click Save to save your documentation.
 Close the Item Description window.

Results
 Open the Cost Distance Matrix tool by double-clicking it in the toolbox
 Set the input parameters as shown below, then click OK to run the script tool

Creating script tools from your standalone script files is a straightforward way to integrate your Python work into ArcGIS. These script tools can now be easily
shared and re-used, used in other geoprocessing workflows, and made into geoprocessing services in ArcGIS Server.

You might also like