Download presentation
Presentation is loading. Please wait.
Published byRoxanne Ford Modified over 9 years ago
2
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Introduction to Geoprocessing in ArcGIS 9 Jason Grootens ESRI-Minneapolis
3
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-2 Workshop objectives Introduce Geoprocessing at ArcGIS 9: New Framework Dialogs (Tools) Modelbuilder Command Line Scripting Ask questions and participate in discussions
4
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-3 What is ArcGIS? ArcGIS clients Application/Data servers ArcGIS Desktop EXTENSIONSEXTENSIONS ArcGIS Engine Components ArcObjects ArcReader ArcView ArcInfo ArcEditor Custom application RDBMS ArcSDE ArcGIS Server ArcIMS EXTENSIONSEXTENSIONS ArcPad Network Web browser
5
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-4 What is geoprocessing? Perform a variety of geographic based tasks Spatial Analysis Conversion Projections Data Management Database CAD GDB Proximity?
6
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-5 Geoprocessing answers spatial questions What is the fastest route over rugged terrain? How many people are within a contamination zone? What is the closest fire hydrant to each building? Where is the best location for a store? Census Block Groups Distance to Roads Land Cost Distance to competitors
7
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-6 Geoprocessing in ArcGIS ArcGIS 9 enhances geoprocessing Hundreds of tools available Wide variety of methods for accessing geoprocessing tools Geoprocessing is what makes a GIS
8
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-7 Geoprocessing at ArcGIS 9 Geoprocessing available with ArcGIS 9 Command Line Models Scripts
9
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-8 Accessing the ArcToolbox window A dockable window with toolboxes Obtained in ArcMap, ArcCatalog, ArcGlobe, or ArcScene Tree view in ArcCatalog No longer a separate application
10
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-9 Toolsets and tools Toolbox: Container for tools and toolsets Toolset: Logical container of tools and other toolsets Tool: Single geoprocessing operation System tool, model, script, custom built tool All tools look and act the same Toolbox Toolset Tool
11
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-10 Executing tools Double-click any tool to specify parameters Messages appear in progress dialogs and Command Line window
12
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-11 Overview of toolboxes Core toolbox Analysis Geoprocessing for feature classes Conversion CAD tools, conversion tools Data Management Field and workspace tools Coverage – *Workstation install Geoprocessing for coverages Linear Referencing Creating routes, locations Geocoding Building locators, table matching Cartography Masking annotation, features Spatial Statistics Analyzing patterns, distributions Core toolbox Analysis Geoprocessing for feature classes Conversion CAD tools, conversion tools Data Management Field and workspace tools Coverage – *Workstation install Geoprocessing for coverages Linear Referencing Creating routes, locations Geocoding Building locators, table matching Cartography Masking annotation, features Spatial Statistics Analyzing patterns, distributions Extensions 3D Analyst TIN tools Geostatistical Analyst Convert to GRID tool Spatial Analyst All tools currently in Spatial Analyst Extensions 3D Analyst TIN tools Geostatistical Analyst Convert to GRID tool Spatial Analyst All tools currently in Spatial Analyst *Ability to create your own toolboxes
13
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-12 Tools and licensing Ability to use ArcToolbox, command line, models, scripts included at all license levels The amount of tools vary depending on license/extensions ArcView = 102 tools ArcEditor = 104 tools ArcInfo = 251 tools Spatial Analyst extension = 158 tools 3D Analyst extension = 45 tools Geostatistical Analyst = 1 tool Total of 455 tools with ArcInfo and all extensions
14
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-13 Toolbox tabs Favorites Most frequently used tools Index Alphabetical listing of all tools Search Search tools by name or keyword
15
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-14 Supported data types At ArcGIS 8.x, ArcToolbox worked primarily with coverages At ArcGIS 9, ArcToolbox works with all data types used in ArcGIS CAD Coverage Geodatabase Shapefile Raster Tables Geoprocessing Layer files Behavior
16
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-15 Accessing geoprocessing functionality Command Line Simple execution Shortcut to tools Command Line Simple execution Shortcut to tools Scripts Batch processing Branching Scripts Batch processing Branching ArcToolbox Execute as dialogs Simple operations ArcToolbox Execute as dialogs Simple operations ArcObjects Use tools with ArcObjects ArcObjects Use tools with ArcObjects Model Builder Graphical Documentation Chain tools into one process Model Builder Graphical Documentation Chain tools into one process
17
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-16 Creating your own toolbox Used to store models, scripts, custom tools, or a shortcut to frequently used tools My Toolboxes Created in ArcToolbox or Catalog Tree Stored as.tbx in user profile Folder Created in Catalog Tree Stored as.tbx in folder Geodatabase (personal or enterprise) Created in Catalog Tree Stored as table in GDB Stored as.TBX file Stored in geodatabase
18
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-17 Creating your own tools Three ways of creating a tool ModelBuilder Script Custom-built tool with ArcObjects All tools act and behave the same Execute as a dialog Accessing documentation
19
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-18 Using and creating models Drag and drop environment Allows processing of multiple tools at once Documentation of process Easy-to-change parameters and re-execute model Project dataToolDerived data
20
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-19 Using and creating tools with scripts Use any language with a COM interpreter Python, VBScript, JScript, Perl Geoprocessor also accessible in programming languages VBA, VB, C#, etc Batch processing Branching based upon conditions Delayed processing Can run outside of ArcGIS #For each shapefile in the list fc = fcs.next() while fc: outname = outworkspace + "\\" + fc #Clip each feature class in the list #Give output fc the name of the input gp.Clip_analysis(fc, clipfc, outname) fc = fcs.next() #For each shapefile in the list fc = fcs.next() while fc: outname = outworkspace + "\\" + fc #Clip each feature class in the list #Give output fc the name of the input gp.Clip_analysis(fc, clipfc, outname) fc = fcs.next()
21
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-20 Using tools at the command line Run a tool from the interface without a dialog Shortcut for advanced users Similar to ArcInfo Workstation Clip_analysis Clip_analysis county_censusblocks citylimit city_censusblocks
22
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-21 Using and creating tools with ArcObjects All geoprocessing tools can be called as COM components Create custom tools (.dll) Geoprocessing Object Model Diagram
23
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-22 Environment Settings Common parameters that can be applied to many tools within a geoprocessing session Settings persist through all tools (models, scripts, custom tools) Geodatabase settings X/Y Domain Precision Geodatabase settings X/Y Domain Precision Geodatabase raster Statistics Compression Geodatabase raster Statistics Compression General settings Current workspace Output spatial reference Extent General settings Current workspace Output spatial reference Extent Raster settings Cell size Mask Raster settings Cell size Mask
24
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-23 Saving environment settings Where environment settings get saved Normal.gxt for ArcCatalog A map document (.mxd) or template (.mxt) Save settings into an XML file to load into other sessions Favorites tab Environment settings Command line variables Save settings to default
25
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Using ArcGIS 9 ModelBuilder
26
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-25 Modeling spatial problems Models help understand and solve complex problems Models simplify reality Models combine geographic layers to answer questions Where should we build our next store? Reality GIS layers Suitability for store Model criteria: - Zoned commercial - Near target population - Away from competition
27
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-26 Types of models Repetitive tasks Minimize grunt work Efficiently execute a series of frequently used tools Suitability models Use to find best location (businesses, vineyards, evacuation centers) Process models Show the landscape as conditions change (fire spreads, rivers flood, oil slicks move) Best store location Filling a reservoir GIS data layers
28
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-27 Why use ModelBuilder? Fast analysis; efficient processing Re-execute the same model, slightly changing parameters to see how end results differ Complex models Graphical documentation of work Project dataToolDerived data
29
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-28 Using ModelBuilder Obtained from a toolbox Create new models in your own toolboxes All tools within ArcToolbox can be used in ModelBuilder Existing model
30
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-29 Model elements Project data: Data that exists before model is run Blue oval Tool: Operation performed on input data Yellow-orange rectangle Derived Data: Output data created by a function Green oval Process: Set of elements Run one process at a time or all at once Process Model Project data Project data Tool Derived data
31
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-30 Adding model elements Drag and drop from ArcCatalog or ArcMap Tools from ArcToolbox Data Add empty variables Supply data source at a later time
32
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-31 Tools within a model Right-click or double-click to obtain parameters Same dialog as tools from a toolbox
33
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-32 Three states of model elements Not ready to run: Parameters not defined Ready to run: All elements colored Already run: All elements colored and shadowed Not Ready to Run Ready to Run Already Run
34
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-33 How to execute models Entire model from ModelBuilder Can execute one process at a time from ModelBuilder As a tool dialog
35
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-34 Parameters Input/Output data and values for a tool Used for running model as dialog Right-click model element and choose to create parameter Data and location Buffer distance Cell size Output name and location Input data Project Data Function Derived Data Project dataToolDerived data
36
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-35 Running models All parameters created in model appear in model dialog
37
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-36 Validating a model Validating a model Returns model elements to ready-to-run or not ready-to-run states Validate to determine if model is invalid Invalid models Parameter values no longer valid (referencing non-existent data) Tools referenced no longer exist COM tool inside the model is unregistered
38
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-37 Intermediate data You determine which derived data elements are intermediate Can delete after model has been executed Save disk space Roads Land use Buffer Select Roads buffer Suitable sites Erase Best sites Intermediate data
39
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-38 Navigating the model Auto Layout Navigate tool Add Connection
40
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-39 Model diagram properties Use grids for better control in placing elements Change flow orientation Change the color, shape, and font
41
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-40 Adding labels Give the model canvas more detail Diagram labels Free floating labels Element labels Maintain position relative to model element Connector labels (tool or data) Maintain position relative to connector
42
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-41 Exporting models Export to a graphic Export as.bmp,.jpg,.emf Useful for placing in map layouts Printing models Add borders, captions, page numbers
43
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-42 Tool documentation Ability to edit documentation for tools and toolboxes Documentation built into ArcGIS online help system Ability to create metadata Useful for Metadata server
44
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-43 Model Report XML document available for viewing or creation Useful for historical view of processes executed Holds information on Variables Processes Messages Time and date of execution
45
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-44 Saving and sharing models Model is saved to.tbx file or geodatabase Give others.tbx or geodatabase to share model Set parameters if used with different data Export model as a script Windows Explorer
46
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-45 Example Model Find suitable area for airport based upon available land and distance from existing airports
47
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 ModelBuilder Demo
48
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Using the Command Line window
49
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-48 Command Line window Available in all ArcGIS applications Holds messaging for all tools executed Similar interface to ArcInfo Workstation Commands and arguments may be different ArcInfo Workstation 7.x ArcGIS 9
50
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-49 Why use command line? Saves time if familiar with geoprocessing tools Allows you to obtain quick view of all tools available Execute scripts and models Shortcut to tools in ArcToolbox
51
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-50 What can be accomplished at command line? Executing tools select soils48 C:\undrained.shp "OTHERPH" = 'UNDRAINED' Environment settings CellSize 50 Workspace C:\Arc9output\OrangeCounty.mdb Create variables
52
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-51 Syntax notation Similar to ArcInfo Workstation and Spatial Analyst ToolName {Argument} {KEYWORD|KEYWORD} RequiredOptionalOptional Keywords First optional keyword will be taken as default Use # to skip arguments Allows multi-line commands Shift + Enter
53
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-52 Passing in parameters Usage appears showing all parameters Dropdown list shows available layers in ArcMap TOC Type in name of command and press Enter Usage appears in Command Line window
54
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-53 Messages Successful completion of a tool Includes Start and End Time Errors (red font) Indicates a tool did not execute Warnings (green font) Indicates that a step may have been skipped; gives usage
55
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-54 Editing and re-executing existing processes Allows to edit parameters or re-execute without changing If source of layers changes Change a parameter (buffer distance) Edits are made (new features added) Selection changes *Can also use up and down arrows on keyboard for previous commands
56
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-55 Adding a toolbox to ArcToolbox Only tools in ArcToolbox recognized in command line In ArcToolbox Browse for toolboxes In ArcCatalog Add any toolbox by right-clicking Copy and paste into ArcToolbox
57
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-56 Variable manager Make variables for parameters Data and workspaces Expressions Reclassification Spatial reference
58
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-57 Accessing data and tools Some tools can have the same name ToolName_ToolboxAlias Buffer_analysis infeatures outfeatures or Buffer_arc infeatures outfeatures Core Toolbox Analysis = Analysis Conversion = Conversion Data Management = Management Coverage = Arc Geocoding = Geocoding Core Toolbox Analysis = Analysis Conversion = Conversion Data Management = Management Coverage = Arc Geocoding = Geocoding Extensions 3D Analyst = 3D Spatial Analyst = SA Extensions 3D Analyst = 3D Spatial Analyst = SA
59
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-58 Adding a toolbox alias Add aliases to your toolboxes
60
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-59 Executing a model from command line Toolbox containing model must be in ArcToolbox Execute model by calling model name, not the label
61
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Command Line Demo
62
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Scripting and the Geoprocessor
63
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-62 Why write scripts for geoprocessing? Similar advantages that models have Efficiently execute series of different tasks Easy to read and document Easy to share Perform batch operations Use logic to control tool execution Interface with other systems Self contained (single file) Run any time Familiar environment for AML and Avenue users Users don’t have to learn a proprietary language
64
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-63 GpDispatch An ArcObject accessible in all COM languages/scripts Also referred to as the Geoprocessor Exposes all geoprocessing functionality Object is late-bound (no code completion) VBScript JScript Python Communication through IGPDispatch Programming Languages Geoprocessor Access to all geoprocessing tools Buffer Clip AddField
65
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-64 Where to write scripts? Choice of scripting languages: Any language with a COM interpreter VBScript Based on VB: Simpler Popular Web language JScript Syntax similar to C/Java Works in many Web browsers Python Flexible, powerful Easy to learn Perl and other scripting languages
66
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-65 Why use Python? Flexible, easy scripting language Object-oriented Ability to compile scripts Offers a debugging environment Modular: Can be broken apart Cross platform Works in many Web browsers It is FREE ESRI samples provided Python script Python script
67
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-66 Installing Python for geoprocessing (Windows) Included with ArcGIS 9 Also a free download Python Foundation (www.python.org)www.python.org Includes command line, code editor, and documentation
68
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-67 Writing scripts Import COM client support import win32com.client Instantiate the Geoprocessor object gp = win32com.client.Dispatch (" esriGeoprocessing.GPDispatch.1") Set properties (e.g., where processing will occur?) gp.workspace = "c:\\Florida.mdb" Comment code # Buffer roads by 100 meters Run tools gp.Buffer_analysis("roads", "rdbuf100", "100")
69
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-68 Constructing Python statements Use the Geoprocessor with object-oriented programming Assign a value to an environment setting with Geoprocessor.EnvironmentSetting = Value gp.Workspace = "c:\\temp" Call tools with Geoprocessor.ToolName (parameter1,.., parameterN) gp.CreateFolder("c:\\Florida", "Scripts") gp.Clean("Europe", "#", "#", "#", "POLY")
70
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-69 Referencing data in Python Use \\ or / for path names Python is based upon the C programming language Defined by double (") or single (') quotes gp.workspace = "c:\\Florida" gp.CreateFolder('c:\\Florida', 'Scripts') Concatenate strings outputfc = gp.workspace + "\\" + inputfc
71
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-70 Referencing tools and toolboxes Only system toolboxes available by default from Geoprocessor Analysis, coverage, data management, etc. Use toolbox alias if tools have the same name gp.Buffer_analysis(roads, Out_Buff, "10 Meters", "FULL") Add your own toolbox gp.AddToolbox("c:\\MyProject\\CrossCountryMobility.tbx") gp.BestPath("start.shp", "destination.shp", "results.shp")
72
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-71 Example script # Import COM support import win32com.client # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") roads = "C:/Data/Florida/ROADS.shp" Out_Buff = "C:/Data/Florida.mdb/ROADS_Buffer" citylimit = "C:/Data/Florida/citylimit.shp" Out_Clip = "C:/Data/Florida.mdb/BUFF_Clip" # Process: Buffer... gp.Buffer_analysis(roads, Out_Buff, "10", "FULL", "ROUND") # Process: Clip... gp.Clip_analysis(Out_Buff, citylimit, Out_Clip)
73
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-72 Running scripts in different environments Check syntax and run in PythonWin ArcGIS applications can be closed Run at DOS prompt Python C:\PythonScripts\RoadBuffer.py Create a tool Add a script to a toolbox Open command runs script tool Edit command opens script source in text editor
74
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-73 Distributing scripts As Python source file.py As script tools in toolboxes User creates script tool for parameters Share the.py file and toolbox
75
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Batch processing and advanced scripting
76
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-75 Batch processing Scripts are ideally suited for batch processing Example: Clip all shapefiles in a folder to a boundary Rerun script when new data is added to folder Batch processing script
77
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-76 Listing data Enumeration: Lists of objects without a known count Use a looping structure to process one object at a time ListFeatureClasses (Wildcard (optional), Type (optional)) #return a list of shapefiles in a workspace gp.workspace = "C:\\Yellowstone" fcs = gp.ListFeatureClasses("*", "all") Examples of Enumerations ListFeatureClasses ListFields ListTables List Indexes ListRasters ListWorkspaces ListDatasets fcs = all shapefiles in C:\Yellowstone
78
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-77 The Geoprocessor Programming Model Geoprocessor diagram lists full functionality
79
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-78 Looping While a condition is true gp.workspace = "C:\\Yellowstone" fcs = gp.ListFeatureClasses ("*", "all") fc = fcs.next() clipfc = "C:\\Yellowstone\\studyarea.shp" outputws = "C:\\Yellowstone\\model" while fc != "": gp.clip_analysis(fc, clipfc, outputws + "\\" + fc) fc = fcs.next() Loop is defined by indentation in Python Indentation is a language construct in Python Needs to be consistent Use or spaces Checked by TabNanny utility in PythonWin
80
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-79 Batch processing example import win32com.client gp = win32com.client.Dispatch("esriGeoprocessing.gpDispatch.1") gp.workspace = "C:\\Database\\Wyoming\\AlbanyCounty" #Get a list of rasters in the workspace rasters = gp.listrasters("*", "all") #Store path to the output folder outputPath = "C:\\Database\\Wyoming\\AlbanyCounty\\PilotPeakStudyArea" #For each raster in the list raster = rasters.next() while raster != "": #Set the outputname to be the same as the input outName = outputPath + "\\" + raster #For each raster, clip it to a specific extent gp.clip_management(raster, "387211 231491 410734 250303", outName) raster = rasters.next()
81
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-80 Built-in geoprocessor methods Check whether an object (feature class, GDB) exists gp.Exists(myGDB) Refresh Catalog to notify script of new data created in script gp.RefreshCatalog("c:\wksp\geodatabase.mdb") File Management tools existing in toolboxes gp.Delete(myGDB) gp.Copy(myGDB, "C:\temp\newGDB")
82
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-81 Describe Method that returns an object with a set of properties Properties vary depending on what is being described Describe (InputValue): Object
83
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-82 Making decisions If statement dsc = gp.describe(fc) inputtype = dsc.ShapeType if inputtype == "Point": gp.Buffer_analysis(fc, "hospital_buff", "500.00 Meters") else: #inputtype is polygon or line gp.Clip_analysis(fc, "cntybnd", "hospital_buff_clp") Break statement to jump out of closest enclosing loop while field: if field.Name == "Flag": gp.CalculateField(fc, "Flag", "1") break field = fields.next()
84
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-83 Why use parameters with script tools? Makes scripts more flexible Dynamically assigns script arguments Workspace Feature classes String, numbers Write scripts to capture input arguments import win32com.client, sys gp = win32com.client.Dispatch("esriGeoprocessing.gpDispatch.1") gp.workspace = sys.argv[1] # first argument buffc = sys.argv[2] # second argument buffoutput = sys.argv[3] buffdistance = sys.argv[4]
85
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-84 Parameter properties Display name Data type (workspace) Required/ Optional Input/ Output
86
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-85 Running scripts that have parameters Use form to browse for data types you specify Form automatically built based upon parameters you specify Name of parameter you set when creating the script Supply arguments at command line or DOS prompt
87
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Advanced modeling
88
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-87 Using advanced functionality Models can carry out actions beyond what is within the toolbox Run a previous model as a tool Run a script as a tool Use an.exe or external function as part of a model Model Script Executable
89
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-88 Running a previous model in another model Drag and drop model from toolbox like any other tool If output from a previous model is a parameter, it will be exposed in a larger model P P P
90
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-89 Relative paths Property of a model or a script Keeps track of all tools and data elements
91
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-90 History C:\Documents and Settings\ \Application Data\ESRI\ArcToolbox\My Toolboxes Each history model contains tools for each process executed in each ArcMap/ArcCatalog session Honor generating reports
92
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-91 Using a script Drag and drop a script from a toolbox Create parameters in script to add connections between tool Attach an.exe or AML to a script
93
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-92 Exporting to a script Easy way to start writing scripts
94
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-93 Run a script at a specific time Windows AT command AT 9:00 C:\yellowstone\yellowstone.py Windows scheduler Control Panel > Scheduled Tasks
95
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-94 Precondition property Used to control flow of model execution Used to branch within a model Precondition Preconditions
96
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-95 Branching in a model Precondition property from a script If the input is a line or point If the input is a polygon Script Output will be polygons Output will be points
97
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-96 Steps for branching within a model Create a script that will set parameters as output-based upon if/then conditions Add the script to a toolbox, specifying output parameters that are in the script Apply precondition properties to tools to determine model flow
98
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-97 Writing a script to branch in a model Specify parameters to control which tools are executed in a model inputfc = gp.GetParameterAsText(0) #SAME AS sys.argv[1] dsc = gp.describe(inputfc) if dsc.shapetype == "polygon": gp.SetParameterAsText(1, "True") gp.SetParameterAsText(2, "False") else: gp.SetParameterAsText(1, "False") gp.SetParameterAsText(2, "True") A
99
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-98 Adding output text parameters Direction = Output Data type = Boolean Type = Derived A
100
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-99 Applying a precondition property Set for tools accepting parameters from a script 1. Apply Precondition to next tool 2. Select condition from script output
101
Copyright © 2002, 2003, 2004 ESRI. All rights reserved. What's New in ArcGIS 9 Scripting with Python Demo
102
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-101 Resources for learning Python Books Learn to Program Using Python Learning Python The Quick Python Book Python, Essential Reference Web sites The Python Foundation (www.python.org): Tutorials, documentationwww.python.org ESRI Instructor-led course Introduction to Geoprocessing Scripts Using Python Writing Geoprocessing Scripts with ArcGIS.pdf Online help
103
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-102 Learning paths Learning Guide Learning paths organized by software and topic Learning options Instructor-led courses Virtual Campus courses Training seminars Web workshops http://www.esri.com/training_events.html
104
What's New in ArcGIS 9 Copyright © 2002, 2003, 2004 ESRI. All rights reserved. 1-103 ESRI Support Center a gateway to resources http://support.esri.com Knowledge Base Technical articles White papers System requirements Downloads Patches and service packs Data models ArcScripts User Forums Discussion groups E-mail lists Software support resources For Developers Developer resources Request ESRI Technical Support Available to support subscribers
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.