Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

• Code – Instructions for a computer

• Programming/Coding – writing, documenting, and


testing code
• Program – A file with instructions for a computer to
execute to complete a task
• Application – A program with a graphic user
interface (as opposed to a command line interface)
• Library – A file with code for a computer to be used
by other programs

 Broadly speaking, ArcPy is organized in tools,


environments, functions, classes, and modules

Debugging ArcGIS Tools You are about to learn how to


create Tools for ArcGIS based on Python scripts. One of
the challenges with this is that there is no "Debug I/O"
window within ArcGIS to help us in debugging the scripts.
There are a number of approaches to help with
debugging:
 Outputting messages to the result dialog with
o arcpy.AddMessage("Put the message here")
 Developing code outside of ArcGIS (turning of the
interface code)
 Using Python dialog boxes to output messages
 Writing to a log file

import tkMessageBox # import the message box module


# before showing the dialog box, we'll want to turn off
the rest of the GUI import Tkinter # import the GUI
package root=Tkinter.Tk() # get the root object of the
GUI root.withdraw() # turn off the typical modeless
window in the GUI tkMessageBox.showinfo("Dialog
Title","Message within the dialog") # show the dialog box

Term Description

Python is an open-source programming


language that was conceived in the late
1980s by Guido van Rossum and introduced
in 1991. It was first incorporated with
ArcGIS 9.0 and has since become the
preferred choice for users creating
Python geoprocessing workflows.

Python is supported by a growing and


varied user community and provides easy
readability, clean syntax, dynamic typing,
and an extensive collection of standard and
third-party libraries.

ArcPy ArcPy (often referred to as the ArcPy site


package) provides Python access for all
geoprocessing tools, including extensions,
as well as a wide variety of useful functions
and classes for working with and
interrogating GIS data. Using Python and
Term Description

ArcPy, you can develop an infinite number


of useful programs that operate on
geographic data.

A module is a Python file that generally


includes functions and classes. ArcPy is
supported by a series of modules, including
ArcPy
a data access module (arcpy.da), mapping
modules module (arcpy.mapping), an ArcGIS Spatial
Analyst module (arcpy.sa), and an ArcGIS
Network Analyst module (arcpy.na).

ArcPy A class is analogous to an architectural


classes blueprint. The blueprint provides the
framework for how to create something.
Classes can be used to create objects,
often referred to as an instance. ArcPy
classes, such as
the SpatialReference and Extent classes
, are often used as shortcuts to complete
geoprocessing tool parameters that would
Term Description

otherwise have a more complicated string


equivalent.

A function is a defined bit of


functionality that does a specific task
and can be incorporated into a larger
program.

In ArcPy, all geoprocessing tools are


provided as functions, but not all functions
ArcPy are geoprocessing tools. In addition to
functions tools, ArcPy provides a number of functions
to better support geoprocessing Python
workflows. Functions (often referred to as
methods) can be used to list certain
datasets, retrieve a dataset's properties,
validate a table name before adding it to a
geodatabase, or perform many other useful
scripting tasks.

Stand-alone A stand-alone Python script is a .py file that


Python script
can be executed from the operating system
Term Description

prompt, a Python Integrated Development


Environment (IDE), or by double-clicking
the .py file in Windows Explorer.

A Python script tool is a Python script that


has been added to a geoprocessing
toolbox. Once added as a script tool, the
Python
script tool becomes like any other
script
geoprocessing tool—it can be opened and
tool executed from the tool dialog box, used in
the Python window and ModelBuilder, and
called from other scripts and script tools.

Python The Python window is a quick and


window convenient place to use Python from within
ArcGIS to interactively run geoprocessing
tools and functionality as well as take
advantage of other Python modules and
libraries. This window also provides a
gateway for you to learn Python.

The Python window can be used to execute


Term Description

a single line of Python code, with the


resulting messages printed to the window.
It is a useful place to experiment with syntax
and work with short lengths of code and
provides an opportunity to test your ideas
outside a larger script.

Python add-in A Python add-in is a customization written


in Python, such as a collection of tools on a
toolbar, that plugs into an ArcGIS
Desktop application that provides
supplemental functionality for
accomplishing custom tasks. To clarify the
development of Python add-ins, you must
download and use the Python Add-In
Wizard to declare the type of
customization. The wizard will generate all
the required files necessary for the add-in
to work. Click here to download the Python
Add-In Wizard from the Geoprocessing
Term Description

Resource Center.

Python toolboxes are geoprocessing


toolboxes that are created entirely in
Python. A Python toolbox and the tools
contained within look, act, and work just
Python like toolboxes and tools created in any
toolbox other way.

A Python toolbox (.pyt) is an ASCII-based


file that defines a toolbox and one or more
tools.

---------------------------------------------------------------------

arcpy.Buffer_analysis("c:/data/
Portland.gdb/streets",
"c:/data/Portland.gdb/steets_buffer",
"500 METERS")

import arcpy
arcpy.AddField_management("c:/data/
Portland.gdb/streets", "LENGTH_MILES",
"TEXT")

arcpy.CalculateField_management("c:/
data/Portland.gdb/streets",
"LENGTH_MILES", "!
shape.length@miles!", "PYTHON_9.3")

arcpy.FeatureClassToFeatureClass_conve
rsion("c:/data/Portland.gdb/streets",
"Database
Connections/MySDE.sde/PortlandDataset"
, "streets")

>> result =
arcpy.Buffer_analysis("rivers",
"riverBuf", "50 METERS")
>>> print result
C:\Portland\Portland_OR.gdb\riverBuf
>>> arcpy.Clip_analysis("streets",
result, "streets_50m_of_rivers")
Return the number of features.
>>> result =
arcpy.GetCount_management("streets_50m
_of_rivers")
>>> print result.getOutput(0)
54

pythonaddins.GPToolDialog(r"C:\Temp\
>>>
Process\BL\Python\GOTOOL\
TESTING.tbx","Script")
>>>

You might also like