Scripting Arcgis
Scripting Arcgis
And other ways of streamlining your workflow Tom Schwartzman ESRI Boston July 13, 2005
Goals
Learn about:
Geoprocessing (automation) Scripting (automation) Customizing
Expectations
Were not going write code today We will look at some samples and learn how to install them This is basic/intermediate user-level
Geoprocessing Framework
Tools Commands Models Scripts Analysis platform Flexible Extendable
ArcToolbox
A dockable window in ArcMap and ArcCatalog
ArcToolbox
Can create your own toolboxes
Store on disk or in a geodatabase Holds tools and models Can be shared with others
Using Modelbuilder
Models are created in the Modelbuilder window Color coded by object type
Data Tool Result
Modelbuilder Functionality
Models can be made flexible with parameters that can be input at run time Variables can hold user defined constants Tests of conditions can be used for branching Preconditions can be set on processes Models can call other Models
Adding Data
Add feature classes to model
Drag and Drop Add from file system Add Layer from ArcMap
Adding Tools
Add tools to model
Drag and Drop from Toolbox
Connect pieces
Model Parameters
Data and variables can be used as model parameters
Data to be input at run time Data to be output at the end to another destination
Scripts cannot then be exported back to models Modified Script can then be added as a Script Tool in a toolbox
Introduction to Python
Free and powerful scripting language Can do many tasks in addition to working with the geoprocessing (gp) framework Python Page http://www.python.org Microsoft Page http://www.microsoft.com/technet/scriptcenter/sc ripts/python/default.mspx contains list of Windows samples scripts Easy to learn, simple syntax Lots of good books out there
OReilly Press: Learning Python good for beginners OReilly Press: Programming Python good reference Interactive execution window: PythonWin Basic development environment: IDLE Widely accepted scripting language
Offers IDEs with debugging tools Modular, can be broken apart Cross platform Ability to compile scripts Installed with ArcGIS 9 and ESRI samples provided
PythonWin and IDLE come with the installation Samples use PythonWin
Toolbars
Change locations of buttons/tools, delete/add buttons/tools Create your own toolbar with your choice of buttons/tools Available by using Customize dialog
Tools Customize Double-click in empty area of toolbar Right-click and choose Customize
Toolbars contd
Toolbars
Lots of useful buttons/tools exist but are not on any toolbar. Examples:
Clear Selected Zoom to Selected Continuous Zoom
Samples
Lots of samples out there from:
ESRI (Developer Kit CD, online http://edn.esri.com) Users (http://arcscripts.esri.com)
Some are VBA scripts (pasted into VBA editor in ArcMap) and run from a button-click
Samples
Some are simply added using Add from file in the Customize Dialog
Samples
Some come with an installer of some sort (batch file, exe, etc) And some need more help getting registered.
Regsvr32.exe to register the compiled .dll with the system Categories.exe to tell ArcGIS what part of the system it belongs in (e.g. sketch tool, renderer, etc)
Templates
Predefined map layouts that can be imported into your current doc Your layout will change to match the template
You may lose/gain elements (legend, north arrow, etc) You wont lose data
Training
Instructor Led:
Intro to ArcObjects: Aug 15-19 Intro to Python: Sep 8-9
Virtual Campus:
Customizing ArcGIS 9 Customizing ArcMap Exploring VBA Working with Forms in VBA Working with Variables and Functions in VBA
Training
Instructor Led:
Intro to ArcObjects: Aug 15-19 Intro to Python: Sep 8-9
Virtual Campus:
Customizing ArcGIS 9 Customizing ArcMap Exploring VBA Working with Forms in VBA Working with Variables and Functions in VBA Getting Started with Scripting (free)