创建 OD 成本矩阵图层 (网络分析)
摘要
创建起点-目的地 (OD) 成本矩阵网络分析图层并设置其分析属性。OD 成本矩阵分析图层对于描述从一组起始位置到一组目的地位置的成本矩阵十分有用。
用法
语法
MakeODCostMatrixLayer_na (in_network_dataset, out_network_analysis_layer, impedance_attribute, {default_cutoff}, {default_number_destinations_to_find}, {accumulate_attribute_name}, {UTurn_policy}, {restriction_attribute_name}, {hierarchy}, {hierarchy_settings}, {output_path_shape})
参数 | 说明 | 数据类型 |
in_network_dataset |
要执行 OD 成本矩阵分析的网络数据集。 | Network Dataset Layer |
out_network_analysis_layer |
要创建的 OD 成本矩阵网络分析图层的名称。 | String |
impedance_attribute |
分析过程中用作阻抗的成本属性。 | String |
default_cutoff (可选) |
中止为指定起点搜索目的地时对应的默认阻抗值。如果累积的阻抗大于中断值,则遍历停止。可通过指定起点的中断值来覆盖此默认值。 | Double |
default_number_destinations_to_find (可选) |
要为每个起点查找的默认目的地数。可通过为起点的 TargetDestinationCount 属性指定一个值来覆盖默认值。 | Long |
accumulate_attribute_name [accumulate_attribute_name,...] (可选) |
分析过程中要累积的成本属性的列表。这些累积属性仅供参考;求解程序仅使用阻抗属性参数所指定的成本属性来计算路径。 对于每个累积的成本属性,均会向求解程序所输出的路径中添加一个 Total_[阻抗] 属性。 | String |
UTurn_policy (可选) |
限制或允许停靠点间网络遍历过程中可能出现在交汇点处的 U 形转弯。
| String |
restriction_attribute_name [restriction_attribute_name,...] (可选) |
分析过程中要应用的约束属性的列表。 | String |
hierarchy (可选) |
如果未在用于执行分析的网络数据集中定义等级属性,该参数将不可用。在这种情况下,使用“#”作为参数值。 | Boolean |
hierarchy_settings (可选) |
旧版本: 在版本 10 之前,可使用此参数将网络数据集中建立的默认等级范围更改为其他范围以用于分析。而版本 10 中不再支持此参数,并且应将其指定为空字符串。如果您要更改等级范围以进行分析,请更新网络数据集中的默认等级范围。 | Network Analyst Hierarchy Settings |
output_path_shape (可选) |
无论选择何种输出 shape 类型,最佳路径始终由网络阻抗(而非欧氏距离)决定。这表示只是路径形状不同,而对网络进行的基础遍历则相同。 | String |
代码示例
MakeODCostMatrixLayer 示例 1(Python 窗口)
仅使用必需参数执行此工具
import arcpy arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/Paris.gdb" arcpy.MakeODCostMatrixLayer_na("Transportation/ParisNet","DrivetimeCosts", "Drivetime")
MakeODCostMatrixLayer 示例 2(Python 窗口)
使用所有参数执行此工具
import arcpy arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/Paris.gdb" arcpy.MakeODCostMatrixLayer_na("Transportation/ParisNet","DrivetimeCosts", "Drivetime",10,20,["Meters","Drivetime"], "NO_UTURNS",["Oneway"],"USE_HIERARCHY","", "NO_LINES")
MakeODCostMatrixLayer 示例 3(工作流)
以下独立 Python 脚本演示了如何使用 MakeODCostMatrixLayer 工具创建起点-目的地成本矩阵,用于将货物从仓库交付给距离仓库十分钟行程范围内的所有商店。
# Name: MakeODCostMatrixLayer_Workflow.py # Description: Create an origin-destination cost matrix for delivery of goods # from the warehouses to all stores within a 10-minute drive time # and save the results to a layer file on disk. Such a matrix can # be used as an input for logistics, delivery and routing analyses. # 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 = "WarehouseToStoreDrivetimeMatrix" impedanceAttribute = "Drivetime" accumulateAttributeName = ["Meters"] inOrgins = "Analysis/Warehouses" inDestinations = "Analysis/Stores" fieldMappings = "Name NOM #" outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr" #Create a new OD Cost matrix layer. We wish to find all stores within a 10 #minute cutoff. Apart from finding the drive time to the stores, we also #want to find the total distance. So we will accumulate the "Meters" #impedance attribute. arcpy.MakeODCostMatrixLayer_na(inNetworkDataset, outNALayer, impedanceAttribute, 10, "", accumulateAttributeName) #Load the warehouse locations as origins using a default field map that maps #the Name property using a name field from warehouse features. arcpy.AddLocations_na(outNALayer, "Origins", inOrgins, "","1000 Meters") #Load the store locations as destinations mapping the NOM field from stores #features as Name property arcpy.AddLocations_na(outNALayer, "Destinations", inDestinations, fieldMappings,"1000 Meters") #Solve the OD cost matrix layer arcpy.Solve_na(outNALayer) #Save the solved OD cost matrix layer as a layer file on disk with 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