本文整理汇总了Python中TestUtilities.createScratch方法的典型用法代码示例。如果您正苦于以下问题:Python TestUtilities.createScratch方法的具体用法?Python TestUtilities.createScratch怎么用?Python TestUtilities.createScratch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestUtilities
的用法示例。
在下文中一共展示了TestUtilities.createScratch方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Exception
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
else:
raise LicenseError
arcpy.ImportToolbox(TestUtilities.toolbox)
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
inputPolyArea = os.path.join(TestUtilities.inputGDB, "samplePolygonArea")
inputRoads = os.path.join(TestUtilities.inputGDB, "roads")
inputSurface = os.path.join(TestUtilities.inputGDB, "Jbad_SRTM_USGS_EROS")
psOutputRV = os.path.join(TestUtilities.outputGDB, "PathSlopeOutputRV")
classValue = '0 3 1;3 10 2;10 15 3;15 20 4;20 30 5;30 45 6;45 60 7;60 85 8;85 10000000000000 9;NODATA 0'
#Testing Path Slope by Reclass Values
arcpy.AddMessage("Starting Test: Path Slope by Reclass Values")
TestUtilities.createScratch()
arcpy.PathSlopeByRanges_path(inputPolyArea, inputRoads, inputSurface, 'DEGREE', classValue, psOutputRV)
#Test for Feature Outpu
outputFeatureCount = int(arcpy.GetCount_management(psOutputRV).getOutput(0))
print("Output FeatureClass: " + str(psOutputRV))
print("Output Feature Count: " + str(outputFeatureCount))
if (outputFeatureCount < 1):
print("Invalid Output Feature Count: " + str(outputFeatureCount))
raise Exception("Test Failed")
print("Test Passed")
except LicenseError:
示例2: RunTest
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
def RunTest():
try:
arcpy.AddMessage("Starting Test: TestCreateRangeFanIndexFeatures")
# WORKAROUND
print "Creating New Scratch Workspace (Workaround)"
TestUtilities.createScratch()
inputPolygonFC = os.path.join(TestUtilities.inputGDB, "RangeFans")
outputExtentBoxes = os.path.join(TestUtilities.outputGDB, "OutputExtentBoxes")
outputRangeVertices = os.path.join(TestUtilities.outputGDB, "RangeVertices")
toolbox = TestUtilities.toolbox
# Set environment settings
print "Running from: " + str(TestUtilities.currentPath)
print "Geodatabase path: " + str(TestUtilities.geodatabasePath)
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
arcpy.ImportToolbox(toolbox, "RFT")
inputFeatureCount = int(arcpy.GetCount_management(inputPolygonFC).getOutput(0))
print "Input FeatureClass: " + str(inputPolygonFC)
print "Input Feature Count: " + str(inputFeatureCount)
if (inputPolygonFC < 1) :
print "Invalid Input Feature Count: " + str(inputPolygonFC)
########################################################3
# Execute the Model under test:
arcpy.CreateRangeFanIndexFeatures_RFT(inputPolygonFC, outputExtentBoxes, outputRangeVertices)
########################################################3
# Verify the results
outputFeatureCountExtent = int(arcpy.GetCount_management(outputExtentBoxes).getOutput(0))
print "Output FeatureClass: " + str(outputExtentBoxes)
print "Output Feature Count: " + str(outputFeatureCountExtent)
outputFeatureCountPoints = int(arcpy.GetCount_management(outputRangeVertices).getOutput(0))
print "Output FeatureClass: " + str(outputRangeVertices)
print "Output Feature Count: " + str(outputFeatureCountPoints)
if (outputFeatureCountExtent < 1) or (outputFeatureCountPoints < 1) :
print "Invalid Output Feature Count: " + str(outputFeatureCountExtent) + ":" + str(outputFeatureCountPoints)
raise Exception("Test Failed")
# WORKAROUND: delete scratch db
print "Deleting Scratch Workspace (Workaround)"
TestUtilities.deleteScratch()
print "Test Successful"
except arcpy.ExecuteError:
# Get the tool error messages
msgs = arcpy.GetMessages()
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
except Exception as e:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
开发者ID:ACueva,项目名称:defense-and-intel-analysis-toolbox,代码行数:77,代码来源:TestCreateRangeFanIndexFeatures.py
示例3: RunTest
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
def RunTest():
try:
arcpy.AddMessage("Starting Test: RangeFans")
if arcpy.CheckExtension("Spatial") == "Available":
arcpy.CheckOutExtension("Spatial")
else:
# Raise a custom exception
raise Exception("LicenseError")
# WORKAROUND
print "Creating New Scratch Workspace (Workaround)"
TestUtilities.createScratch()
# Verify the expected configuration exists
inputPointsFC = os.path.join(TestUtilities.inputGDB, "sampleRangePoints")
inputSurface = os.path.join(TestUtilities.inputGDB, "Jbad_SRTM_USGS_EROS")
outputRangeFansFC = os.path.join(TestUtilities.outputGDB, "RangeFans")
outputRangeVizFC = os.path.join(TestUtilities.outputGDB, "RangeViz")
toolbox = TestUtilities.toolbox
sr = arcpy.SpatialReference(32642) #WGS_1984_UTM_Zone_42N using factoryCode
# Check For Valid Input
objects2Check = []
objects2Check.extend([inputPointsFC, inputSurface, toolbox])
for object2Check in objects2Check :
desc = arcpy.Describe(object2Check)
if desc == None :
raise Exception("Bad Input")
else :
print("Valid Object: " + desc.Name)
# Set environment settings
print("Running from: " + str(TestUtilities.currentPath))
print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
arcpy.ImportToolbox(toolbox, "VandR")
inputFeatureCount = int(arcpy.GetCount_management(inputPointsFC).getOutput(0))
print("Input FeatureClass: " + str(inputPointsFC))
print("Input Feature Count: " + str(inputFeatureCount))
if (inputFeatureCount < 1) :
print("Invalid Input Feature Count: " + str(inputFeatureCount))
maximumRange = 1000.0
bearing = 150.0
traversal = 22.0
########################################################3
# Execute the Model under test:
arcpy.RangeFan_VandR(inputPointsFC, maximumRange, bearing, traversal, inputSurface, outputRangeFansFC, outputRangeVizFC, sr)
########################################################3
# Verify the results
outputFeatureCountFans = int(arcpy.GetCount_management(outputRangeFansFC).getOutput(0))
print("Output FeatureClass: " + str(outputRangeFansFC))
print("Output Feature Count: " + str(outputFeatureCountFans))
outputFeatureCountViz = int(arcpy.GetCount_management(outputRangeVizFC).getOutput(0))
print("Output FeatureClass: " + str(outputRangeVizFC))
print("Output Feature Count: " + str(outputFeatureCountViz))
if (outputFeatureCountFans < 1) or (outputFeatureCountViz < 1):
print("Invalid Output Feature Count: " + str(outputFeatureCountFans) + ":" + str(outputFeatureCountViz))
raise Exception("Test Failed")
# WORKAROUND: delete scratch db
print("Deleting Scratch Workspace (Workaround)")
TestUtilities.deleteScratch()
print("Test Successful")
except arcpy.ExecuteError:
# Get the tool error messages
msgs = arcpy.GetMessages()
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
except Exception as e:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
finally:
#.........这里部分代码省略.........
示例4: RunTest
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
def RunTest():
try:
arcpy.AddMessage("Starting Test: LocalPeaks")
if arcpy.CheckExtension("Spatial") == "Available":
arcpy.CheckOutExtension("Spatial")
else:
# Raise a custom exception
raise Exception("LicenseError")
# WORKAROUND
print "Creating New Scratch Workspace (Workaround)"
TestUtilities.createScratch()
# Verify the expected configuration exists
inputPolygonFC = os.path.join(TestUtilities.inputGDB, "samplePolygonArea")
inputSurface = os.path.join(TestUtilities.defaultGDB, "Jbad_SRTM_USGS_EROS")
outputPointsFC = os.path.join(TestUtilities.outputGDB, "LocalPeaks")
toolbox = TestUtilities.toolbox
# Check For Valid Input
objects2Check = []
objects2Check.extend([inputPolygonFC, inputSurface, toolbox])
for object2Check in objects2Check:
desc = arcpy.Describe(object2Check)
if desc == None:
raise Exception("Bad Input")
else:
print "Valid Object: " + desc.Name
# Set environment settings
print "Running from: " + str(TestUtilities.currentPath)
print "Geodatabase path: " + str(TestUtilities.geodatabasePath)
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
arcpy.ImportToolbox(toolbox, "VandR")
inputFeatureCount = int(arcpy.GetCount_management(inputPolygonFC).getOutput(0))
print "Input FeatureClass: " + str(inputPolygonFC)
print "Input Feature Count: " + str(inputFeatureCount)
if inputFeatureCount < 1:
print "Invalid Input Feature Count: " + str(inputFeatureCount)
numberOfPeaks = 3
########################################################3
# Execute the Model under test:
arcpy.FindLocalPeaks_VandR(inputPolygonFC, numberOfPeaks, inputSurface, outputPointsFC)
########################################################3
# Verify the results
outputFeatureCount = int(arcpy.GetCount_management(outputPointsFC).getOutput(0))
print "Output FeatureClass: " + str(outputPointsFC)
print "Output Feature Count: " + str(outputFeatureCount)
if outputPointsFC < 3:
print "Invalid Output Feature Count: " + str(outputFeatureCount)
raise Exception("Test Failed")
# WORKAROUND: delete scratch db
print "Deleting Scratch Workspace (Workaround)"
TestUtilities.deleteScratch()
print "Test Successful"
except arcpy.ExecuteError:
# Get the tool error messages
msgs = arcpy.GetMessages()
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
except Exception as e:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
finally:
# Check in the 3D Analyst extension
arcpy.CheckInExtension("Spatial")
示例5: RunTest
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
def RunTest():
try:
arcpy.AddMessage("Starting Test: TestRangeFanByBearingAndTraversal")
# WORKAROUND
print("Creating New Scratch Workspace (Workaround)" )
TestUtilities.createScratch()
inputPointsFC = os.path.join(TestUtilities.inputGDB, "sampleRangePoints")
outputRangeFansFC = os.path.join(TestUtilities.outputGDB, "RangeFansBearingAndTraversal")
toolbox = TestUtilities.toolbox
# Set environment settings
print("Running from: " + str(TestUtilities.currentPath))
print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
arcpy.ImportToolbox(toolbox, "Range")
inputFeatureCount = int(arcpy.GetCount_management(inputPointsFC).getOutput(0))
print("Input FeatureClass: " + str(inputPointsFC))
print("Input Feature Count: " + str(inputFeatureCount))
if (inputFeatureCount < 1) :
print("Invalid Input Feature Count: " + str(inputFeatureCount))
maximumRangeInMeters = 2000
centralBearingInDegrees = 320
traversalWidthInDegrees = 30
########################################################3
# Execute the Model under test:
# mfunk 8/12/2014: Tool parameters have been modified, this test is no longer valid
#arcpy.RangeFanByBearingAndTraversal_Range(inputPointsFC, maximumRangeInMeters, centralBearingInDegrees, traversalWidthInDegrees, outputRangeFansFC)
########################################################3
# Verify the results
outputFeatureCount = int(arcpy.GetCount_management(outputRangeFansFC).getOutput(0))
print("Output FeatureClass: " + str(outputRangeFansFC))
print("Output Feature Count: " + str(outputFeatureCount))
if (outputFeatureCount < 1) :
print("Invalid Output Feature Count: " + str(outputFeatureCount))
raise Exception("Test Failed")
# WORKAROUND: delete scratch db
print("Deleting Scratch Workspace (Workaround)")
TestUtilities.deleteScratch()
print("Test Successful")
except arcpy.ExecuteError:
# Get the tool error messages
msgs = arcpy.GetMessages()
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
except Exception as e:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
示例6: RunTest
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
def RunTest():
try:
arcpy.AddMessage("Starting Test: RangeRings")
# WORKAROUND
print("Creating New Scratch Workspace (Workaround)")
TestUtilities.createScratch()
# Verify the expected configuration exists
inputPointsFC = os.path.join(TestUtilities.inputGDB, "sampleRangePoints")
outputRangeRingsFC = os.path.join(TestUtilities.outputGDB, "RangeRings")
outputRangeRadialsFC = os.path.join(TestUtilities.outputGDB, "RangeRadials")
toolbox = TestUtilities.toolbox
# Check For Valid Input
objects2Check = []
objects2Check.extend([inputPointsFC, toolbox])
for object2Check in objects2Check :
desc = arcpy.Describe(object2Check)
if desc == None :
raise Exception("Bad Input")
else :
print("Valid Object: " + desc.Name)
# Set environment settings
print("Running from: " + str(TestUtilities.currentPath))
print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
arcpy.ImportToolbox(toolbox, "VandR")
inputFeatureCount = int(arcpy.GetCount_management(inputPointsFC).getOutput(0))
print("Input FeatureClass: " + str(inputPointsFC))
print("Input Feature Count: " + str(inputFeatureCount))
if (inputFeatureCount < 1) :
print("Invalid Input Feature Count: " + str(inputFeatureCount))
numberOfRings = 5
ringInterval = 1000.0
distanceUnits = "METERS"
numberOfRadials = 8
########################################################3
# Execute the Model under test:
arcpy.RangeRings_VandR(inputPointsFC, numberOfRings, ringInterval, distanceUnits, numberOfRadials, outputRangeRingsFC, outputRangeRadialsFC)
########################################################3
# Verify the results
outputFeatureCountRings = int(arcpy.GetCount_management(outputRangeRingsFC).getOutput(0))
print("Output FeatureClass: " + str(outputRangeRingsFC))
print("Output Feature Count: " + str(outputFeatureCountRings))
outputFeatureCountRadials = int(arcpy.GetCount_management(outputRangeRadialsFC).getOutput(0))
print("Output FeatureClass: " + str(outputRangeRadialsFC))
print("Output Feature Count: " + str(outputFeatureCountRadials))
if (outputFeatureCountRings < 1) or (outputFeatureCountRadials < 1) :
print("Invalid Output Feature Count: " + str(outputFeatureCountRings) + ":" + str(outputFeatureCountRadials))
raise Exception("Test Failed")
# WORKAROUND: delete scratch db
print("Deleting Scratch Workspace (Workaround)")
TestUtilities.deleteScratch()
print("Test Successful")
except arcpy.ExecuteError:
# Get the tool error messages
msgs = arcpy.GetMessages()
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
except Exception as e:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
示例7: RunTest
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
def RunTest():
try:
arcpy.AddMessage("Starting Test: CoordinateConversion")
# WORKAROUND
print "Creating New Scratch Workspace (Workaround)"
TestUtilities.createScratch()
inputTable = os.path.join(TestUtilities.csvPath, "SigActs.csv")
outputDbf = os.path.join(TestUtilities.dbfPath, "test_coordinate_cc.dbf")
toolbox = TestUtilities.toolbox
# Set environment settings
print "Running from: " + str(TestUtilities.currentPath)
print "Geodatabase path: " + str(TestUtilities.geodatabasePath)
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
arcpy.ImportToolbox(toolbox, "MyAlias")
inputFeatureCount = int(arcpy.GetCount_management(inputTable).getOutput(0))
print "Input FeatureClass: " + str(inputTable)
print "Input Feature Count: " + str(inputFeatureCount)
if (inputFeatureCount < 1) :
print "Invalid Input Feature Count: " + str(inputFeatureCount)
coordinateConversionFrom = 'MGRS'
coordinateFieldX = 'Location'
coordinateFieldY = '#'
########################################################3
# Execute the Model under test:
# sample params:
# 'data\csv\SigActs.csv', 'MGRS', 'Location', '#', 'data\test_coordinate_cc.dbf',
arcpy.ConvertCoordinates_MyAlias(inputTable, coordinateConversionFrom, coordinateFieldX, coordinateFieldY, outputDbf)
########################################################3
# Verify the results
outputFeatureCount = int(arcpy.GetCount_management(outputDbf).getOutput(0))
print "Output FeatureClass: " + str(outputDbf)
print "Output Feature Count: " + str(outputFeatureCount)
if (outputFeatureCount <> inputFeatureCount) :
print "Input / Output Feature Count don't match: " + str(inputFeatureCount) + ":" + str(outputFeatureCount)
raise Exception("Test Failed")
# WORKAROUND: delete scratch db
print "Deleting Scratch Workspace (Workaround)"
TestUtilities.deleteScratch()
print "Test Successful"
except arcpy.ExecuteError:
# Get the tool error messages
msgs = arcpy.GetMessages()
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
except Exception as e:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
示例8: RunTest
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
def RunTest():
try:
arcpy.AddMessage("Starting Test: TestLocalPeaks")
#TEST_IMPLEMENTED = False
#
#if not TEST_IMPLEMENTED :
# arcpy.AddWarning("***Test Not Yet Implemented***")
# return
# TODO: once model has a version that works with local surface data
# (rather than image service), then finish this test/implementation below
#
# alternately you can add an image service connection in Catalog and
# fill in the parameter below
if arcpy.CheckExtension("Spatial") == "Available":
arcpy.CheckOutExtension("Spatial")
else:
# Raise a custom exception
raise Exception("LicenseError")
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
# WORKAROUND
print("Creating New Scratch Workspace (Workaround)")
TestUtilities.createScratch()
# Verify the expected configuration exists
inputPolygonFC = os.path.join(TestUtilities.inputGDB, "samplePolygonArea")
inputSurface = TestUtilities.inputElevationURL
outputPointsFC = os.path.join(TestUtilities.outputGDB, "LocalPeaks")
toolbox = TestUtilities.toolbox
arcpy.ImportToolbox(toolbox, "MAoT")
# Check For Valid Input
objects2Check = []
#objects2Check.extend([inputPolygonFC, inputSurface, toolbox])
objects2Check.extend([inputPolygonFC, toolbox])
for object2Check in objects2Check :
desc = arcpy.Describe(object2Check)
if desc == None :
raise Exception("Bad Input")
else :
print("Valid Object: " + desc.Name)
# Set environment settings
print("Running from: " + str(TestUtilities.currentPath))
print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
inputFeatureCount = int(arcpy.GetCount_management(inputPolygonFC).getOutput(0))
print("Input FeatureClass: " + str(inputPolygonFC))
print("Input Feature Count: " + str(inputFeatureCount))
if (inputFeatureCount < 1) :
print("Invalid Input Feature Count: " + str(inputFeatureCount))
numberOfPeaks = 3
########################################################3
# Execute the Model under test:
arcpy.FindLocalPeaks_MAoT(inputPolygonFC, numberOfPeaks, inputSurface, outputPointsFC)
########################################################3
# Verify the results
outputFeatureCount = int(arcpy.GetCount_management(outputPointsFC).getOutput(0))
print("Output FeatureClass: " + str(outputPointsFC))
print("Output Feature Count: " + str(outputFeatureCount))
if (outputPointsFC < 3) :
print("Invalid Output Feature Count: " + str(outputFeatureCount))
raise Exception("Test Failed")
# WORKAROUND: delete scratch db
print("Deleting Scratch Workspace (Workaround)")
TestUtilities.deleteScratch()
print("Test Successful")
except arcpy.ExecuteError:
# Get the tool error messages
msgs = arcpy.GetMessages()
arcpy.AddError(msgs)
# return a system error code
sys.exit(-1)
except Exception as e:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages() + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
#.........这里部分代码省略.........
示例9: RunTest
# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import createScratch [as 别名]
def RunTest():
try:
arcpy.AddMessage("Starting Test: TestLocalPeaks")
#TEST_IMPLEMENTED = False
#
#if not TEST_IMPLEMENTED :
# arcpy.AddWarning("***Test Not Yet Implemented***")
# return
# TODO: once model has a version that works with local surface data
# (rather than image service), then finish this test/implementation below
#
# alternately you can add an image service connection in Catalog and
# fill in the parameter below
if arcpy.CheckExtension("Spatial") == "Available":
print("Checking out Spatial Analyst license...")
arcpy.CheckOutExtension("Spatial")
else:
# Raise a custom exception
raise Exception("LicenseError")
if arcpy.CheckExtension("3D") == "Available":
print("Checking out 3D Analyst license...")
arcpy.CheckOutExtension("3D")
else:
raise Exception("LicenseError")
try:
print("Getting Advanced license...")
import arcinfo
except ImportError:
print("Could not use ArcGIS Advanced license...")
raise Exception
arcpy.env.overwriteOutput = True
arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
# WORKAROUND
print("Creating New Scratch Workspace (Workaround)")
TestUtilities.createScratch()
# Getting inputs
print("Getting inputs...")
print("inputPolygonFC...")
inputPolygonFC = os.path.join(TestUtilities.inputGDB, "samplePolygonArea")
print("inputSurface...")
inputSurface = TestUtilities.inputElevationURL
print("outputPointsFC")
outputPointsFC = os.path.join(TestUtilities.outputGDB, "LocalPeaks")
print("ImportToolbox--MAoT...")
arcpy.ImportToolbox(TestUtilities.toolbox, "MAoT")
# mf - these have been tested
# # Check For Valid Input
# print("Checking valid inputs...")
# objects2Check = []
# #objects2Check.extend([inputPolygonFC, inputSurface, toolbox])
# objects2Check.extend([inputPolygonFC, toolbox])
# for object2Check in objects2Check :
# desc = arcpy.Describe(object2Check)
# if desc == None :
# raise Exception("Bad Input")
# else :
# print("Valid Object: " + desc.Name)
# Set environment settings
print("Running from: " + str(TestUtilities.currentPath))
print("Geodatabase path: " + str(TestUtilities.geodatabasePath))
inputFeatureCount = int(arcpy.GetCount_management(inputPolygonFC).getOutput(0))
print("Input FeatureClass: " + str(inputPolygonFC))
print("Input Feature Count: " + str(inputFeatureCount))
# if (inputFeatureCount < 1):
# print("Invalid Input Polygon Feature Count: " + str(inputFeatureCount))
# Convert input elevation service to local dataset surface
print("Converting input image service into a local raster surface")
polygonExtent = arcpy.Describe(inputPolygonFC).extent
print("Using extent: " + str(polygonExtent))
cellSize = CellSize(inputPolygonFC)
print("Using cell size: " + str(cellSize))
localSurf = None
srWGS84 = arcpy.SpatialReference(4326) # GCS_WGS_1984
srWebMerc = arcpy.SpatialReference(3857) #Web_Mercator_Auxiliary_Sphere
print("Reworking inputs from image service...")
try:
tempClipExtent = os.path.join(TestUtilities.scratchGDB,"tempClipExtent")
localSurf = os.path.join(TestUtilities.scratchGDB,"localSurf")
print(" projecting input clip to WGS 1984 to match service...")
arcpy.Project_management(inputPolygonFC,tempClipExtent,srWGS84)
tempCellSize = CellSize(tempClipExtent)
#MakeImageServerLayer_management (in_image_service, out_imageserver_layer, {template},
#{band_index}, {mosaic_method}, {order_field},
#{order_base_value}, {lock_rasterid}, {cell_size},
#{where_clause}, {processing_template})
print(" getting image service layer with cell size " + str(tempCellSize) + "...")
arcpy.MakeImageServerLayer_management(inputSurface, "inputSurface", tempClipExtent,
"#", "#", "#",
"#", "#", tempCellSize)
print(" projecting image service layer to match target data...")
#.........这里部分代码省略.........