2006 GIS Jam: ArcGIS Python Scripting - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

2006 GIS Jam: ArcGIS Python Scripting

Description:

When NOT to bother with scripting? VB script. Jscript. PERL. Python (comes with ArcGIS) ... list of feature classes. fcs = gp.ListFeatureClasses('*','polygon' ... – PowerPoint PPT presentation

Number of Views:140
Avg rating:3.0/5.0
Slides: 47
Provided by: DaveVe1
Category:
Tags: arcgis | gis | class | jam | python | scripting

less

Transcript and Presenter's Notes

Title: 2006 GIS Jam: ArcGIS Python Scripting


1
2006 GIS Jam ArcGIS Python Scripting
http//nrm.salrm.uaf.edu/dverbyla/arcgis_python
2
Getting Started With Python Geoprocessing
  • Why use scripting with ArcGIS?
  • Python Basics
  • ArcGIS Geoprocessor Basics
  • Simple Applications
  • Sources of confusion

3
Why bother with scripting?
4
When NOT to bother with scripting?
5
(No Transcript)
6
(No Transcript)
7
(No Transcript)
8
Scripting Languages for Geoprocessing
  • VB script
  • Jscript
  • PERL
  • Python (comes with ArcGIS)

9
Python
  • Platform independent (linux, unix, windows)
  • Object-oriented, developer language
  • Good website (www.python.org)
  • Comes with ArcGIS, free from web

10
GeoProcessor Model
11
(No Transcript)
12
(No Transcript)
13
Export Model to Script
14
ArcGIS Geoprocessor Basics
  • Import modules
  • Create geoprocessor object
  • Use geoprocessor

15
polygon_to_poly_line.py Created on Fri Dec
31 2004 123454 PM (generated by
ArcGIS/ModelBuilder) Import system
modulesimport sys, string, os,
win32com.client Create the Geoprocessor
objectgp win32com.client.Dispatch("esriGeoproces
sing.GpDispatch.1") Local variables...poly_lin
es_shp "C/temp/poly_lines.shp"selected_polygon
s_shp "C/temp/selected_polygons.shp"
Process Polygon To Line...gp.toolbox
"C/workshop_geoprocessing/ExampleToolbox.tbx"gp.
PolygonToLine(selected_polygons_shp,
poly_lines_shp)
  • Python system
  • String module
  • Operating System
  • COM Dispatch

16
OR
OR
17
Script arguments or variables...Input_Features
sys.argv1Output_Feature_Class
sys.argv2 Process Polygon To
Line...gp.toolbox "C/temp/My
Toolbox.tbx"gp.PolygonToLine(Input_Features,
Output_Feature_Class)
Script Arguments---input from user
18
Running python scripts
  • Using PythonWin debugger
  • Using Python command window
  • As system process
  • As scheduled process

19
PythonWin
20
1) Check for syntax errors
2) Step Through Script Using Debugger
21
(No Transcript)
22
Thousands of Toolbars Bog Down System To A Crawl!
23
Easy Fix comment out self.SaveBarState(ToolbarD
efault)
24
Python command window
25
Running script as system process
26
Scheduling Scripts
27
(No Transcript)
28
(No Transcript)
29
Messages From Executing Tools
30
Example Applications
  • For every polygon theme in workspace
  • Convert polygon theme to polyline theme
  • Compute area and perimeter in all themes
  • For every workspace in text file
  • Build raster pyramids for every raster in each
    workspace

31
Convert all pond polygon to line themes
Import system modules import sys, string, os,
win32com.client Create the Geoprocessor
object gp win32com.client.Dispatch("esriGeoproce
ssing.GpDispatch.1") set workspace gp.workspace
"C/ponds" print "workspace set to ",
str(gp.workspace) get list of feature
classes fcs gp.ListFeatureClasses("","polygon")
fcs.reset() print "All pond polygon themes will
be converted to pond shoreline themes..." Get
the first theme and start the loop Current_Theme
fcs.next() while Current_Theme While the
Current_Theme is not empty print "Converting
Theme", str(Current_Theme)
gp.PolygonToLine(Current_Theme, "c/shorelines/"
Current_Theme) Current_Theme
fcs.next() print "End of Script"
32
(No Transcript)
33
(No Transcript)
34
(No Transcript)
35
(No Transcript)
36
(No Transcript)
37
(No Transcript)
38
Problems With Python Scripting
  • Interpreted language
  • Case sensitive
  • Indentation source of structure
  • \ is a reserved character
  • is a commenting character
  • Newline character at end of lines

39
Interpreted Line by Line SLOW
40
Case Sensitive
41
Indentation Source of Structure
42
/ is a reserved character is a comment character
43
Determine shape type of every theme listed in
text file..
44
(No Transcript)
45
(No Transcript)
46
More information
  • Python
  • http//wiki.python.org/moin/BeginnersGuide
  • http//www.python.org/
  • http//diveintopython.org/
  • ArcGIS Python Scripting
  • http//hobu.biz/software/python_guide_esri/
  • http//arcscripts.esri.com/
Write a Comment
User Comments (0)
About PowerShow.com