使用方法
语法
MakeClosestFacilityLayer(in_network_dataset, out_network_analysis_layer, impedance_attribute, {travel_from_to}, {default_cutoff}, {default_number_facilities_to_find}, {accumulate_attribute_name}, {UTurn_policy}, {restriction_attribute_name}, {hierarchy}, {hierarchy_settings}, {output_path_shape}, {time_of_day}, {time_of_day_usage})| 参数 | 说明 | 数据类型 | 
in_network_dataset  | 要执行最近设施点分析的网络数据集。  | Network Dataset Layer | 
out_network_analysis_layer  | 要创建的最近设施点网络分析图层的名称。  | String | 
impedance_attribute  | 分析过程中用作阻抗的成本属性。  | String | 
travel_from_to (可选)  | 指定设施点与事件点之间的行驶方向。 
 如果网络具有单向限制和因行驶方向而异的阻抗,则使用此选项可在该网络上查找到不同的设施点。例如,从事件点行驶到设施点时,可能需要 10 分钟,而从设施点行驶到事件点时,可能因该方向上的行驶时间不同而需要 15 分钟。  | String | 
default_cutoff (可选)  | 停止为指定事件点搜索设施点时所对应的默认阻抗值。可通过以下方式覆盖该默认值:在行驶方向为从事件点到设施点时,指定事件点的中断值;或者在行驶方向为从设施点到事件点时,指定设施点的中断值。  | Double | 
default_number_facilities_to_find (可选)  | 要按事件点查找的默认最近设施点数。可通过为事件点的 TargetFacilityCount 属性指定一个值来覆盖该默认值。  | Long | 
accumulate_attribute_name [accumulate_attribute_name,...] (可选)  | 分析过程中要累积的成本属性的列表。这些累积属性仅供参考;求解程序仅使用阻抗属性参数所指定的成本属性来计算路径。 对于每个累积的成本属性,均会向求解程序所输出的路径中添加一个 Total_[阻抗] 属性。  | String | 
UTurn_policy (可选)  | 指定将在交汇点处使用的 U 形转弯策略。允许 U 形转弯表示求解程序可以在交汇点处转向并沿同一街道往回行驶。考虑到交汇点表示街道交叉路口和死角,不同的车辆可以在某些交汇点转弯,而在其他交汇点则不行 - 这取决于交汇点是交叉路口还是死角。为适应此情况,U 形转弯策略参数由连接到交汇点的边数隐性指定,这称为交汇点价。此参数可接受的值如下所列;每个值的后面是根据交汇点价对其含义的描述。 
 如果您需要定义更加精确的 U 形转弯策略,可以考虑在网络成本属性中添加一个通用转弯延迟赋值器,或者如果存在的话,调整其设置,并特别注意反向转弯的配置。还可以设置网络位置的 CurbApproach 属性。  | String | 
restriction_attribute_name [restriction_attribute_name,...] (可选)  | 分析过程中要应用的限制属性的列表。  | String | 
hierarchy (可选)  | 
 如果未在用于执行分析的网络数据集中定义等级属性,该参数将不可用。  | Boolean | 
hierarchy_settings (可选)  | 旧版本:在版本 10 之前,可使用此参数将网络数据集中建立的默认等级范围更改为其他范围以用于分析。而版本 10 中不再支持此参数,并且应将其指定为空字符串。要更改等级范围以进行分析,请更新网络数据集中的默认等级范围。  | Network Analyst Hierarchy Settings | 
output_path_shape (可选)  | 为分析所输出的路径要素指定形状类型。 
 无论选择何种输出形状类型,最佳路径始终由网络阻抗(而非欧氏距离)决定。这表示只是路径形状不同,而对网络进行的基础遍历则相同。  | String | 
time_of_day (可选)  | 指定路径应该开始或结束的时间和日期。对该值的解释取决于是将“时间用法”设置为路径的起始时间还是终止时间。 如果您已经选择了基于流量的阻抗属性,将会根据特定的某天某时的动态交通状况来生成解决方案。日期和时间可被指定为 5/14/2012 10:30 AM。 可使用以下日期来指定一周中的每一天,而无需使用特定的日期: 
  | Date | 
time_of_day_usage (可选)  | 指示“时间”参数值是表示路径的到达时间还是离开时间。 
  | String | 
派生输出
| 名称 | 说明 | 数据类型 | 
| output_layer | 新创建的网络分析图层。  | 网络分析图层 | 
代码示例
仅使用必需参数执行此工具。
network = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
arcpy.na.MakeClosestFacilityLayer(network, "ClosestFireStations", "TravelTime")使用所有参数执行此工具。
network = "C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
arcpy.na.MakeClosestFacilityLayer(network, "ClosestHospitals", "TravelTime",
                                    "TRAVEL_TO", 5 ,3, ["Meters", "TravelTime"],
                                    "ALLOW_UTURNS", ["Oneway"], "USE_HIERARCHY",
                                    "", "TRUE_LINES_WITH_MEASURES")以下独立 Python 脚本演示了如何使用 MakeClosestFacilityLayer 工具查找距商店位置最近的仓库。
# Name: MakeClosestFacilityLayer_Workflow.py
# Description: 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"
    impedance = "DriveTime"
    accumulate_attributes = ["Meters"]
    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. 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.
    result_object = arcpy.na.MakeClosestFacilityLayer(network, layer_name,
                                                   impedance, "TRAVEL_TO",
                                                   "", 1, accumulate_attributes,
                                                   "NO_UTURNS")
    #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))环境
许可信息
- Basic: 是
 - Standard: 是
 - Advanced: 是