Professional Documents
Culture Documents
• ArcGIS Desktop CD
• Explore rather than open to avoid
autoinstallation of ArcGIS
In Python folder..
# Local variables...
poly_lines_shp = "C:/temp/poly_lines.shp"
selected_polygons_shp = "C:/temp/selected_polygons.shp"
name = ‘moose_locations’
type = “.shp”
shapefile = name + type
print shapefile
moose_locations.shp
# 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
Listing Data
List first 2 pond polygon feature classes
# Import system modules
import sys, string, os, win32com.client
# Create the Geoprocessor object
gp =
win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
#set workspace
gp.workspace = "C:/ponds "; print "workspace set to: ",
str(gp.workspace)
#get list of feature classes
fcs = gp.ListFeatureClasses("pond*","polygon")
fcs.reset()
#get first two objects in list and assign to variables theme1,
theme2:
theme1 = fcs.next()
theme2 = fcs.next()
List all pond polygon feature classes
# Import system modules
import sys, string, os, win32com.client
# Create the Geoprocessor object
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
#set workspace
gp.workspace = "C:/ponds“; print "workspace set to: ", str(gp.workspace)
#get list of feature classes
fcs = gp.ListFeatureClasses("pond*","polygon")
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”
Convert all pond polygon to line themes
# Import system modules
import sys, string, os, win32com.client
#set workspace
gp.workspace = "C:/ponds"; print "workspace set to: ", str(gp.workspace)
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()