サマリー
OD (起点-終点) コスト マトリックス ネットワーク解析レイヤーを作成し、解析プロパティを設定します。ODコスト マトリックス解析レイヤーは、複数の出発地から複数の目的地までのコスト マトリックスを表すときに役立ちます。
使用法
このツールで解析レイヤーを作成した後は、[ロケーションの追加 (Add Locations)] ツールを使用して解析レイヤーにネットワーク解析オブジェクトを追加し、[解析の実行 (Solve)] ツールを使用して解析を実行し、[レイヤー ファイルの保存 (Save To Layer File)] ツールを使用して結果をディスクに保存することができます。
このツールをジオプロセシング モデルに使用するときは、モデルをツールとして動作させる場合、出力ネットワーク解析レイヤーにモデル パラメーターを作成する必要があります。そうしないと、出力レイヤーはマップのコンテンツに追加されません。
構文
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}, {time_of_day})| パラメーター | 説明 | データ タイプ | 
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_[Impedance]] プロパティが追加されます。  | String | 
UTurn_policy (オプション)  | ジャンクションでの U ターン ポリシー。U ターンを許可するということは、解析においてジャンクションで方向転換し、同じ道路を引き返すことができるということを意味します。 ジャンクションが道路の交差と行き止まりを表すことを前提に、さまざまな車両が、一部のジャンクションでは方向転換でき、他のジャンクションでは方向転換できない、というように設定できます。これは、ジャンクションが交差と行き止まりのどちらを表すかによって変わります。これに対応するには、ジャンクションに接続するエッジの数 (ジャンクションでのノードへの接続数) によって、暗黙的に U ターン ポリシーを指定します。以下では、このパラメーターで選択できる値と、ジャンクションので接続におけるそれぞれの意味について示します。 
 U ターン ポリシーをさらに正確に定義する必要がある場合、グローバル ターン遅延エバリュエーターをネットワーク コスト属性に追加するか、すでに存在する場合はそれを調整することを検討してください。その際、逆ターンの設定には特に注意が必要です。また、ネットワーク ロケーションの CurbApproach プロパティの設定についても調べてください。  | String | 
restriction_attribute_name [restriction_attribute_name,...] (オプション)  | 解析中に適用される規制属性のリスト。  | String | 
hierarchy (オプション)  | 
 解析を実行するネットワーク データセットに使用する階層属性が定義されていない場合、パラメーターは使用されません。この場合、「"#"」をパラメーター値として使用します。  | Boolean | 
hierarchy_settings (オプション)  | Network Analyst Hierarchy Settings | |
output_path_shape (オプション)  | 
 どの出力形状のタイプを選択するかに関係なく、常に最適なルートはユークリッド距離ではなくネットワーク インピーダンスによって決定されます。ネットワーク解析の結果は同じですが、ルート形状のみが異なります。  | String | 
time_of_day (オプション)  | 起点からの出発日時を示します。 交通量ベースのインピーダンス属性を選択した場合、ここで指定した時刻での動的な交通状況に対する解決策が生成されます。日時は、2012/05/14 10:30 のように指定できます。 特定の日付を使用する代わりに、次の日付を使用して曜日を指定することができます。 
  | Date | 
コードのサンプル
MakeODCostMatrixLayer (OD コスト マトリックス レイヤーの作成) の例 1 (Python ウィンドウ)
必須パラメーターのみを使用してツールを実行します。
network = "C:/Data/Paris.gdb/Transportation/ParisMultimodal_ND"
arcpy.na.MakeODCostMatrixLayer(network, "DrivetimeCosts", "DriveTime")
MakeODCostMatrixLayer (OD コスト マトリックス レイヤーの作成) の例 2 (Python ウィンドウ)
すべてのパラメーターを使用してツールを実行します。
network = "C:/Data/Paris.gdb/Transportation/ParisMultimodal_ND"
arcpy.na.MakeODCostMatrixLayer(network, "DrivetimeCosts", "DriveTime", 10, 20,
                                ["Meters", "DriveTime"], "NO_UTURNS",
                                ["Oneway"], "USE_HIERARCHY", "", "NO_LINES")
MakeODCostMatrixLayer (OD コスト マトリックス レイヤーの作成) の例 3 (ワークフロー)
次のスタンドアロン Python スクリプトは、MakeODCostMatrixLayer ツールを使用して、商品を倉庫からすべての店舗に 10 分以内の走行時間で配達する際の OD コスト マトリックスを作成する方法を示しています。
# 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"
    outNALayerName = "WarehouseToStoreDrivetimeMatrix"
    impedanceAttribute = "Drivetime"
    searchTolerance = "1000 Meters"
    accumulateAttributeName = ["Meters"]
    inOrgins = "Analysis/Warehouses"
    inDestinations = "Analysis/Stores"
    outLayerFile = "C:/data/output" + "/" + outNALayerName + ".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.
    outNALayer = arcpy.na.MakeODCostMatrixLayer(inNetworkDataset, outNALayerName,
                                                impedanceAttribute, 10, "",
                                                accumulateAttributeName)
    
    #Get the layer object from the result object. The OD cost matrix layer can 
    #now be referenced using the layer object.
    outNALayer = outNALayer.getOutput(0)
    
    #Get the names of all the sublayers within the OD cost matrix layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later
    originsLayerName = subLayerNames["Origins"]
    destinationsLayerName = subLayerNames["Destinations"]
    
    #Load the warehouse locations as origins using a default field mappings and
    #a search tolerance of 1000 Meters.
    arcpy.na.AddLocations(outNALayer, originsLayerName, inOrgins, "",
                          searchTolerance)
    
    #Load the store locations as destinations and map the NOM field from stores
    #features as Name property using field mappings
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, destinationsLayerName)
    fieldMappings["Name"].mappedFieldName = "NOM"
    arcpy.na.AddLocations(outNALayer, destinationsLayerName, inDestinations, 
                          fieldMappings, searchTolerance)
    
    #Solve the OD cost matrix layer
    arcpy.na.Solve(outNALayer)
    
    #Save the solved OD cost matrix layer as a layer file on disk with relative
    #paths
    arcpy.management.SaveToLayerFile(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 occurred on line %i" % tb.tb_lineno
    print str(e)
MakeODCostMatrixLayer (OD コスト マトリックス レイヤーの作成) の例 4 (ワークフロー)
次のスタンドアロン Python スクリプトは、サブレイヤーへのアクセス方法、入力および出力レイヤーの結合方法、入力元および入力先から出力ライン レイヤーへのフィールド値の転送方法を示しています。
# Name: MakeODCostMatrixLayer_Workflow2.py
# Description: Find the travel time to the closest hospital from each census
#               tract and join the travel time and hospital name to the input
#               tracts.
# Requirements: Network Analyst Extension
import datetime
#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/SanFrancisco.gdb"
    env.overwriteOutput = True
    #Set inputs and outputs
    inNetworkDataset = "Transportation/Streets_ND"
    inOrigins = "Analysis/TractCentroids"
    inDestinations = "Analysis/Hospitals"
    outNALayerName = "HospitalsOD"
    outTracts_withOD = "Analysis/TractCentroids_withOD"
    #Define some OD cost matrix analysis settings
    #Optimize based on travel time
    impedanceAttribute = "TravelTime"
    #Calculate the total distance, even though the analysis is optimizing time
    accumulate_attrs = ["Meters"]
    #Find only the closest hospital
    num_hospitals_to_find = 1
    #Set the time of day for the analysis to 6PM on a generic Monday.
    start_time = datetime.datetime(1900, 1, 1, 18, 0, 0)
    #Don't output line shapes (output Lines will still list travel times)
    out_lines = "NO_LINES"
    #Create a new OD cost matrix layer.
    outODResultObject = arcpy.na.MakeODCostMatrixLayer(inNetworkDataset,
                    outNALayerName, impedanceAttribute,
                    default_number_destinations_to_find=num_hospitals_to_find,
                    accumulate_attribute_name=accumulate_attrs,
                    output_path_shape=out_lines, time_of_day=start_time)
    #Get the layer object from the result object. The OD layer can
    #now be referenced using the layer object.
    outNALayer = outODResultObject.getOutput(0)
    #Get the names of all the sublayers within the OD layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Store the layer names for later use
    originsLayerName = subLayerNames["Origins"]
    destinationsLayerName = subLayerNames["Destinations"]
    #The input census tract data has a unique ID field that can be transferred
    #to the analysis layer. Add the field, and then use field mapping to
    #transfer the values.
    arcpy.na.AddFieldToAnalysisLayer(outNALayer, originsLayerName,
                                                        "Tract_ID", "TEXT")
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, originsLayerName)
    fieldMappings["Tract_ID"].mappedFieldName = "ID"
    #Load the census tracts as origins.
    arcpy.na.AddLocations(outNALayer, originsLayerName, inOrigins,
                            fieldMappings, "",
                            exclude_restricted_elements = "EXCLUDE")
    #Map the input hospital NAME field to a new Hospital_Name field in
    #Destinations
    arcpy.na.AddFieldToAnalysisLayer(outNALayer, destinationsLayerName,
                                                        "Hospital_Name", "TEXT")
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer,
                                                        destinationsLayerName)
    fieldMappings["Hospital_Name"].mappedFieldName = "NAME"
    #Load the hospitals as desinations.
    arcpy.na.AddLocations(outNALayer, destinationsLayerName, inDestinations,
                            fieldMappings, "",
                            exclude_restricted_elements = "EXCLUDE")
    #Solve the OD layer
    arcpy.na.Solve(outNALayer)
    #Get sublayers
    #arcpy.mapping.ListLayers returns a list of layer objects containing the NA
    #layer itself (item 0) and each of the sublayers. Put these in a dictionary
    #with the sublayer names as the keys
    subLayers = dict((lyr.datasetName, lyr) for lyr in arcpy.mapping.ListLayers(outNALayer)[1:])
    OriginsSubLayer = subLayers["Origins"]
    DestinationsSubLayer = subLayers["Destinations"]
    LinesSubLayer = subLayers["ODLines"]
    #Transfer the tract ID from the input Origins to the output Lines
    arcpy.management.JoinField(LinesSubLayer, "OriginID",
                            OriginsSubLayer, "ObjectID", "Tract_ID")
    #Transfer the hospital name from the input Destinations to the output Lines
    arcpy.management.JoinField(LinesSubLayer, "DestinationID",
                            DestinationsSubLayer, "ObjectID", "Hospital_Name")
    #Transfer fields of interest (hospital name, TravelTime cost, and other
    #accumulated costs) from the output Lines to the input census tracts
    #feature class using the Tract_ID field
    output_impedance_fieldname = "Total_" + impedanceAttribute
    fields_to_transfer = ["Hospital_Name", output_impedance_fieldname]
    for field in accumulate_attrs:
        fields_to_transfer.append("Total_" + field)
    arcpy.management.CopyFeatures(inOrigins, outTracts_withOD)
    arcpy.management.JoinField(outTracts_withOD, "ID",
                            LinesSubLayer, "Tract_ID", fields_to_transfer)
    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)
環境
ライセンス情報
- ArcGIS Desktop Basic: はい
 - ArcGIS Desktop Standard: はい
 - ArcGIS Desktop Advanced: はい