Hello, I have been using the code below with success with ESRI ArcMap 9.2. However, I'd like to know how to add some more automation to this script. Currently I run this from the command line like this:
C:\Python24\python "C:\Documents and Settings\user\Desktop\test
.py" LANDCOVERfileLIST DONUTfileLIST
So each time I want to run this I need to create a list of files to use and then enter their location in the statement above and run. I also change the 'new_name' field each time in the body of the script. I need the count appended to the end to be the way it is, it currently matches the ID of the files. I have six (and counting) sets of landcover files each in their own folder and each with a unique name and numbered 1 - 71 and then I have one set of Donut files each numbered 1 -71. So in the end I'll have 6 sets of files now named new_name01, newname02, etc. How can I set this up to be more automatic?
Can I?
-make so I just use the folders where the files are located and have a name derived from folder name?
-make a long list with file locations and somehow have the outnames change for every set and the numbers stay in sync?
-do this someother way that is more elegant than I currently think of?
I appreciate annotated code and instructions so that I can learn more about python, etc.
Thank you,
MJ
# Multi_Output_Map_Algebra_s
ample.py
# Description:
# Runs an expression built with the Map Algebra language.
# Requirements: None
import sys, arcgisscripting
#import sys
# Create the Geoprocessor object
gp = arcgisscripting.create()
f = open(sys.argv[1],'r')
circlefile = open(sys.argv[2],'r')
count = 1
tmpdir = 'c:\\temp\\'
try:
for landcover in f:
donut = circlefile.readline()
# Set local variables
Outfname = os.path.join(tmpdir, 'new_name', str(count))
InExpression = "CON(ISNULL(" + donut.strip() + ")," + landcover.strip() + "," + landcover.strip() + " * -1)"
print InExpression
# Check out Spatial Analyst extension license
gp.CheckOutExtension("Spat
ial")
# Process: MapAlgebra
gp.SingleOutputMapAlgebra_
sa(InExpre
ssion, Outfile)
count = count + 1
f.close
circlefile.close
except:
# If an error occurred while running a tool, then print the messages.
print gp.GetMessages()
Start Free Trial