Module 6: Geoprocessing Scripts - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

Module 6: Geoprocessing Scripts

Description:

gp =win32com.client.Dispatch('esriGeoprocessing.GpDispatch.1' ... gp.SetProduct('ArcInfo') Python system. String module. Operating System. COM Dispatch ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 30
Provided by: daveve
Category:

less

Transcript and Presenter's Notes

Title: Module 6: Geoprocessing Scripts


1
Module 6 Geoprocessing Scripts
2
Processing loops and decisions
3
(No Transcript)
4
(No Transcript)
5
Most COM compliant scripting languages
  • AML (Arc Macro Language)
  • VB script
  • Jscript
  • PERL
  • Python (comes with ArcGIS)

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

7
Installing Python
  • ArcGIS Desktop CD
  • Explore rather than open to avoid
    autoinstallation of ArcGIS

8
In Python folder..
  • Run both exe files

9
GeoProcessor Object
10
(No Transcript)
11
(No Transcript)
12
Export Model to Script
13
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") Set the ArcGIS product
code (Arcview, ArcEditor, or ArcInfo)gp.SetProduc
t("ArcInfo")
  • Python system
  • String module
  • Operating System
  • COM Dispatch

14
Load required toolboxes...gp.AddToolbox("C/wor
kshop_geoprocessing/ExampleToolbox.tbx")
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)
15
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)
16
use to concatenate strings single or
double-quotes enclose string charsname
moose_locationstype .shpshapefile name
typeprint shapefilemoose_locations.shp
17
decisions or branching indentation used to
indicate structure if type 'point'
print 'Theme is point type' print 'Must be
polygon type to use erase tool'elif type
'polyline' print 'Theme is polyline type'
print 'Convert to polygon type, then rerun
script'elif type 'polygon' print 'Theme
is polygon type' print 'Correct feature type
for using erase tool'else print "Theme
type is not point, line, or polygon"print End
of Script out of if block
18
Listing Data
19
List first 2 pond polygon feature classes
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("pond","polyg
on") fcs.reset() get first two objects in list
and assign to variables theme1, theme2 theme1
fcs.next() theme2 fcs.next() print "First two
polygon themes in workspace ", str(theme1),
str(theme2)
20
List all pond polygon feature classes
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("pond","polyg
on") fcs.reset() Get the first theme and start
the loop Current_Theme fcs.next() while
Current_Theme While the Current_Theme is
not empty Print Current theme in list
is, str(Current_Theme) Current_Theme
fcs.next() Print End of Script
21
(No Transcript)
22
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("pond","polyg
on") 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_T
heme, "c/shorelines/" Current_Theme)
Current_Theme fcs.next() print "End of Script"
23
1) Check for syntax errors
2) Step Through Script Using Debugger
24
Test Batch Process.
25
Scheduling Scripts
26
(No Transcript)
27
(No Transcript)
28
Sources of Confusion
  • Python commands and variables are case sensitive
  • ( print theme ltgt Print theme ltgt print Theme )
  • Geoprocessor properties not case sensitive
  • ( gp.workspace gp.WorkSpace )
  • \ is a reserved character meaning line
    continuation
  • (use / or \\ for paths instead of \)
  • Indentation is a source of loop structure

29
Sources of Confusion
  • Model does not use UML like ArcObjects
  • Arrows indicate instantiation
  • Only non character properties are indicated in
    diagram
Write a Comment
User Comments (0)
About PowerShow.com