arcpy.na.MakeODCostMatrixAnalysisLayer(network_data_source, {layer_name}, {travel_mode}, {cutoff}, {number_of_destinations_to_find}, {time_of_day}, {time_zone}, {line_shape}, {accumulate_attributes}, {ignore_invalid_locations}, {analysis_geodatabase}, {analysis_feature_dataset_name})
|
名前
|
説明
|
データ タイプ
|
|
network_data_source
|
ネットワーク解析が実行されるネットワーク データセットまたはサービス。
このパラメーターは、次のいずれかを使用して指定できます。
ポータル URL を使用するには、ルート検索権限があるアカウントでポータルにサイン インする必要があります。
Python でポータルにサイン インする方法の詳細
ルート検索サービスを使用したネットワーク解析についての詳細
ArcGIS Online を使用してルート検索サービスが入力ネットワークとして構成されている ArcGIS Online または ArcGIS Enterprise ポータルを使用している場合、解析を実行するとクレジットが消費され、特定の制限 (許可された入力の数など) の対象になります。
ネットワーク解析におけるクレジット消費量と解析の制限の詳細
|
Network Dataset Layer; String
|
|
layer_name
(オプション)
|
作成されるネットワーク解析レイヤーの名前。
|
String
|
|
travel_mode
(オプション)
|
解析で使用される移動モードの名前。 移動モードは、移動規制や U ターン ポリシーなど、歩行者、車、トラック、その他の交通手段がネットワークをどのように移動するかを決定するネットワーク設定のコレクションを表します。 移動モードは、ネットワーク データ ソースに対して定義されます。
arcpy.na.TravelMode オブジェクトおよび移動モードの有効な JSON 表現を含む文字列もこのパラメーターの入力として使用できます。
|
String
|
|
cutoff
(オプション)
|
指定された起点における終点の検索を停止するインピーダンス値。 この値は、選択した移動モードで使用されているインピーダンス属性の単位になります。 この制限を超える終点は検索されません。 このカットオフ値は、起点サブレイヤーのカットオフ値を個別に指定することで、起点ごとにオーバーライドできます。 デフォルトでは、解析にカットオフは使用されません。
|
Double
|
|
number_of_destinations_to_find
(オプション)
|
起点ごとに検索を実行する終点の数。 起点サブレイヤーの TargetDestinationCount プロパティの値を個別に指定することで、デフォルトをオーバーライドできます。 デフォルトでは、制限は使用されず、すべての終点が検索されます。
|
Long
|
|
time_of_day
(オプション)
|
起点からの出発日時。
交通量ベースのインピーダンス属性を選択した場合、ここで指定した時刻での動的な交通状況に対する解決策が生成されます。 日時は、2012/05/14 10:30 のように指定できます。
特定の静的な日付の代わりに曜日または現在の日付をモデル化するには、次のいずれかの特殊な日付を使用するように解析を構成します。
Today—12/30/1899
Sunday—12/31/1899
Monday—1/1/1900
Tuesday—1/2/1900
Wednesday—1/3/1900
Thursday—1/4/1900
Friday—1/5/1900
Saturday—1/6/1900
ネットワーク解析での日時の使用と解釈の詳細
|
Date
|
|
time_zone
(オプション)
|
時刻 パラメーターのタイム ゾーン。
|
String
|
|
line_shape
(オプション)
|
出力ライン形状を指定します。
指定した出力形状のタイプに関係なく、常に最適なルートはユークリッド距離ではなくネットワーク インピーダンスによって決定されます。 これは、ルート形状のみが異なり、ネットワークの基となっているトラバースは同じであることを意味します。
|
String
|
|
accumulate_attributes
[accumulate_attributes,...]
(オプション)
|
解析中に累積されるコスト属性のリスト。 これらの累積属性は、参考情報としてのみ使用されます。解析では、指定されている移動モードで使用されるコスト属性のみが使用されます。
累積されるコスト属性ごとに、ネットワーク解析の出力フィーチャに Total_ [Impedance] プロパティが入力されます。
このパラメーターは、ネットワーク データ ソースが ArcGIS Online サービスであるか、ネットワーク データ ソースが累積をサポートしていないバージョンの Portal for ArcGIS のサービスである場合には使用できません。
|
String
|
|
ignore_invalid_locations
(オプション)
|
無効な入力ロケーションを除外するかどうかを指定します。 通常、ネットワーク上で特定できないロケーションは無効になります。 無効なロケーションを除外する場合は、そのロケーションがスキップされ、残りのロケーションを使用して解析が実行されます。
|
Boolean
|
|
analysis_geodatabase
(オプション)
|
新しいネットワーク解析レイヤーのサブレイヤー データが格納されるファイル ジオデータベース ワークスペース。 このパラメーターが指定されていない場合、サブレイヤー データは、通常プロジェクト ジオデータベースである 現在のワークスペース ジオプロセシング環境に作成されます。
ネットワーク解析レイヤーの解析データ ソースの詳細
|
Workspace
|
|
analysis_feature_dataset_name
(オプション)
|
ネットワーク解析レイヤーのサブレイヤー データを格納するために、このツールが解析ジオデータベースに作成する新しいフィーチャ データセットに使用する名前。 指定しない場合、ランダムな一意の名前を使用してフィーチャ データセットが作成されます。
ネットワーク解析レイヤーの解析データ ソースの詳細
|
String
|
派生した出力
|
名前
|
説明
|
データ タイプ
|
|
out_network_analysis_layer
|
新しく作成されたネットワーク解析レイヤー。
|
Network Analyst Layer
|
コードのサンプル
MakeODCostMatrixAnalysisLayer の例 1 (Python ウィンドウ)
必須パラメーターのみを使用して、ツールを実行します。
network = "C:/Data/Paris.gdb/Transportation/ParisMultimodal_ND"
arcpy.na.MakeODCostMatrixAnalysisLayer(network, "DrivetimeCosts")
MakeODCostMatrixAnalysisLayer の例 2 (Python ウィンドウ)
すべてのパラメーターを使用してツールを実行します。
network = "C:/Data/Paris.gdb/Transportation/ParisMultimodal_ND"
arcpy.na.MakeODCostMatrixAnalysisLayer(network, "DrivetimeCosts",
"Driving Time", 10, 20, "1/1/1900 9:00 AM",
"UTC", "NO_LINES", ["Meters", "TravelTime"])
MakeODCostMatrixAnalysisLayer の例 3 (ワークフロー)
次のスタンドアロン Python スクリプトは、MakeODCostMatrixAnalysisLayer 関数を使用して、商品を倉庫からすべての店舗に 10 分以内の走行時間で配達する際の OD コスト マトリックスを作成する方法を示しています。
# Name: MakeODCostMatrixAnalysisLayer_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
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 = "WarehouseToStoreDrivetimeMatrix"
travel_mode = "Driving Time"
search_tolerance = "1000 Meters"
origins = os.path.join(input_gdb, "Analysis", "Warehouses")
destinations = os.path.join(input_gdb, "Analysis", "Stores")
output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")
#Create a new OD Cost matrix layer. We wish to find all stores within a 10
#minute cutoff.
result_object = arcpy.na.MakeODCostMatrixAnalysisLayer(network, layer_name,
travel_mode, 10)
#Get the layer object from the result object. The OD cost matrix layer can
#now be referenced using the layer object.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the OD cost matrix layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
origins_layer_name = sublayer_names["Origins"]
destinations_layer_name = sublayer_names["Destinations"]
#Load the warehouse locations as origins using a default field mappings and
#a search tolerance of 1000 Meters.
arcpy.na.AddLocations(layer_object, origins_layer_name, origins, "",
search_tolerance)
#Load the store locations as destinations and map the NOM field from stores
#features as Name property using field mappings
field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
destinations_layer_name)
field_mappings["Name"].mappedFieldName = "NOM"
arcpy.na.AddLocations(layer_object, destinations_layer_name, destinations,
field_mappings, search_tolerance)
#Solve the OD cost matrix layer
arcpy.na.Solve(layer_object)
#Save the solved OD cost matrix 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))
MakeODCostMatrixAnalysisLayer の例 4 (ワークフロー)
次のスタンドアロン Python スクリプトは、サブレイヤーへのアクセス方法、入力および出力レイヤーの結合方法、入力元および入力先から出力ライン レイヤーへのフィールド値の転送方法を示しています。
レガシー:
GetNASublayer 関数を使用して、ネットワーク解析レイヤーのサブレイヤーを取得できます。 これは ArcGIS Pro 2.7 で導入されました。 以前のソフトウェア バージョンでは、サブレイヤー名をワイルドカードとして使用するネットワーク解析の Layer オブジェクトの listLayers メソッドを使用することがネットワーク解析レイヤーのサブレイヤー オブジェクトを取得する最適な方法でした。
# Name: MakeODCostMatrixAnalysisLayer_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 system modules
import datetime
import os
import arcpy
try:
# Set environment settings
output_dir = "C:/Data"
#The NA layer's data will be saved to the workspace specified here
arcpy.env.workspace = os.path.join(output_dir, "Output.gdb")
arcpy.env.overwriteOutput = True
# Set inputs and outputs
input_gdb = "C:/Data/SanFrancisco.gdb"
network = os.path.join(input_gdb, "Transportation", "Streets_ND")
origins = os.path.join(input_gdb, "Analysis", "TractCentroids")
destinations = os.path.join(input_gdb, "Analysis", "Hospitals")
output_features = "TractCentroids_withOD"
# Define some OD cost matrix analysis settings
layer_name = "HospitalsOD"
# User settings for driving
travel_mode = "Driving Time"
# Calculate the total distance, even though the analysis is optimizing time
accumulate_attributes = ["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.
result_object = arcpy.na.MakeODCostMatrixAnalysisLayer(network, layer_name,
travel_mode,
number_of_destinations_to_find=num_hospitals_to_find,
time_of_day=start_time, line_shape=out_lines,
accumulate_attributes=accumulate_attributes)
# Get the layer object from the result object. The OD layer can
# now be referenced using the layer object.
layer_object = result_object.getOutput(0)
# Get the names of all the sublayers within the OD layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
# Store the layer names for later use
origins_layer_name = sublayer_names["Origins"]
destinations_layer_name = sublayer_names["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(layer_object, origins_layer_name,
"Tract_ID", "TEXT")
field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
origins_layer_name)
field_mappings["Tract_ID"].mappedFieldName = "ID"
# Load the census tracts as origins.
arcpy.na.AddLocations(layer_object, origins_layer_name, origins,
field_mappings, "")
# Map the input hospital NAME field to a new Hospital_Name field in
# Destinations
arcpy.na.AddFieldToAnalysisLayer(layer_object, destinations_layer_name,
"Hospital_Name", "TEXT")
field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
destinations_layer_name)
field_mappings["Hospital_Name"].mappedFieldName = "NAME"
# Load the hospitals as desinations.
arcpy.na.AddLocations(layer_object, destinations_layer_name, destinations,
field_mappings, "")
# Solve the OD layer
arcpy.na.Solve(layer_object)
# Get sublayers
origins_sublayer = arcpy.na.GetNASublayer(layer_object, "Origins")
destinations_sublayer = arcpy.na.GetNASublayer(layer_object, "Destinations")
lines_sublayer = arcpy.na.GetNASublayer(layer_object, "ODLines")
# Use the JoinField tool to transfer OD Cost Matrix information to the
# output feature class
# Transfer the tract ID from the input Origins to the output Lines
arcpy.management.JoinField(lines_sublayer, "OriginID",
origins_sublayer, "ObjectID", "Tract_ID")
# Transfer the hospital name from the input Destinations to the output Lines
arcpy.management.JoinField(lines_sublayer, "DestinationID",
destinations_sublayer, "ObjectID", "Hospital_Name")
# Transfer fields of interest (hospital name, impedance attribute, and other
# accumulated costs) from the output Lines to a copy of the input census
# tracts feature class using the Tract_ID field
# Determine the impedance attribute
solver_props = arcpy.na.GetSolverProperties(layer_object)
impedance = solver_props.impedance
output_impedance_fieldname = "Total_" + impedance
fields_to_transfer = ["Hospital_Name", output_impedance_fieldname]
for field in accumulate_attributes:
fields_to_transfer.append("Total_" + field)
arcpy.management.CopyFeatures(origins, output_features)
arcpy.management.JoinField(output_features, "ID",
lines_sublayer, "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))
MakeODCostMatrixAnalysisLayer の例 5 (スタンドアロン スクリプト)
次のスタンドアロン Python スクリプトは、修正版の移動モードをネットワーク データセットから作成し、新しい OD コスト マトリックス レイヤーの作成時にこの移動モードを使用する方法を示します。
import json
network = r"C:/Data/SanFrancisco.gdb/Transportation/Streets_ND"
# Get all travel modes from the network dataset
travel_modes = arcpy.na.GetTravelModes(network)
# Get the Driving Distance travel mode
dd_travel_mode = travel_modes["Driving Distance"]
# Make a json representation of the travel mode
travel_mode_json = json.loads(str(dd_travel_mode))
# Modify the userHierarchy property to turn hierarchy off, and update the name
travel_mode_json["useHierarchy"] = False
travel_mode_json["name"] = "Driving Distance without Hierarchy"
# Create a new travel mode object from the modified json
new_travel_mode_object = arcpy.na.TravelMode(json.dumps(travel_mode_json))
# Use the new travel mode object to MakeODCostMatrixAnalysisLayer
# We could also pass in the json directly without first converting it to an object
arcpy.na.MakeODCostMatrixAnalysisLayer(network, "OD Without Hierarchy", new_travel_mode_object)