当前位置: 首页>>代码示例>>Python>>正文


Python TestUtilities.deleteScratch方法代码示例

本文整理汇总了Python中TestUtilities.deleteScratch方法的典型用法代码示例。如果您正苦于以下问题:Python TestUtilities.deleteScratch方法的具体用法?Python TestUtilities.deleteScratch怎么用?Python TestUtilities.deleteScratch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestUtilities的用法示例。


在下文中一共展示了TestUtilities.deleteScratch方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RunTest

# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import deleteScratch [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")
开发者ID:jfrygeo,项目名称:defense-and-intel-analysis-toolbox,代码行数:96,代码来源:TestModelLocalPeaks.py

示例2: RunTest

# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import deleteScratch [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 deleteScratch [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:
#.........这里部分代码省略.........
开发者ID:aguha-github,项目名称:solutions-geoprocessing-toolbox,代码行数:103,代码来源:TestModelRangeFan.py

示例4: RunTestTableToPoints

# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import deleteScratch [as 别名]
    arcpy.env.scratchWorkspace = TestUtilities.scratchGDB
    arcpy.ImportToolbox(toolbox, "Position")

    ################################################
    # Run Individual Geometry Importer Tests
    print "Testing all TableTo{Geometry} Models..."

    RunTestTableToPoints()
    RunTestTableToPolyline()
    RunTestTableToEllipse()
    RunTestTableToLOB()

    ################################################

    print "Deleting Scratch Workspace"
    TestUtilities.deleteScratch()

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
开发者ID:jeffbaranyi,项目名称:solutions-geoprocessing-toolbox,代码行数:33,代码来源:TestTableToGeometry.py

示例5: RunTest

# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import deleteScratch [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)
开发者ID:GISkev,项目名称:solutions-geoprocessing-toolbox,代码行数:77,代码来源:TestRangeFanByBearingAndTraversal.py

示例6: RunTest

# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import deleteScratch [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)
开发者ID:GISkev,项目名称:solutions-geoprocessing-toolbox,代码行数:93,代码来源:TestModelRangeRings.py

示例7: RunTest

# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import deleteScratch [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)
开发者ID:ACueva,项目名称:defense-and-intel-analysis-toolbox,代码行数:80,代码来源:TestCoordinateConversion.py

示例8: RunTest

# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import deleteScratch [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)
#.........这里部分代码省略.........
开发者ID:GISkev,项目名称:solutions-geoprocessing-toolbox,代码行数:103,代码来源:TestModelLocalPeaks.py

示例9: RunTest

# 需要导入模块: import TestUtilities [as 别名]
# 或者: from TestUtilities import deleteScratch [as 别名]

#.........这里部分代码省略.........
        # #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...")
            arcpy.ProjectRaster_management("inputSurface",localSurf,srWebMerc)
            #arcpy.CopyRaster_management("inputSurface", localSurf)
        except arcpy.ExecuteError:
            print("Error converting image service...")
            msgs = arcpy.GetMessages()
            print(msgs)
            sys.exit(-1)

        numberOfPeaks = 3

        ########################################################
        # Execute the Model under test:
        arcpy.FindLocalPeaks_MAoT(inputPolygonFC, numberOfPeaks, localSurf, outputPointsFC)
        ########################################################

        # 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")
        arcpy.CheckInExtension("3D")
开发者ID:chinasio,项目名称:solutions-geoprocessing-toolbox,代码行数:104,代码来源:TestModelLocalPeaks.py


注:本文中的TestUtilities.deleteScratch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。