Advertisement
Advertisement
| 07.18.2008 at 12:56PM PDT, ID: 23578050 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: |
# Multi_Output_Map_Algebra_sample.py
# Description:
# Runs an expression built with the Map Algebra language.
# Requirements: None
import arcgisscripting
import glob
import os
gisworkDir = 'c:\Giswork'
def log(s):
f = open("C:/tester.txt","w")
f.write(s)
f.close()
def allLandcoverDonutAndIdSuffix(gisworkDir):
'''Generates all tuples (landcover, donut, idSuffix) from the gisworkDir.'''
##log("1\n")
# Prepare the path to the donuts.
donutDir = os.path.join(gisworkDir, 'landcoverprep', 'Donut')
assert os.path.isdir(donutDir)
##log("2\n")
# Iterate through sequence of top-level landcover subdirectories.
mask = os.path.normpath(os.path.join(gisworkDir, 'Landcoverprep\landcover*'))
##log(mask)
for LDir in glob.glob(mask): # full paths to LandcoverA, LandcoverB, etc.
subdir = os.path.basename(LDir)
##log("3\n")
# Iterate through all numbered landcover subdirs inside.
mask2 = os.path.join(LDir, '*')
for LnumDir in glob.glob(mask2):
# Separate the counter part, the idSuffix and construct
# the related donut numbered directory name.
numSuffix = LnumDir[-2:] # last 2 chars
idSuffix = LnumDir[-4:] # last 4 chars
DnumDir = os.path.normpath(
os.path.join(donutDir, 'DONUT_' + numSuffix))
assert os.path.isdir(DnumDir)
##log("4")
# Generate another output tuple.
yield (LnumDir, DnumDir, idSuffix)
# Create the Geoprocessor object
gp = arcgisscripting.create()
expTemplate = 'CON(ISNULL(%s), %s, %s * -1)'
log("\n===== Output below: ====\n")
for landcover, donut, idSuffix in allLandcoverDonutAndIdSuffix(gisworkDir):
# Construct the expression and the output directory name.
outDir = os.path.join(gisworkDir, 'landcoverprep', 'Results', idSuffix)
log("\n" + outDir)
InExpression = expTemplate % (donut, landcover, landcover)
log(" " + InExpression)
# Check out Spatial Analyst extension license
gp.CheckOutExtension("Spatial")
# Process: MapAlgebra
gp.SingleOutputMapAlgebra_sa(InExpression, outDir)
log("Msg: " + gp.GetMessages())
|