解决 (网络分析)

摘要

基于网络位置和属性解决网络分析图层问题。

用法

语法

Solve_na (in_network_analysis_layer, {ignore_invalids}, {terminate_on_solve_error})
参数说明数据类型
in_network_analysis_layer

要进行分析计算的网络分析图层。

Network Analyst Layer
ignore_invalids
(可选)
  • SKIP解决程序将跳过未定位的网络位置而仅根据有效的网络位置来解决分析图层。如果这些位置位于不可遍历的元素上或具有其他错误,解决程序仍会继续解决。如果您了解您的网络位置并不完全正确,但是想对有效的网络位置解决,此选项很有用。
  • HALT如果存在无效位置,则不执行解决。您随后可对这些无效位置进行校正,然后重新运行分析。

对于多路径配送网络分析图层,由于多路径配送解决程序要求所有网络位置都有效,因此将 HALT 作为参数值。

Boolean
terminate_on_solve_error
(可选)
  • TERMINATE该工具将在解决程序遇到错误时无法执行操作。这是默认设置。使用该选项时,如果工具因解决程序遇到错误而无法执行操作,则不创建任何结果对象。您应通过 ArcPy 对象获取地理处理消息。
  • CONTINUE即使解决程序遇到错误,该工具也不停止,而是继续执行操作。解决程序返回的所有错误消息都将转换为警告消息。使用该选项时,即使解决程序遇到错误,也始终创建结果对象,并将结果对象的 maxSeverity 属性设置为 1。将结果对象的 getOutputo 方法和索引值 1 结合使用可确定解决程序是否成功。
Boolean

代码示例

解决示例 1(Python 窗口)

使用所有参数执行工具。

import arcpy
arcpy.Solve_na("Route","HALT","TERMINATE")
解决示例 2(工作流)

以下独立 Python 脚本演示了如何使用“解决”工具执行最近设施点分析并将结果保存到图层文件中。

# Name: Solve_Workflow.py
# Description: Solve a closest facility analysis to find the closest warehouse 
#              from the store locations and save the results to a layer file on 
#              disk.
# Requirements: Network Analyst Extension 

#Import system modules
import arcpy
from arcpy import env

try:
    #Check out the Network Analyst extension license
    arcpy.CheckOutExtension("Network")

    #Set environment settings
    env.workspace = "C:/data/Paris.gdb"
    env.overwriteOutput = True
    
    #Set local variables
    inNetworkDataset = "Transportation/ParisMultimodal_ND"
    outNALayer = "ClosestWarehouse"
    impedanceAttribute = "Drivetime"
    accumulateAttributeName = ["Meters"]
    inFacilities = "Analysis/Warehouses"
    inIncidents = "Analysis/Stores"
    fieldMappings = "Name NOM #"
    outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr"
    
    #Create a new closest facility analysis layer. Apart from finding the drive 
    #time to the closest warehouse, we also want to find the total distance. So
    #we will accumulate the "Meters" impedance attribute.
    arcpy.MakeClosestFacilityLayer_na(inNetworkDataset,outNALayer,
                                      impedanceAttribute,"TRAVEL_TO","",1,
                                      accumulateAttributeName,"NO_UTURNS")
    
    #Load the warehouses as Facilities using the default field mappings and 
    #search tolerance
    arcpy.AddLocations_na(outNALayer,"Facilities",inFacilities,"","")
    
    #Load the Stores as Incidents. Map the Name property from the NOM field
    arcpy.AddLocations_na(outNALayer,"Incidents",inIncidents,fieldMappings,"")
    
    #Solve the closest facility layer
    arcpy.Solve_na(outNALayer)
    
    #Save the solved closest facility layer as a layer file on disk using
    #relative paths
    arcpy.SaveToLayerFile_management(outNALayer,outLayerFile,"RELATIVE")
    
    print "Script completed successfully"

except Exception as e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "An error occured on line %i" % tb.tb_lineno
    print str(e)

环境

相关主题


7/10/2012