asked on
# 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())
ASKER
ASKER
ASKER
ASKER
# 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, 'landcoverprepnew', '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, 'Landcoverprepnew\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[-3:] # last 3 chars
idSuffix = LnumDir[-5:] # last 5 chars
DnumDir = os.path.normpath(
os.path.join(donutDir, 'DONUT_' + numSuffix))
assert os.path.isdir(DnumDir)
##log("4/n")
# Generate another output tuple.
yield (LnumDir, DnumDir, idSuffix)
# Create the Geoprocessor object
gp = arcgisscripting.create()
expTemplate = '(%s, + (%s * 10))'
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, 'landcoverprepnew', 'Results', idSuffix)
log("\n" + outDir)
InExpression = expTemplate % (donut, landcover)
log(" " + InExpression)
# Check out Spatial Analyst extension license
gp.CheckOutExtension("Spatial")
# Process: MapAlgebra
gp.SingleOutputMapAlgebra_sa(InExpression, outDir)
log("Msg: " + gp.GetMessages())
ASKER
# 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/Hibernacula/EUA_805/TOCREATE2016'
def log(s):
f = open("C:/test_mish.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, '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, '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[-3:] # last 3 chars
idSuffix = LnumDir[-5:] # last 5 chars
DnumDir = os.path.normpath(
os.path.join(donutDir, 'DONUT_' + numSuffix))
print LnumDir, DnumDir
assert os.path.isdir(DnumDir), "Dir %s not found" % DnumDir
##log("4/n")
# Generate another output tuple.
yield (LnumDir, DnumDir, idSuffix)
# Create the Geoprocessor object
gp = arcgisscripting.create()
expTemplate = '(%s, + (%s * 10))'
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, 'Results', idSuffix)
log("\n" + outDir)
InExpression = expTemplate % (donut, landcover)
log(" " + InExpression)
# Check out Spatial Analyst extension license
gp.CheckOutExtension("Spatial")
# Process: MapAlgebra
gp.SingleOutputMapAlgebra_sa(InExpression, outDir)
log("Msg: " + gp.GetMessages())
ASKER
ASKER
Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.
TRUSTED BY
which the script expect to be.