gis jam arcgis python scripting dave verbyla
TRANSCRIPT
![Page 1: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/1.jpg)
2006 GIS Jam: ArcGIS Python Scripting
http://nrm.salrm.uaf.edu/~dverbyla/arcgis_python
![Page 2: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/2.jpg)
Getting Started With Python Geoprocessing
• Why use scripting with ArcGIS?
• Python Basics
• ArcGIS Geoprocessor Basics
• Simple Applications
• Sources of confusion
![Page 3: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/3.jpg)
Why bother with scripting?
![Page 4: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/4.jpg)
When NOT to bother with scripting?
![Page 5: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/5.jpg)
![Page 6: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/6.jpg)
![Page 7: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/7.jpg)
![Page 8: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/8.jpg)
• VB script
• Jscript
• PERL
• Python (comes with ArcGIS)
Scripting Languages for Geoprocessing
![Page 9: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/9.jpg)
Python
• Platform independent (linux, unix, windows)
• Object-oriented, developer language
• Good website (www.python.org)
• Comes with ArcGIS, free from web
![Page 10: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/10.jpg)
GeoProcessor Model
![Page 11: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/11.jpg)
![Page 12: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/12.jpg)
![Page 13: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/13.jpg)
Export Model to Script
![Page 14: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/14.jpg)
ArcGIS Geoprocessor Basics
• Import modules
• Create geoprocessor object
• Use geoprocessor
![Page 15: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/15.jpg)
# polygon_to_poly_line.py# Created on: Fri Dec 31 2004 12:34:54 PM# (generated by ArcGIS/ModelBuilder)
# Import system modulesimport sys, string, os, win32com.client
# Create the Geoprocessor objectgp =win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
# Local variables...poly_lines_shp = "C:/temp/poly_lines.shp"selected_polygons_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
![Page 16: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/16.jpg)
OROR
![Page 17: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/17.jpg)
# Script arguments or variables...Input_Features = sys.argv[1]Output_Feature_Class = sys.argv[2]
# Process: Polygon To Line...gp.toolbox = "C:/temp/My Toolbox.tbx"gp.PolygonToLine(Input_Features, Output_Feature_Class)
Script Arguments---input from user
![Page 18: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/18.jpg)
Running python scripts
• Using PythonWin debugger
• Using Python command window
• As system process
• As scheduled process
![Page 19: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/19.jpg)
PythonWin
![Page 20: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/20.jpg)
1) Check for syntax errors
2) Step Through Script Using Debugger
![Page 21: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/21.jpg)
![Page 22: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/22.jpg)
Thousands of Toolbars Bog Down System To A Crawl!
![Page 23: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/23.jpg)
“Easy Fix”— comment out self.SaveBarState(ToolbarDefault)
![Page 24: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/24.jpg)
Python command window
![Page 25: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/25.jpg)
Running script as system process
![Page 26: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/26.jpg)
Scheduling Scripts
![Page 27: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/27.jpg)
![Page 28: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/28.jpg)
![Page 29: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/29.jpg)
Messages From Executing Tools
![Page 30: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/30.jpg)
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
![Page 31: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/31.jpg)
Convert all pond polygon to line themes # Import system modulesimport sys, string, os, win32com.client
# Create the Geoprocessor objectgp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
#set workspacegp.workspace = "C:/ponds"; print "workspace set to: ", str(gp.workspace)
#get list of feature classesfcs = gp.ListFeatureClasses("*","polygon")fcs.reset()
print "All pond polygon themes will be converted to pond shoreline themes..."# Get the first theme and start the loopCurrent_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"
![Page 32: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/32.jpg)
![Page 33: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/33.jpg)
![Page 34: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/34.jpg)
![Page 35: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/35.jpg)
![Page 36: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/36.jpg)
![Page 37: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/37.jpg)
![Page 38: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/38.jpg)
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
![Page 39: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/39.jpg)
Interpreted Line by Line = SLOW
![Page 40: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/40.jpg)
Case Sensitive
![Page 41: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/41.jpg)
Indentation Source of Structure
![Page 42: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/42.jpg)
/ is a reserved character# is a comment character
![Page 43: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/43.jpg)
Determine shape type of
every theme listed in text file…..
![Page 44: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/44.jpg)
![Page 45: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/45.jpg)
![Page 46: GIS Jam ArcGIS Python Scripting Dave Verbyla](https://reader036.vdocuments.mx/reader036/viewer/2022081412/545fcb40af795935708b4ef0/html5/thumbnails/46.jpg)
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/