Lab exercise 9 due Apr7, 2008
EES6513: Advanced GIS, UTSA
Student name: ______________
Part II: Further development with Geoprocessing
Based on tutorials found in ESRI Visual
Campus (campus.esri.com),
"Geoprocessing with ArcGIS Desktop”
Lab data: Copy the directory of Lab9 under \\129.115.25.240\XIE_misc\EES6513\
into your local
computer
About the
lynx project
Most of the exercises
throughout the rest of the lab are designed to take you through a
problem-solving scenario using ArcGIS Desktop geoprocessing tools and methods. Before moving on, read the
following information to get acquainted with the project specifics.
The scenario
A regional wildlife conservation plan needs updating and you've been asked to
contribute by using GIS to model suitable habitat for an animal called the
As your first task, you're
going to construct a test GIS project for finding suitable lynx habitat in
northeastern
In the interest of time,
the initial research and information about the required datasets are provided
for you below. Please be aware that the methodology you're going to use in the
lynx project, while based on readily available information and standard GIS
practice, is for educational purposes only.
Lynx facts
Unless otherwise noted, the following information comes from the Oregon Fish
and Wildlife Office, a department of the US Fish and Wildlife Service
(http://oregonfwo.fws.gov).
The
|
|
|
Lynx (Lynx canadensis). Family: Felidae.
Group: Mammals. (Photo by Erwin & Peggy Bauer/USFWS) [Click to enlarge] |
As of March 2000, the
Lynx project data
The datasets you will use only cover a small geographic area in order to keep
the data downloads quick and easy. Normally, projects such as this one are
regional in scope. The project data used in this course would best be applied
to a larger geographic area.
Based on the research, you
will start the project with the basic datasets shown in the table below.
|
Dataset |
Reason |
|
vegetation |
Lynx
prefer montane coniferous forests containing lodgepole pine, spruce, subalpine
fir, cedar, or hemlock. |
|
elevation |
Lynx in
the northwest prefer elevation zones between 4000 and 6000 feet. |
|
prey
habitat |
Lynx
prefer a snowshoe hare diet that also includes squirrels and grouse. |
|
landforms |
Lynx
prefer gently rolling terrain. |
|
watersheds |
Watershed
boundaries will be used to create a study area for the pilot project. |
The selected source
datasets are based on research papers and documents about lynx habitat. Defining
lynx habitat is a complicated process requiring consideration of many factors
and conditions deduced from years of field work by experts. The source datasets
offered in this lab are for educational purposes only and shouldn't be
construed as an alternative to the work accomplished by those experts.
Lynx project workflow
For this part, you'll use geoprocessing tools and
methods to complete the project steps listed below.
·
First, you'll
prepare the data for analysis by building a project database and getting the
data ready for analysis.
·
Next, you'll
analyze the data. Specifically, you'll use geoprocessing
to model potential habitat.
Setting up your work
environment
A key characteristic of
successful geoprocessing is organization. Knowing
ahead of time where the input data is stored and where the new output datasets
will be located will help expedite your workflow. You can organize your data
input and output locations by using or creating workspaces, or
containers for geographic data. A workspace can be a system folder, a geodatabase, or a feature dataset.
Workspace organization not
only standardizes the way you work, but also helps you protect original data
and better manage the results of geoprocessing. You
can use geoprocessing tools to create new workspaces
and migrate source datasets into them. You might choose to create separate
workspaces for intermediate
data and final data. The first thing you will do for the lynx project is
create workspaces.
Another way to organize
your work environment is to isolate the geoprocessing
tools you will need for your project. You can create a custom toolbox that
contains only a subset of the many geoprocessing
tools available to you, making your project tools easily accessible by you as
well as those with whom you want to share your work. For the lynx project, you
can create and work with custom toolboxes that will contain only the geoprocessing tools you need.
Organization
considerations
Workspace organization
involves defining where your input and output data will physically be located.
It can be an ad hoc organization that you design for a simple one-time project,
or it can involve many people working together to design an entire database. It
all depends on the scope of your project.
For example, the workspace
organization for a simple project might be a geodatabase
that contains almost everything, including original data, final data, and
toolboxes. The advantage of this type of organization is that nearly everything
you need for your project is stored in one database. Scripts, however, cannot
be stored in a geodatabase, but they can be
referenced by script tools that are stored in a geodatabase.
You'll learn more about script tools later in the Lab.
|
|
|
A geodatabase
can hold all of your project data as well as custom toolboxes. Scripts are
stored in a separate system folder. |
The single geodatabase workspace makes it easy to share your project
with other people in your company. However, since you're only using one
container for your project, you have to pay special attention to managing geoprocessing results (the output data).
Another approach is to use
system folders to define the workspace organization. For example, you might create
an upper level project folder composed of subfolders. One subfolder could be
designated for data, and it might contain one or more geodatabases.
Another subfolder could be used to store custom toolboxes, while another could
be used to store scripts. Everything you need for your project is stored either
in a system folder or a geodatabase. In this way, you
can easily share either the whole project or individual pieces of it. This is
how you'll organize the data for the lynx project.
|
|
|
System folders can be used to organize multiple geodatabases,
custom toolboxes, and scripts. |
Remember, workspaces are
simply containers for geographic data. By designating separate workspaces for
various stages of your project, you will be able to better manage your data. In
other words, you will know exactly where your input data is coming from and
where it will go when you run operations on it.
Step 1:
Create your organizational workspaces
A. Start ArcCatalog and navigate to a workspace
In the Catalog Tree,
navigate to your module folder …\Prepare
The Prepare folder is a geoprocessing workspace. The datasets it contains are the
source data for the lynx project. They represent the basic ingredients for
defining potential lynx habitat. Before you do anything with the data, you will
create some organizational workspaces.
But first, you should
check your geoprocessing options. From the Tools
menu, choose Options. click the Geoprocessing tab.
Make sure that the options
to Overwrite the outputs of geoprocessing operations
and Log geoprocessing operations to a history model
are both checked.
B. Create a folder
workspace from the command line
Click
the Show/Hide Command Line Window button
to
display the Command Line window.
In the command line, start
typing the word create.
From the drop-down list,
select CreateFolder and press the space bar. The
usage tells you that the next required parameter is the output location for
your new folder.
In the Catalog Tree, drag
the Prepare folder and drop it into the command line; add a space, then
for out_name, type the name of the new folder: LynxProject, which is your master workspace. All of your related project
materials and data will be stored here.
Now execute the command by
pressing the Enter key. The LynxProject folder is
added under the Prepare folder.
C. Create additional
folder workspaces
You'll create a few more
organizational folders using the command line. You'll recall the previous
command, edit it slightly, and then execute it.
In the message area below
the command line, right-click the CreateFolder
command (displayed in blue) and choose Recall.
In the command line modify
the path in the CreateFolder command by typing a backslash
( \ ) after the word Prepare and then deleting the space in front of LynxProject Now the command says that you're going to
create a folder in the LynxProject folder.
Place the cursor directly
after the word LynxProject and press the space bar. For
out_name, type Data. (e.g.,..prepare\LynxProject\Data).
Execute the command.
Now recall your last
command to create the Data folder.
Backspace over Data and
name the new folder Tools.
Execute the command.
When you are finished,
expand the LynxProject folder in the Catalog Tree. It
contains two subfolders: Data and Tools.
Next,
you will create geodatabases for the project.
D. Create geodatabase
workspaces
Like folders, you can also
generate geodatabases using the command line. In this
step you will use the tool dialog box to create one geodatabase,
and the command line to create another.
In the Catalog Tree,
scroll down to the Toolboxes folder and expand it.
Expand Data Management
Tools-> Workspace toolset. Double-click the Create Personal GDB tool to open
its dialog box. Position the dialog box so that you can see it and the Catalog
Tree simultaneously.
In the Catalog Tree,
navigate back to your …\Prepare\LynxProject
folder. Drag and drop the Data folder from the Catalog Tree to the
Output Location text box on the Create Personal GDB dialog box.
In the Output Personal GDB
text box, type LynxHabitat.
Click OK. Then you can see
the newly created LynxHabitat geodatabase, which
will store your final result.
In the message section of
the Command Line window, scroll up and notice that all the processes you've
executed in this session are recorded in blue.
Recall the previously
executed command (CreatePersonalGDB_management).
Change the name of the out_name to LynxScratch,
which will store the temporary
files.
Execute the command.
Step 2.
Create and Customize a toolbox for your project
A. Add tools to your
toolbox
In this step, you will
fill the Lynx_Tools toolbox with the geoprocessing tools that will help you complete those tasks,
then copy the Lynx_tools toolbox into the ..\LynxProject\tool folder.
In ArcToolbox,
click the Index tab. Type the keyword append.
Append (management) is
found. Click Locate in the bottom.
The Append geoprocessing tool is located in the General toolset of the
Data Management toolbox. In ArcToolbox, right-click append, choose Copy, and then
right-click the \Lynx_Tools toolbox and choose
Paste.
Using the same method, add
the following tools to the Lynx_Tools toolbox.
When you are finished,
examine your custom toolbox. Notice most of the system tools you added are
simple, one-process tools, but you also have a system script tool and a system
model.

.
B. Modify ArcToolbox (Optional)
Now that you have
assembled the tools you need for your project, you will modify ArcToolbox by getting rid of all the toolboxes except Lynx_Tools. First,
collapse all the toolboxes except LynxTools_Prepare.
Right-click each of the toolboxes except for LynxTools_Prepare
and choose Remove. When you are finished, ArcToolbox
should only contain Lynx_tools toolbox:
C. Set ArcToolbox environment
As a final step in setting
up ArcToolbox for the lynx project, you will
establish some general environment
settings.
Right-click an empty space
in ArcToolbox and choose Environments.
In the Environment Settings
dialog box, click General Settings to expand it.
For Current Workspace,
click the Browse button and navigate to your the Prepare folder.
For Scratch Workspace,
click the Browse button and navigate to your …\Prepare\LynxProject\Data
folder.
Click LynxScratch.mdb and
click Add.
Now, any geoprocessing tools that you launch from ArcToolbox will be expecting input data from the Prepare
workspace, and all automatically generated output data will be directed to the LynxScratch geodatabase, which
you will use to store all of your temporary and intermediate data. You always
have the option of changing default tool parameters, of course, and you can
change your ArcToolbox environment settings any time.
Click
OK to close the Environment Settings dialog box.
Now you will save the
current state of your ArcToolbox Favorites tab as
well as the environment settings you just specified. Saving your ArcToolbox settings also saves any variables you create in
the command line. You will create a variable in the next step.
Right-click an empty area
of ArcToolbox, point to Save Settings, and click To
File.
In the Save Settings
dialog box, navigate to your …\Prepare\LynxProject
folder. For File Name, type Lynx_prepare.xml
Once you have organized your workspaces and assembled the tools you need for your project, you are ready to start processing the data to prepare it for analysis. Typically, you would first want to move the source datasets to your new organizational structure. At this point, you might choose to convert the data into a common format.
Even with the project data all in one place and in the same format, there are additional data characteristics that may need to be modified. For example, all of the project feature classes may not have the same spatial reference information. Some may be in different coordinate systems or have different spatial extents. You can use geoprocessing tools to reconcile these differences throughout your project data.
Examples of other refinements to your project data might include:
· Deriving new feature classes from existing ones
· Simplifying feature geometry based on attribute values
· Combining multiple adjacent feature classes into a single feature class
· Assigning domains to feature attributes
Step 3 Add
source data to a project geodatabase
The lynx project source
data provided in the data download is in a variety of formats, including shapefiles, coverages, geodatabase feature classes, and INFO and DBF tables. In
this step, you will use several types of geoprocessing
tools to move all of that data into a project geodatabase.
A. Navigate to the LynxScratch geodatabase
In the Catalog Tree,
navigate to your LynxProject\Data
folder.
In the Data folder, select
LynxScratch.mdb.
At this point, the LynxScratch geodatabase is an
empty workspace.
You are going to use
conversion tools on the data located at the root level of the Prepare folder,
resulting in new output features that will be stored in the LynxScratch
geodatabase.
Eventually,
the data you need for analysis will end up in the LynxHabitat
geodatabase, but now you will be creating a number of
temporary datasets, so you will put them in your scratch workspace.
B. Preview the project
data in ArcCatalog
The Prepare folder
contains the LynxProject folder that you created
earlier and the source datasets that you will use for the lynx project.
The source datasets
include:
There are other
differences between these datasets besides their format. Some have different
spatial extents and coordinate systems. Some contain unnecessary fields.
If
you would like, take a few moments and preview each feature class and table to
familiarize yourself with the original format of the data. In the next step,
you will start the converting data from one format to another.
C. Run a batch
conversion tool
In some cases, you will
want to move several datasets into a geodatabase as a
"batch" operation. The Feature Class to Geodatabase
(multiple) tool allows you to convert many datasets in practically any format
to geodatabase feature and object classes.
In ArcToolbox,
expand the Lynx_Tools toolbox, Double-click Feature Class to Geodatabase
(multiple) to open its dialog box. In the Catalog Tree, expand the LynxProject geodatabase and the
Vegetation feature dataset. Drag and drop StudyArea
from the Catalog Tree into the Input Features text box. Notice you are able to
choose multiple input features with this tool.
Now drag and drop Watersheds
into the Input Features text box.
Finally, drag and drop the
vegetation_east and vegetation_west
feature classes into the Input Features text box.
Drag and drop LynxScratch.mdb
into the Output Geodatabase text box.
When the process is
complete, in the Catalog Tree, expand the LynxScratch
geodatabase and notice that the new feature classes
have been added.
D. Remove unnecessary
fields when converting data
Some datasets may contain
attribute fields that are unnecessary for your purposes. With the Feature Class
To Feature Class tool you can remove those fields during the conversion
process.
In this step, you will
continue to move datasets to the LynxScratch geodatabase, except this time you will eliminate unnecessary
fields during the process.
Double-click the Feature
Class To Feature Class tool in ArcToolbox.
Position the dialog box so
that you can still see the Catalog Tree.
Expand the elevzones coverage and click the polygon
feature class.
Drag and drop polygon
into the Input Features text box.
Drag and drop LynxScratch.mdb
into the Output Location text box.
For Output Feature Class
Name, type Elevation.
In the Field Info
(optional) section, a list of fields for the layer is displayed. By default,
the Visible property for each field is set to TRUE.
In this case, the values
in the ELEVZONE field are codes that
indicate elevation ranges. This information might be useful for the lynx
project. However, the other fields are simply artifacts of the coverage data
type. You do not need to see them in the new output geodatabase
feature type.
Remove all other fields except ELEVZONE.
Click OK to execute the
tool.

Next,
you will use the same conversion method for the polygon feature class in the
landforms coverage, except this time you will also change the name of the
output fields.
E. Change output field
names
Open the Feature Class To
Feature Class tool again.
In the Catalog Tree,
expand the landforms coverage.
For Input Features, add
the polygon feature class for the landforms coverage.
For Output Location, add
the LynxScratch geodatabase.
For Output Feature Class
Name, type Landforms.
Make only the LF_CODE field visible.
With the Feature Class To Feature
Class tool, you can also change the name of fields as you convert the features
from one data type to another.
In the Field Info section,
right click LF_CODE and Rename the
field by typing LandformCode. Press the Enter
key.
Click OK to run the tool.
Now use the Feature Class
To Feature Class tool three more times to convert the RedSquirrel,
RuffedGrouse, and SnowshoeHare
shapefiles in the Prepare workspace to feature
classes in the LynxScratch geodatabase.
Tip: Unlike coverages, which
contain multiple feature classes, shapefiles contain
only one feature class. To convert each of these shapefiles,
drag the shapefile name (e.g. RedSquirrel.shp)
from the Catalog Tree and drop it in the Input Features text box on the Feature
Class To Feature Class tool dialog box.
Make the Output Feature Class Name for each the same as the shapefile
name (RedSquirrel, RuffedGrouse,
and SnowshoeHare).
For these new feature
classes, make only the HABZONE field
visible, remove other fields, but do not change the field name.
When you are finished
converting the three shapefiles, the LynxScratch geodatabase will
contain nine feature classes.

F. Run TableToDomain command
Tables, like feature
classes, can also be converted from different formats to geodatabase
tables (also referred to as object classes).
For the lynx project,
there are four tables in the Prepare workspace. Each table corresponds to one
of the feature classes. These are simple tables, but they have a specific
purpose—each table represents a "look up" table for one of the source
datasets.
For example, both the vegetation_east and vegetation_west
feature classes have a ZONEP field that contains codes representing different
vegetation types, but it is not clear what the code means.
If you previewed the vegcode table, you would notice it has a similar field
named VEGCODE, except that there are also two descriptive fields called TYPE
and REMARKS that help to decipher the code.
You could join the vegcode table with each of the vegetation feature classes
but, for the lynx project, you will do something a little more powerful. You
will build those tables into the LynxHabitat geodatabase, turning them into attribute
domains.
You will start by
converting the Elevation table found in the Prepare folder into a geodatabase domain located in LynxHabitat.gdb.
Open the Command Line
window, in the command line,
start to type the word table.
Scroll down the drop-down
list,
highlight the TableToDomain command
Remember, you added this
tool to the LynxTools_Prepare toolbox in the previous
topic, so it shows up as an option here.
Note: If you did not remove the system toolboxes from ArcToolbox as you were instructed to do in the previous
exercise, two TableToDomain commands will be
displayed in the drop-down list. Choose the one with the management alias (TableToDomain_management).
Press the space bar to add
it to the command line.
The next required
parameter is the name of the in_table.
Type Elevation.dbf
and press the space bar.
Notice that you do not
have to type (or drag and drop) the entire path name. Elevation.dbf
is located in the Prepare folder, which you set as your default current
workspace in the previous exercise; therefore, simply typing the table name is
sufficient.
For code_field,
select ELEVZONE from the drop-down
list that appears and press the space bar.
For description_field,
double-click RANGE.
The next required parameter
for this tool is in_workspace.
You could either drag and
drop the appropriate workspace (LynxHabitat.mdb), or you could type the full
pathname, but that's a lot of typing and prone to error.
Since you are going to use
the same path again in this exercise, why not create a variable
here to save time and prevent error?
G. Create a command line variable
Right-click in the command
line and choose Variables.
In the Variable Manager
dialog box, click the Add button.
Click the first cell under
Name.
Replace Variable0 with LynxHabitatGDB.
Click the cell under Data
Type, scroll down the list, and choose Workspace.
Click the cell under Value
then click the ellipsis button.
In the LynxHabitatGDB
dialog box, click the Browse button and navigate to your Prepare\LynxProject\Data folder.
Click LynxHabitat.mdb
then click Add.
Click OK. The value for
your variable is now defined.
While you are in the
Variable Manager, add another variable with the following properties:
When
you are finished, click OK to close the Variable Manager and continue with the TableToDomain command.
H.
Convert a table into a geodatabase domain
Make sure the command line
cursor is positioned right after the letter E in the word RANGE and then press the space bar.
The two variables, LynxHabitatGDB and LynxScratchGDB,
appear in a drop-down list.
Double-click LynxHabitatGDB to add it to the command and then press the
space bar.
For domain_name,
type ElevationZones.
Press the Enter key to run
the tool.
The
LynxHabitat geodatabase
appears unchanged because the domain is added to the geodatabase
properties behind the scenes. In the last step, you will take a look at the
properties of the LynxHabitat geodatabase,
but first you will convert a few more tables into domains.
I.
Convert the rest of the tables into domains
Recall and modify the
previous command in the Command Line to create three more domains for the LynxHabitat geodatabase from the
following tables:
Use the guide below for
completing the processes.
Table To Domain
in_table
code_field
description_field
in_workspace
domain_name
Habitat.dbf
HabZone
Habitat
LynxHabitatGDB
PreyHabitat
Landforms.dbf
LF_CODE
LANDFORM
LynxHabitatGDB
LandformZones
vegcode
VEGCODE
TYPE
LynxHabitatGDB
VegetationZones
In the Catalog Tree,
right-click the LynxHabitat geodatabase
and choose Properties. Click the Domains tab.
Four domains, ElevationZones, LandformZones, PreyHabitat, and VegetationZones
are now associated with the LynxHabitat geodatabase.
In the next exercise, you
will assign these domains to attribute fields of feature classes that will be
added to the LynxHabitat geodatabase.
At the bottom of the
Database Properties dialog box, you can view the coded values for each domain.
In the next module, you will
see how helpful domain values are when using geoprocessing
tools.
Close
the dialog box.
save your ArcToolbox settings to Lynx_Prepare2.xml to maintain
the variables you created in this step.
Close
ArcCatalog.
Step 4: Get
your data in shape
So far, you have used ArcCatalog to do most of the data preparation work for the
lynx project. You created workspaces and converted source data into geodatabase feature classes. You could have used the same geoprocessing tools in ArcMap.
In this step, you are
going to continue preparing data for analysis, but in ArcMap
so that you can see the results of your geoprocessing.
You will continue to
create intermediate data within a scratch workspace, but towards the end of the
exercise, you will redirect the geoprocessing output
and put your final feature classes in your final workspace, LynxHabitat.mdb.
A. Add LynxScratch features
In this step, you'll add
the feature classes from the LynxScratch geodatabase to the map. Remember, these feature classes are
the intermediate results of the conversion geoprocessing
that you did in the previous exercise.
Click the Add Data button
.
Navigate to your …\Prepare\LynxProject\Data folder. Double-click LynxScratch.mdb.
Add all of the feature
classes.
Right Click Layers
and click turn all layers off.
Now turn on the StudyArea layer.
The StudyArea
layer represents the total geographic extent for the lynx project.
Move
the StudyArea layer below the two vegetation layers
in the Table of Contents.
B. Append feature
classes together
Remember, when you first
read about the lynx project you learned that vegetation is a key factor in
determining potential lynx habitat.
Turn on the vegetation_east and vegetation_west
layers.
Holding down the Shift
key, click each layer to select them both. Make sure they are the only two
layers selected.
With both layers selected,
right-click one of them and choose Zoom to Layers.
The polygons in the two
adjacent layers represent primary vegetation types.
Turn off and on vegetation_east and vegetation_west.
As you can see, you have
vegetation data that covers the same extent as the study area but it is
separated into two feature classes. Analysis that includes the vegetation data
will be easier if there is only one vegetation layer that contained all the
necessary features.
You will use the Append
tool to add features from one feature class to the other.
In Lynx-tools, toolbox,
double-click the Append tool.
In the Append dialog box,
for Input Features, click the drop-down arrow and choose vegetation_east.
The features in this
feature class will be appended to the feature class named in the Output
Features text box. With this tool you could choose several input feature layers
if necessary.
Remember, you can click
Show Help at the bottom of the dialog box if you need help understanding how
the tool works.
For Output Features, choose
vegetation_west from the drop-down list.
This is the layer to which
you are adding features from the Input Features list.
Click OK.
When the process is
complete, click an empty area of the Table of Contents to unselect the
vegetation layers.
Turn off vegetation_east.
You can see that the
features of the vegetation_east layer have been added
to the vegetation_west layer.
Right-click
the vegetation_east layer and choose Remove to delete
it from the Table of Contents. You no longer need it.
C. Dissolve features
Now that you have all the
vegetation features in one feature class, you can clean up the data by removing
any unnecessary boundaries between features with the same attribute values.
In ArcToolbox,
double-click the Dissolve tool.
For Input Features, choose
vegetation_west.
For Output Feature Class,
keep the default setting—a new feature class named vegetation_west_Dissolve
will be created in the LynxScratch geodatabase.
Tip: Remember, you can click the Output Feature Class
text box and arrow to the right or highlight the entire path to see the output
feature class name.
For Dissolve Fields, check
ZONEP.
Click OK.
When the process is
complete, a new layer called vegetation_west_Dissolve
is added to the map.
Remove
the vegetation_west layer from the Table of Contents.
D. Investigate the
spatial reference information for the layers
You probably have not
noticed, but not all of the feature classes in this map share the same
projected coordinate system. This could potentially lead to problems or inconsistent
results during analysis.
In the Table of Contents,
right-click vegetation_west_Dissolve and choose
Properties.
Click the Source tab.
In the Data Source
section, notice that the Projected Coordinate System is
NAD_1927_StatePlane_Washington_South_FIPS_4602 and projection is Lambert
Conformal Conic.
You'll find that the
projected coordinate system and projection is the same for all but two of the
layers. This is the projection and coordinate system you will use for the lynx
project.
Click OK to close the
Layer Properties dialog box.
Now examine the layer
properties for the Elevation and Landforms layers.
Question:
What is the projected coordinate system for the
Elevation and Landforms layers?
To
ensure proper analysis results, you will change the projected coordinate system
for the Elevation and Landforms layers to
NAD_1927_StatePlane_Washington_South_FIPS_4602.
E. Run the Project tool
In Linx_tools
Toolbox, double-click the Project tool.
For Input Dataset or
Feature Class, choose Elevation.
For Output Dataset or
Feature Class, notice that a new feature class named Elevation_Project
is going to be created in the LynxScratch geodatabase.
For Output Coordinate
System, click the Spatial Reference Properties button
.
In the Spatial Reference
Properties dialog box, click Import.
Navigate to LynxScratch.mdb.
You'll use the spatial
reference information from the vegetation_west_Dissolve
feature class. It has the right spatial extent and projected coordinate system
for your project.
Click vegetation_west_Dissolve
and click Add.
Click OK.
Click OK to create a new
projected feature class.
When the process is
complete, a new layer called Elevation_Project is
added to the map.
Remove the original
Elevation layer from the Table of Contents.
Now project the Landforms layer
using the same method. Make sure to import the Spatial Reference from vegetation_west_Dissolve.
When the process is
complete, the Landforms_Project layer is added to the
map.
Remove the original
Landforms layer from the Table of Contents.
Now
all of the layers in the Table of Contents are in the same projected coordinate
system.
F. Create a selected
set
Instead of using the StudyArea layer provided, you are going to create a new
study area for the lynx project. You will use watershed boundaries, which
follow the summit of ridges, hills, and mountains. In this way, the new study
area will be based on recognizable landform features.
First, you will need to select the watersheds.
Turn off all the layers
except the StudyArea and Watersheds layers.
In ArcToolbox,
double-click the Select Layer By Location tool.
You will need to select
watershed features that are completely inside the StudyArea
feature. Note that this tool does not result in a new feature class, but a new
selection.
Try filling out the dialog
box to match below.

Click OK to run the tool.
When the process is
complete, all of the watersheds that are completely within the study area are
selected.
In
the next step, you will create a new feature class from this selected set.
G. Create the new study
area
In this step, you will
perform geoprocessing on the selected features of a
feature class to create a new feature class (the new study area). The new study
area is also the first feature class that is complete and ready to use for
analysis. In other words, you are not creating intermediate data anymore; you
are creating final data. Therefore, you will redirect the geoprocessing
output to the LynxHabitat geodatabase
rather than LynxScratch.
In ArcToolbox, double-click the Dissolve tool.
For Input Features, choose
Watersheds.
This is the feature class
containing the selected features.
For Output Feature Class,
click the Browse button
.
Save the output feature
class in LynxHabitat.mdb and name it StudyArea.
For Dissolve_Field(s),
leave everything unchecked.
Click OK.
When the process is
complete, the new Study Area layer that is based on watershed boundaries is added
to the map.
From the Selection menu,
choose Clear Selected Features.
Turn off the old StudyArea and Watersheds layers to see the new StudyArea layer.
Remove the old,
rectangular StudyArea from the Table of Contents.
You
will use the new StudyArea layer as the boundary for
all of your final data.
H. Reset the geoprocessing environment
In these last few steps of
this exercise, you will finalize the remaining data layers. Like the new StudyArea layer you just created, the final output of the
remaining layers will be directed to the LynxHabitat geodatabase.
To make your geoprocessing easier, you will change your environment
settings. Remember, in the second exercise of this lab, you set the environment
settings so that you could easily move data from the Prepare folder to the LynxScratch geodatabase.
Right-click an empty space
in ArcToolbox and choose Environments.
In the Environment
Settings dialog box, click General Settings to expand it.
For Current Workspace, the
path points to the Prepare folder. Although you will now be working with data
that resides in the LynxScratch geodatabase,
you do not have to bother changing this setting right now. That is because you
are working in ArcMap, so the layers in the Table of
Contents will be displayed in the input drop-down list, no matter what you
designate as your current workspace.
For Scratch Workspace,
click the Browse button.
Navigate to your Prepare\LynxProject\Data folder. Select LynxHabitat.mdb
and click Add.
Remember, the scratch
workspace is the default location into which all automatically generated geoprocessing outputs will be placed.
Click
OK.
I. Clip all of the
project feature classes to the study area
In this step, you will use
the Clip geoprocessing tool and the new StudyArea feature class that you just created to clip all
of the feature classes shown in the Table of Contents to a common boundary.
You will put the new
clipped feature classes in the LynxHabitat geodatabase.
Open the Clip tool dialog
box.
For Input Features, select
Landforms_Project from the drop-down list.
For Clip Features, select StudyArea from the drop-down list.
For Output Feature Class,
keep the default location (LynxHabitat.mdb) but change the default name to Landforms.
(Hint: Just delete _Project_Clip in the output
text box).
Click OK.
When the process is
complete the Landforms layer is added to the map.
Remove Landforms_Project
from the Table of Contents.
Use the table below as a
guide and repeat the clip process for the remaining layers.
After each process is
complete, remove the input feature layers from the Table of Contents.
Clip Table
Input Features
Clip Features
Output Feature Class
Elevation_Project
StudyArea
LynxHabitat.mdb\Elevation
vegetation_west_Dissolve
StudyArea
LynxHabitat.mdb\Vegetation
RedSquirrel
StudyArea
LynxHabitat.mdb\Squirrel
RuffedGrouse
StudyArea
LynxHabitat.mdb\Grouse
SnowshoeHare
StudyArea
LynxHabitat.mdb\Hare
Watersheds
StudyArea
LynxHabitat.mdb\Watersheds
When you are finished, the
Table of Contents should resemble the graphic below.

Take
a moment to look at the new feature classes by turning all of the layers off
and then turning them on one at a time, starting from the bottom of the Table
of Contents.
J. Assign a coded value
domain to a field
Remember the domains that
you created from the four tables in the previous exercise? Now is the time to
put them to work.
First, open the attribute
table for the Hare layer.
Notice the values in the
HABZONE field are numbers, either 0, 1, or 2. These are codes that don't mean
much unless you're very familiar with the data. It would be better if the
meanings of the codes were apparent.
Close the table.
Double-click the Assign
Domain To Field tool in the Lynx_tools toolbox.
For Input Table, choose
Hare.
For Field Name, select
HABZONE.
For Domain Name, choose PreyHabitat.
Click OK.
When the process is
complete, open the attribute table for the Hare
Notice that the HABZONE
field is now populated with the words Core, Peripheral, and Not suitable
instead of numbers.
Close the table.
Using the same method,
assign the PreyHabitat domain to the HABZONE field
for the Grouse and Squirrel layers.
Open the attribute tables
to check your work if you like.
Now run the same process three
more times using the following parameters:
Open the layer attribute
tables to check your work.
Later
in the course you will see how domain values make it easier to make decisions
when designing models and performing analysis.
If you want, save the map
document as Lynx_Propare3.mxd in your module folder.
Close
ArcMap.
At this point, the lynx project data is prepared for the analysis you will do
in the next part. It is stored in one place, is in a common format, and shares
the same spatial extent and coordinate system. Additional modifications that
will make analysis easier have also been made.
In this step, you
performed geoprocessing operations one at a time,
using either the geoprocessing tool dialog box or the
command line. In some cases the output of one process was an intermediate step
that became the input of another process. In the step, you are going to learn
how to string processes together within a model.
In your own GIS project,
you might evaluate the intermediate data, such as the feature classes that are
currently in the LynxScratch geodatabase,
and decide whether or not to keep certain datasets. In the next part, you will
learn how to easily manage intermediate data within your workflow.
Part III: Model builder and Data
Analysis
Analysis allows you to solve problems by examining the geographic patterns in your data and observing relationships between features. The methodology you use to solve problems can be very simple—sometimes just by making a map you're doing analysis—or more complex, involving models that mimic the real world by combining several data layers and processes and discovering the patterns and numbers that result.
Because the ArcGIS® Desktop geoprocessing framework includes ModelBuilder™, it's possible to design and execute even the most complex analyses. Model criteria and methodology can be quickly adjusted, and you can run your model as many times as necessary to test alternative solutions.
In this part, you will get practice using ModelBuilder as you continue working on the lynx project.
Specifically, you will build models to locate potential lynx habitat in
northeastern
![]()
You can use geoprocessing
tools for analyzing your data.
In ArcGIS Desktop, a model is a tool that defines a set of rules and procedures for representing a phenomenon or predicting an outcome. Models consist of one or more processes. In ModelBuilder, models are represented as flow charts with distinct symbols for each type of component. Model components are referred to as elements. Elements are connected by connector lines that serve to create processes as well as show processing flow. Below is a list of the elements you will see in ModelBuilder:
· Tools—the same tools that are in ArcToolbox™ are available for use in models. Tool elements are represented by gold rectangles in ModelBuilder.
· Project data—any data that exists before a tool executes. Project data will typically be used as the input to a tool in a model. Project data elements are represented by blue ovals.
· Derived data—data created by running a geoprocessing operation on existing project data. Derived data from one process can serve as input data for another process. Derived data elements are represented by green ovals.
· Values—reference tool parameters other than datasets; for example, the buffer distance for the Buffer tool. Value elements are represented by light blue ovals.
· Derived values—reference values that are created by running a tool, such as the output value from the Calculate Default Cluster Tolerance tool. You'll work with derived value elements later in this course. Derived value elements are represented by light green ovals.
|
|
|
Models typically contain several processes, and they can be chained together so that the derived output from one process becomes the input for another process. The conceptual model shown here contains three processes. |
Any element in a model that is not a tool is a variable. Variables can be thought of as placeholders for datasets or other tool parameters. Variable values can be easily changed, and they can be shared between processes in a model.
Element states have unique symbology. An element that is not ready to run is white. An element that is ready to run is colored. An element that has been run adds a dropshadow to its color.
|
|
|
The three
states of a process shown from top to bottom are: not ready to run, ready to
run, and has been run. The state of a process depends on the state of its
elements. |
Building models has several advantages, the most
important of which are described below.
Automate the geoprocessing workflow
Models help you manage the complex
combination of assumptions, tools, datasets, and other factors associated with
your analysis. Models can be easily modified so that you can explore
alternative outcomes or accommodate new information. The model updates
dynamically. Changes to one part of the model are automatically carried through
to the rest of the model.
Share geoprocessing knowledge
Models easily communicate what is being done. In the case of ModelBuilder, models are represented as flow charts with
distinct symbols for input data, spatial operations, and output data. The
structure of the model and flow of data processing are apparent. This makes it
easy for you and others to see the model's scope and understand how it works.
Record and document
methodology
Models allow for simple or sophisticated geoprocessing
workflows to be captured and documented. You can document the sources of input
data and assumptions you made in the model for future use or to share your work
with others. You'll learn more about documentation later in this course.
Add complexity as
needed
Models allow you to assemble simple and complex processes into one tool. For
complex processes, you can create a separate model. These "submodels" can be added to primary models, allowing
you to incorporate components developed by experts in various disciplines.
Step 1:
Create a new model
Right click Lynx_tools, ->new-> toolset, rename as working.
Right-click the Working toolset,
point to New, and then click Model to open the ModelBuilder
window.
From the Model menu,
choose Model Properties. Make sure the General tab is active.
For Name, type SimpleLynxHabitat.
For Label, type Simple
Lynx Habitat Model.
The name defines how the
tool will be referenced at the command line and in scripts. Names do not allow
spaces or certain characters such as periods because they are not allowed in
scripts. Labels determine how the model will appear in a toolbox. You can use
spaces and periods in labels to provide a clear explanation of what the model
is for.
For Description, type (or
copy and paste) Finds suitable habitat for lynx based on preferred
vegetation, elevation, and landform.
Check the box to store
relative path names.
Step 2: Apply
environment settings
Environment settings can
either be applied to all tools executed from ArcToolbox
or to an individual model. Since all of your source data is stored in one
location and your output created from this model will be placed in another geodatabase, you will set the Current Workspace and Scratch
Workspace environment settings.
In the Model Properties
dialog box, click the Environments tab.
Expand General Settings
and check the boxes next to Current Workspace and Scratch Workspace.
Click Values.
In the Environment
Settings dialog box, expand General Settings.
For Current Workspace,
navigate to your …\LynxProject\Data folder,
choose LynxHabitat.mdb, and click Add.
For Scratch Workspace,
choose LynxScratch.mdb and click Add.
Click OK to close the
Environment Settings dialog box.
Click OK to close the
Model Properties dialog box.
Notice that the title bar
of the model now reflects the label you added.
Click the Save button
in the
ModelBuilder window.
Now
you are ready to add data and processes to the model.
Step 3: Add
data to the model
Your model will use three
datasets to define suitable lynx habitat: elevation, vegetation, and landforms.
Drag the Elevation layer
from the ArcMap Table of Contents and drop it into
the model. Do the same for the Vegetation and Landforms layers.
Arrange the project data
elements as shown below by clicking each element and, with the mouse button
held down, dragging it to the correct location.

Tip: Elements can be resized to see the full element
name. Click an element to select it and drag its sides until the text is
visible.
Whenever you add data to ModelBuilder, it automatically becomes a variable. This
allows it to be recognized within tool dialog boxes and shared between
processes.
Another
way to add data to a model is by using the Add Data or Tools button
in
ModelBuilder. If you do not have ArcCatalog
open and your project data is not displayed in ArcMap,
this is the method you would use.
Step 4: Add
a process to select preferred elevation
In northeastern
Drag the Select tool from ArcToolbox and drop it into the model as shown below.

You currently have three
data layers and one tool in your model. The white model elements indicate that
you need to give the tool more information in order for it to be ready to run;
specifically, the input and output data parameters.
In the model, double-click
Select.
The dialog box that opens
is the same dialog box that you would see if you opened the Select tool from ArcToolbox.
From the Input Features
drop-down list, click the Elevation variable. Notice that all model variables are preceded with the variable icon
.
For Output Feature Class,
accept the default of Elevation_Select.
Notice that by default the
output feature class will be written to the LynxScratch
geodatabase, the location you specified to be the
scratch workspace earlier in this exercise.
Now you will create an
expression to select those elevation zones that are above 4000 feet.
Click the Query Builder button
.
Double-click the
[ELEVZONE] Field to add it to your query.
Click the >= button.
Now click Get Unique
Values.
You see the values of the
ELEVZONE field. Because you assigned a domain to the ELEVZONE field in the
previous module, you can see its description as well. The use of coded value
domains is especially useful for filling out tool parameters, providing a
friendly description of what a value actually means.
Finally, under Unique
Values, double-click 10 - 4000 - 4200 feet.
Your expression should
read: [ELEVZONE] >= 10
In the Query Builder
dialog box, click OK.
Click OK to close the
Select dialog box.
In the model, the Select
and Elevation_Select elements are now colored in and
in the "ready to run" state.
In the model, right-click
Select and choose Run.
Note: Choosing run for a particular tool will only
execute that single process. You will learn how to run an entire model later in
this exercise.
When the process is
complete, the Elevation_Select feature class is
created. Notice that Select and Elevation_Select have
dropshadows behind them indicating that the process
has been executed.
If you would like to
preview the Elevation_Select feature class,
right-click the Elevation_Select element (in the
model) and choose Add to Display to add the layer to ArcMap.
Notice that Elevation_Select shows only those elevation zones that are
primary to lynx habitat.
When
you are finished previewing Elevation_Select,
right-click the Elevation_Select element again and
uncheck Add to Display to remove it from the Table of Contents.
Step 5: Add
a process to select preferred vegetation
Of the vegetation types
within the study area, those that contribute to primary lynx habitat are red
cedar and subalpine fir. In this step, you will use
the Select tool to extract these vegetation types.
Drag the Select tool from ArcToolbox and drop it into the model as shown below.

You now have two Select
tools in your model. The second select operation is automatically named Select
(2).
Double-click Select (2) to
specify the parameter values for the tool.
Fill out the parameters as
follows:
Input Features: Vegetation
(variable)
Output Feature Class: Accept the default (Vegetation_Select)
Expression: [ZONEP] = 37 OR [ZONEP] = 81
Click OK to close the
Select (2) dialog box.
In the model, right-click
Select (2) and choose Run.
When the process is
complete, preview the Vegetation_Select feature
class.
Vegetation_Select represents the vegetation types most associated
with lynx habitat.
Remove
Vegetation_Select from the display when you are
finished examining it.
Step 6 Add a
process to select preferred landforms
Lynx have a preference for
gentle terrain when available. In this step, you will use the Select tool to
extract gentle landforms such as benches, plateaus, valleys, and gently rolling
ridge tops.
Drag the Select tool into
the model again, as shown below.

This select operation is
automatically named Select (3).
Double-click Select (3) to
specify the parameter values for the tool.
Fill out the parameters as
follows:
Input Features: Landforms
(variable)
Output Feature Class: Accept the default (Landforms_Select)
Expression: [LandformCode] = 35 OR [LandformCode] = 44
Click OK to close the
Select (3) dialog box.
In the model, right-click
Select (3) and choose Run.
When the process is
complete, preview the Landforms_Select feature class.
Landforms_Select represents the landforms most associated with lynx
habitat.
Remove
Landforms_Select from the display when you are
finished examining it.
Step 7: Add
a process to intersect lynx habitat criteria
Now that you have
extracted the elevation, vegetation, and landforms favored by lynx, you're
ready to use these three derived datasets to define lynx habitat.
First, you will use
Intersect to overlay the selected habitat characteristics based on elevation
and vegetation. As its name implies, the Intersect tool calculates the
geometric intersection of any number of feature classes and feature layers. The
features or portion of features that are common to all inputs will be written
to the output feature class.
Drag the Intersect tool
into the model as shown below. If necessary, make the ModelBuilder
window larger so that you can see all of the tools and variables.

In the model, double-click
Intersect to specify its parameter values.
From the Input Features
drop-down list, choose Elevation_Select and then
choose Vegetation_Select.
At the end of the path for
Output Feature Class, change the default name to Criteria_Intersect_1.
Notice that the output
will be saved in the LynxScratch.mdb workspace.
Click OK.
Right-click the Output
Feature Class element and click Rename.
In the Rename dialog box,
type Intersect 1 of habitat criteria.
Click OK.
This will not change the
name on disk, but only how the element is represented in the model and in
dialog boxes. Using the Rename option allows you to assign friendlier, more
helpful names to output elements while maintaining the feature class name you
chose in the dialog box. Element names can contain spaces and special
characters, but feature class names cannot.
Tip: Remember you can resize a model element so that you
can see the entire label.
In ModelBuilder,
click the Auto Layout button
to
organize the model elements. Note: Your model layout might differ
slightly from the following view result graphic.
At this point, you are
only intersecting two of the three habitat criteria.
In the model, right-click
Intersect and choose Run.
When the process is
complete, turn off all the layers in the Table of Contents except StudyArea and then preview Intersect 1 of habitat criteria.
The Criteria_Intersect_1
feature class contains only the area common to the two inputs and represents
predicted lynx habitat.
Remove
the layer from the display when you are finished examining it.
Step 8: Add
a second intersect process to the model
In the previous step, the
overlay analysis using the Intersect tool provided a quick result using only
two variables, selected elevation features and selected vegetation features.
This in itself is an example of a simple suitability model. But what about the
selected landform features?
Add another Intersect tool
to the Simple Lynx Habitat Model.
Double click Intersect (2)
to open the dialog box.
From the Input Features
drop-down list, select Landforms_Select and Intersect
1 of Habitat Criteria.
For Output Feature Class,
change the output feature class name to Criteria_Intersect_2.
Click OK.
In the model, right-click
the Output Feature Class element for Intersect (2) and choose Rename.
In the Rename dialog box,
type Intersect 2 of habitat criteria, and click OK.
Click the Auto Layout button
,
then click the Full View button
.
Now right-click Intersect
(2) and choose Run.
When the process is
complete, preview the result in ArcMap.
Remove
the layer from the display when you are finished examining it.
Step 9: Add a process to dissolve
unnecessary polygons
In the previous step, you
probably noticed that the output of this model has many adjacent polygons that
could be merged together. For your preliminary analysis, you do not need any of
the individual attributes of the polygons—your only concern is that the area
may contribute to lynx habitat. To simplify matters, you will merge all the
individual polygons together using the Dissolve tool. You will save the final
output of the model in your LynxHabitat geodatabase.
Drag the Dissolve tool
into the model.
Double-click the Dissolve
element to fill out its parameter values.
For Input Features, choose
Intersect 2 of habitat criteria.
For Output Feature Class,
highlight the existing path, and replace it with SimpleHabitat.
Tip: You can highlight the entire path by placing your
cursor anywhere in the line and double-clicking.
On your keyboard, press
the Tab key.
Notice that the output
feature class will be sent to your LynxHabitat geodatabase, instead of the LynxScratch
geodatabase. Because you designated LynxHabitat.mdb
as your current workspace in the model's environment settings, you can just
type the name of the feature class as a shortcut.
Click OK.
Click the Auto Layout button
,
then the Full View button
.
Rename the SimpleHabitat element Simple Lynx Habitat.
This is your final output
for the model. In the next step, you will delete your intermediate
data in one easy step. But first, it is important to designate Simple Lynx
Habitat as your final output rather than intermediate data, so it does not get
deleted.
Right-click the Simple
Lynx Habitat element and uncheck Intermediate.
Click
the Save button
.
Step 10: Run
the model
You could run the Dissolve
process by itself as you did for the other processes, but this time you will
run the entire model at once. Once a process has run successfully, it will not
run again.
To see all of the model processes run, you need to
delete the intermediate data.
From the Model menu,
choose Delete Intermediate Data.
If necessary, click the
Full View button
to
see all of the processes in your model then click the Auto Layout button
to
organize the model.
Now click the Run button
.
Notice that as the model
executes, the current process is highlighted in red. Once all of the processes
have completed, the entire model has been executed.
After the model has run,
preview Simple Lynx Habitat.
If necessary, turn off the
Elevation, Vegetation, and Landforms layers to help you better see the results.
Your
model results in a map depicting areas that include the elevation, vegetation,
and landforms that define lynx habitat.
Step 11:
Save the model and map document
Again, from the Model
menu, choose Delete Intermediate Data.
Click the Save button
.
Close your model.
If you want, save the map
document as LynxSimple2.mxd in your module folder.
If you are continuing to
the next topic, keep ArcMap open. Otherwise, close ArcMap.
Part IV: Create Scripts
in Model
Scripts
are similar to models in that they allow you to chain processes together and
run those processes in a certain order. Also like models, scripts can be used
to build functionality that might not be available from the system tools in ArcGIS® Desktop. For example,
Even if you never write a
line of code yourself, you may want to use scripts that others have written.
Keep in mind that with the proper licenses and extensions, you can execute any
of the system tools from a script. For this reason, you should be able to
recognize some of the basic elements in a geoprocessing
script, such as comments, standard code, script arguments, environment settings,
and tools.
Comments
In Python, any line of code preceded by one or many number signs (#) is a
comment. When you run a script, comments are ignored, and only the uncommented
lines of code execute.
Standard code
A Python script that uses geoprocessing
functionality, must, at minimum, start with the following two lines of code:
import win32com.client
and gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
Script arguments
Also called system arguments, this code allows users to interact with
the script and specify values for variables like output workspaces.
Environment setting
A setting that applies to all processes run by a script, such as the default
workspace as you set in part I and part II.
Tools
Any system tool can be run from a script by specifying the tool name plus the
toolbox alias and the tools parameters.
You can run a script as a standalone operation or
you can add a script to a toolbox and then run the script from its dialog box
or incorporate it into a model.
Running a script as a standalone operation means
that you can accomplish geoprocessing without ever
opening an ArcGIS Desktop application. For example,
you can run scripts from within a script editor, like Pythonwin,
or from the command prompt.
To run a geoprocessing
script as a standalone operation, you should make sure you or the person you
are sharing the script with has:
1.
An available
license to use ArcGIS Desktop
2.
A license to
use the geoprocessing tools in the script
3.
Python
installed (if you're using a Python script)
4.
Access to any
data and workspace referenced in the script
If you want to run a script from within an ArcGIS Desktop application, like a system tool, or use it
in a model, you must first add it to a toolbox and make it a script tool.
Step 1: Add
the script to a toolbox
In the ArcCatalog Catalog
Tree, …\Prepare\LynxProject\tools, right click folder
“tools”->new->toolbox, name the new toolbox as Scripts_tools.
Right click Script_tools->Add->
Script.
On the first panel of the Add Script wizard, for
Name, type ClipAll, and for Label, type Clip
All Feature Classes.
Note: Spaces
or certain characters such as periods are not allowed in script tool names, but
they are allowed in labels, which determine how the script will appear in a
toolbox.
Copy the following description and paste it into
the Description text box: This script tool clips all feature classes in a
workspace and puts the resulting feature classes in another workspace.
Check the box next to Store relative path names.
Click Next.
On the second panel, click the Browse button
and navigate to
your …\start folder. Select ClipAll.py
and click Open. You already run this scripts in part I. Now you will add it
into your tool box by yourself.
Click Next in the Add Script wizard.
The third panel is where you will specify the three
tool parameters—the three text boxes that you or another user see when you run
the tool. The parameters are dictated by the script; you will use this panel of
the wizard to tell ArcGIS what they are.
Click the cell beneath Display Name and type Input
Workspace. This is the text that the user will see above the text box.
Click the cell beneath Data Type and choose
Workspace from the drop-down list. This determines which type of data will be
accepted for the parameter.
Under Parameter Properties, default values have
automatically been provided for three of the properties. The default values are
correct in this case—the user must fill in this parameter (Type: Required); the
parameter is used to provide input for the process (Direction: Input); and the
parameter cannot accept multiple values (MultiValue:
No).
Now add the second parameter. Under Display Name,
type Clip Feature Class. For Display Type, choose Feature Class. Accept
the default parameter properties.
Finally, add the third parameter. Under Display
Name, type Output Workspace. For Display Type, choose Workspace. Accept
the default parameter properties.
Note: It
may seem confusing initially that the Direction is specified as
"Input" for the Output Workspace. When you are specifying parameter
properties, input is any data that already exists. Output data is any data that
gets created as a result of the tool being run. If you were to choose Output,
the script would expect to create a new workspace. However, in this case, you
are asking the user to specify an existing workspace. In other words, the
existing output workspace is chosen through user input.
Click Finish.
The new script tool is added to the Script_tools toolbox. Expand the toolbox to see the new
tool. This script tool can be used like any other tool.
It is important to understand that the Script Tool
wizard and the script are independent of one another. The wizard does not
"know" which input and outputs the script requires. If you provide it
with incorrect information (in other words, information that conflicts with the
code in the script), the tool will either not work at all, or will not work
correctly.
Step 2: export a model to scripts
In the Catalog Tree, navigate to your …\Start
folder and expand the CentralFlorida geodatabase. Right-click SelectAndBuffer
model and choose Edit
In the model builder window, click
model->export->to script->Python,
and save the scripts to your …\tools folder as Select&buffer.
Right-click the …\tool folder and choose Refresh to
see the script file.
If you can not see the scripts in the catalog
window, go to explore window->…\tool folder, right click Select&Buffer.py->edit.
Then the pythonwin or pythoncell
window open, and you can check the scripts.
Take a minute to compare the script to the model it
was created from.
You should be able to identify the four variables
(shown as script arguments and local variables) and the two tools or processes.
Then you will add this script to the script_tools toolbox like you do in the first step.
Right-click the Script_tools
toolbox, point to Add, and choose Script.
In the Add Script wizard, name the tool selec&Buffer and label it select and buffer.
Check the box next to Store relative path names.
Click Next.
On the second panel, add the Select&Buffer
script from the …\tool folder.
Click Next.
On the third panel of the wizard, you will set up
the three parameters—one for each of the script arguments, in the same order
that they appear in the script. If you want, you can refer back to the script
in PythonWin to remind yourself about the order of
the arguments and how they are used.
After you add it into toolbox, you can run it like
a model.
If you like, you can add a scripts into a model,
and combine the scripts and model together to finish automatically batch
process.