arcpy.na.Solve(in_network_analysis_layer, {ignore_invalids}, {terminate_on_solve_error}, {simplification_tolerance}, {overrides})
|
名称
|
说明
|
数据类型
|
|
in_network_analysis_layer
|
要进行分析计算的网络分析图层。
|
Network Analyst Layer
|
|
ignore_invalids
(可选)
|
指定是否忽略无效的输入位置。 通常,如果无法 在网络上定位,则位置无效。 当无效位置被忽略时,求解程序将跳过它们并尝试使用剩余位置执行分析。
默认值将匹配指定 in_network_analysis_layer 值的 ignoreInvalidLocations 属性。
|
Boolean
|
|
terminate_on_solve_error
(可选)
|
指定在求解过程中遇到错误时是否终止工具运行。
TERMINATE—该工具在求解程序遇到错误时将终止工具运行。 这是默认设置。 使用该选项时,如果工具因求解程序遇到错误而停止,则不创建任何 Result 对象。 查看来自 ArcPy 对象的地理处理消息。
CONTINUE—即使求解程序遇到错误,该工具也不停止,而是继续运行。 求解器返回的所有错误消息都将转换为警告消息。 使用该选项时,将始终创建 Result 对象,并将 Result 对象的 maxSeverity 属性设置为 1。 将 Result 对象的 getOutput 方法和索引值 1 结合使用可确定求解程序是否成功。
|
Boolean
|
|
simplification_tolerance
(可选)
|
容差确定输出几何的简化程度。 如果已指定了容差,容差必须大于零。 可以选择首选单位;默认单位为十进制度。
指定简化容差会减少渲染路径或服务区的时间。 但缺点是,简化几何移除了折点,这样会降低以更大比例输出的空间精确度。
由于带两个折点的线不能再简化,所以此参数对单一线段输出的绘制时间没有影响,例如直线路线、OD 成本矩阵线和位置分配线。
|
Linear Unit
|
|
overrides
(可选)
|
|
String
|
派生输出
|
名称
|
说明
|
数据类型
|
|
output_layer
|
已解决的网络分析图层。
|
Network Analyst Layer
|
|
solve_succeeded
|
指示求解是否成功的布尔值。
|
Boolean
|
代码示例
使用所有参数运行此工具
arcpy.na.Solve("Route", "HALT", "TERMINATE", "10 Meters")
以下独立 Python 脚本演示了如何使用 Solve 函数执行最近设施点分析并将结果保存到图层文件中。
# 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
import os
try:
#Set environment settings
output_dir = "C:/Data"
#The NA layer's data will be saved to the workspace specified here
env.workspace = os.path.join(output_dir, "Output.gdb")
env.overwriteOutput = True
#Set local variables
input_gdb = "C:/Data/Paris.gdb"
network = os.path.join(input_gdb, "Transportation", "ParisMultimodal_ND")
layer_name = "ClosestWarehouse"
travel_mode = "Driving Time"
facilities = os.path.join(input_gdb, "Analysis", "Warehouses")
incidents = os.path.join(input_gdb, "Analysis", "Stores")
output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")
#Create a new closest facility analysis layer.
result_object = arcpy.na.MakeClosestFacilityAnalysisLayer(network,
layer_name, travel_mode,
"TO_FACILITIES",
number_of_facilities_to_find=1)
#Get the layer object from the result object. The closest facility layer can
#now be referenced using the layer object.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the closest facility layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
facilities_layer_name = sublayer_names["Facilities"]
incidents_layer_name = sublayer_names["Incidents"]
#Load the warehouses as Facilities using the default field mappings and
#search tolerance
arcpy.na.AddLocations(layer_object, facilities_layer_name,
facilities, "", "")
#Load the stores as Incidents. Map the Name property from the NOM field
#using field mappings
field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
incidents_layer_name)
field_mappings["Name"].mappedFieldName = "NOM"
arcpy.na.AddLocations(layer_object, incidents_layer_name, incidents,
field_mappings, "")
#Solve the closest facility layer
arcpy.na.Solve(layer_object)
#Save the solved closest facility layer as a layer file on disk
layer_object.saveACopy(output_layer_file)
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 occurred on line %i" % tb.tb_lineno)
print(str(e))