Escolar Documentos
Profissional Documentos
Cultura Documentos
• Try…except statement:
try:
# Write the code here (i.e. the steps in the code that may result
# in errors). Some people put all their code here.
except:
# If the code in the try block creates and error, Python will not
# handle the error, and will instead skip to the except block.
# Here, in the except, block you can write code to determine how
# to handle the error.
Example Code: Try…Except statement
# Set variables for the arguments
input = sys.argv[1]
output = sys.argv[2]
0
1
4
5
Example Code: Parsing GetMessage() Method
# Set variables for the arguments
input = sys.argv[1]
output = sys.argv[2]
• Advisable to
create the new
Toolbox in
ArcCatalog, within
the folder you wish
to put the toolbox
(e.g. Lesson7).
• The toolbox is a
file with a .tbx
extension
• Give it a name
starting with ‘Z’ so
that is goes to the
bottom.
Review: Adding Scripts as Tools in ArcToolbox
1
Documentation Editor:
Documentation Editor:
Paragraph
Bullets
Hyperlink
Image
Subsection
Indent
Delete
Documentation Editor:
Documentation Editor:
Documentation Editor:
Accessing Help
Documentation:
Lesson 7d: Transporting Toolboxes with scripts
/* start Grid
grid
/********************************************************************
&routine calc_slope
/********************************************************************
&type Calculating degree slope as integer...
xxslp_int = int(slope(%grd%, degree))
&type Reclassifying final slope factor grid...
xxslp_fact = reclass(xxslp_int, %textfilepath%/slp_reclass.txt, nodata)
&type ****************************
&type Done with slope factor grid!
&type ****************************
&return
/********************************************************************
&routine calc_aspect
/********************************************************************
&type Calculating aspect as integer...
xxasp_int = int(aspect(%grd%))
&type Reclassifying aspect...
xxasp_rcl = reclass(xxasp_int, %textfilepath%/asp_reclass.txt, nodata)
.
.
.
Assignment for Lesson 7
• There are two options for this week’s assignment.
• Option 1: Write a script that can be used to determine the length
of hiking trails that are within the viewshed of each nestsite in a
dataset. The script should have error checking, and should have
arguments for the required datasets. Turn in the script as a tool in
a toolbox.
• Option 2: Write a script that can be used to read-in a list of x,y
coordinates; from that list of x,y coordinates, create a new
shapefile with square polygons centered on the x,y coordinate
pair. The size of the polygons should be 200 m x 200 m. The
script should have error checking, and should have arguments for
the required datasets. Turn in the script as a tool in a toolbox.
• You are free to do both options, but are required to do only one.