ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • ヘルプ
  • Sign Out
ArcGIS Desktop

ArcGIS Online

組織のマッピング プラットフォーム

ArcGIS Desktop

完全なプロ仕様の GIS

ArcGIS Enterprise

エンタープライズ GIS

ArcGIS Developers

位置情報利用アプリの開発ツール

ArcGIS Solutions

各種業界向けの無料のテンプレート マップおよびテンプレート アプリケーション

ArcGIS Marketplace

組織で使えるアプリとデータを取得

  • ドキュメント
  • サポート
Esri
  • サイン イン
user
  • マイ プロフィール
  • サイン アウト

ArcMap

  • ホーム
  • はじめに
  • マップ
  • 解析
  • データ管理
  • ツール
  • エクステンション

OD コスト マトリックス レイヤーの作成 (Make OD Cost Matrix Layer)

  • 概要
  • 使用法
  • 構文
  • コードのサンプル
  • 環境
  • ライセンス情報

概要

OD (起点-終点) コスト マトリックス ネットワーク解析レイヤーを作成し、解析プロパティを設定します。ODコスト マトリックス解析レイヤーは、複数の出発地から複数の目的地までのコスト マトリックスを表すときに役立ちます。

使用法

  • このツールで解析レイヤーを作成した後は、[ロケーションの追加 (Add Locations)] ツールを使用して解析レイヤーにネットワーク解析オブジェクトを追加し、[解析の実行 (Solve)] ツールを使用して解析を実行し、[レイヤー ファイルの保存 (Save To Layer File)] ツールを使用して結果をディスクに保存することができます。

  • このツールをジオプロセシング モデルに使用するときは、モデルをツールとして動作させる場合、出力ネットワーク解析レイヤーにモデル パラメーターを作成する必要があります。そうしないと、出力レイヤーはマップのコンテンツに追加されません。

構文

arcpy.na.MakeODCostMatrixLayer(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 ターン ポリシーを指定します。以下では、このパラメーターで選択できる値と、ジャンクションので接続におけるそれぞれの意味について示します。

  • ALLOW_UTURNS —任意の数の接続されたエッジを持つジャンクションで U ターンを許可します。これがデフォルトです。
  • NO_UTURNS —ジャンクションの接続にかかわらず、すべてのジャンクションで U ターンを禁止します。ただし、この設定が選択されている場合でも、ネットワーク ロケーションでは U ターンが許可されます。同様に、個々のネットワーク ロケーションの CurbApproach プロパティで U ターンを禁止するように設定できます。
  • ALLOW_DEAD_ENDS_ONLY —1 つの隣接エッジを持つジャンクション (行き止まり) を除くすべてのジャンクションでの U ターンを禁止します。
  • ALLOW_DEAD_ENDS_AND_INTERSECTIONS_ONLY —2 つの隣接するエッジが接するジャンクションでの U ターンを禁止します。ただし、交差点 (3 つ以上の隣接エッジを持つジャンクション) および行き止まり (1 つの隣接エッジを持つジャンクション) では U ターンを許可します。ネットワークには、道路セグメントの中間に無関係のジャンクションが存在する場合があります。このオプションは、これらの場所で車両が U ターンすることを防ぎます。

U ターン ポリシーをさらに正確に定義する必要がある場合、グローバル ターン遅延エバリュエーターをネットワーク コスト属性に追加するか、すでに存在する場合はそれを調整することを検討してください。その際、逆ターンの設定には特に注意が必要です。また、ネットワーク ロケーションの CurbApproach プロパティの設定についても調べてください。

String
restriction_attribute_name
[restriction_attribute_name,...]
(オプション)

解析中に適用される規制属性のリスト。

String
hierarchy
(オプション)
  • USE_HIERARCHY — 階層属性を解析に使用します。階層を使用すると、解析は下位ランクのエッジよりも上位ランクのエッジを優先します。階層解析は、より高速で、運転者が遠回りであっても一般道路の代わりに高速道路を利用する状況をシミュレートするのに使用できます。このオプションは入力ネットワーク データセットが階層属性を持つ場合のみ有効です。
  • NO_HIERARCHY —階層属性を解析に使用しません。階層を使用しないことで、ネットワーク データセットの正確なルートが検索されます。

解析を実行するネットワーク データセットに使用する階層属性が定義されていない場合、パラメーターは使用されません。この場合、「"#"」をパラメーター値として使用します。

Boolean
hierarchy_settings
(オプション)

レガシー:

10 より前のバージョンでは、このパラメーターによって、解析のためにネットワーク データセット構築時のデフォルトの階層範囲から階層範囲の変更を行うことを許可していました。バージョン 10 では、このパラメーターはサポートされていないため、空の文字列を指定する必要があります。解析のために階層範囲を変更したい場合、ネットワーク データセットのデフォルトの階層範囲を更新します。

Network Analyst Hierarchy Settings
output_path_shape
(オプション)
  • NO_LINES —出力ルートに形状は生成されません。これは、起点と終点の数が多く、OD コスト マトリックス テーブルだけが必要 (出力ライン形状は不要) な場合に便利です。
  • STRAIGHT_LINES —出力ルート形状は各起点~終点間を結ぶ 1 本の直線になります。

どの出力形状のタイプを選択するかに関係なく、常に最適なルートはユークリッド距離ではなくネットワーク インピーダンスによって決定されます。ネットワーク解析の結果は同じですが、ルート形状のみが異なります。

String
time_of_day
(オプション)

起点からの出発日時を示します。

交通量ベースのインピーダンス属性を選択した場合、ここで指定した時刻での動的な交通状況に対する解決策が生成されます。日時は、2012/05/14 10:30 のように指定できます。

特定の日付を使用する代わりに、次の日付を使用して曜日を指定することができます。

  • 今日 - 1899/12/30
  • 日 - 1899/12/31
  • 月 - 1900/1/1
  • 火 - 1900/1/2
  • 水 - 1900/1/3
  • 木 - 1900/1/4
  • 金 - 1900/1/5
  • 土 - 1900/1/6
たとえば、移動を火曜日の 5:00 PM に開始するよう指定するには、パラメーター値を「1900/1/2 5:00 PM」に指定します。

Date

派生した出力

名前説明データ タイプ
output_layer

新しく作成されたネットワーク解析レイヤー。

Network Analyst レイヤー

コードのサンプル

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)

環境

  • 現在のワークスペース

ライセンス情報

  • Basic: はい
  • Standard: はい
  • Advanced: はい

関連トピック

  • OD コスト マトリックス解析
  • 階層を使用したネットワーク解析について
  • 解析ツールセットの概要
  • ネットワーク解析レイヤーとは

ArcGIS Desktop

  • ホーム
  • ドキュメント
  • サポート

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

Esri について

  • 会社概要
  • 採用情報
  • Esri ブログ
  • ユーザ カンファレンス
  • デベロッパ サミット
Esri
ご意見・ご感想をお寄せください。
Copyright © 2021 Esri. | プライバシー | リーガル