arcpy.na.Directions(in_network_analysis_layer, file_type, out_directions_file, report_units, {report_time}, {time_attribute}, {language}, {style_name}, {stylesheet})
|
名前
|
説明
|
データ タイプ
|
|
in_network_analysis_layer
|
ルート案内を生成するネットワーク解析レイヤー。 ルート案内は、ルート、最寄り施設、および配車ルート ネットワーク解析レイヤーに対してのみ生成することができます。
注意:
ラスト マイル デリバリー解析レイヤーと廃棄物収集解析レイヤーではルート案内がサポートされていますが、このツールではこれらのタイプのレイヤーはサポートされていません。
|
Network Analyst Layer
|
|
file_type
|
出力されるルート案内ファイルに使用される形式を指定します。 スタイルシート パラメーターが値を持つ場合、このパラメーターは無視されます。
XML—出力のルート案内ファイルは .xml ファイルとして生成されます。 ファイルにはルート案内用文字列およびルートの距離、時間の情報とは別に、マヌーバー タイプおよび各方向のターン角度に関する情報も含まれます。
TEXT—出力のルート案内ファイルはルート案内用文字列、ルートの距離、時間 (オプション) の情報を含む単純な .txt ファイルとして生成されます。
HTML—出力のルート案内ファイルはルート案内用文字列、ルートの距離、時間 (オプション) の情報を含む .html ファイルとして生成されます。
|
String
|
|
out_directions_file
|
stylesheet パラメーターにスタイル シートを指定する場合は、out_directions_file の値のファイル接尾辞が、スタイル シートが生成するファイル タイプに一致することを確認してください。
|
File
|
|
report_units
|
ルート案内ファイルで使用される距離単位を指定します。 たとえば、インピーダンス属性がメートル単位の場合でも、ルート案内をマイル単位で表示することができます。
|
String
|
|
report_time
(オプション)
|
ルート案内ファイルで移動時間を出力するかどうかを指定します。
|
Boolean
|
|
time_attribute
(オプション)
|
ルート案内の移動時間の提供に使用する時間ベースのコスト属性。 入力ネットワーク解析レイヤーで使用されるネットワーク データセットには、コスト属性が必ず存在する必要があります。 タイム ウィンドウを使用する配車ルート レイヤーとルート レイヤーの場合、このパラメーターには移動モードのコスト属性のみを使用できます。
|
String
|
|
language
(オプション)
|
ルート案内に使用する言語。
このパラメーターには、ルート案内生成に使用できる言語のうちの 1 つを表す 2 文字または 5 文字の言語コードを使用します。 Python で ListDirectionsLanguages 関数を使用して、使用できる言語コードのリストを取得できます。
|
String
|
|
style_name
(オプション)
|
ルート案内に使用される書式スタイルを指定します。
NA Desktop—印刷可能な詳細なルート案内が使用されます。
NA Navigation—車載ナビゲーション デバイス用に設計された詳細なルート案内が使用されます。
NA Campus—歩行者ルート用に設計された詳細な歩行ルート案内が使用されます。
|
String
|
|
stylesheet
(オプション)
|
書式設定された出力ファイル タイプ (PDF、Word、HTML ファイルなど) の生成に使用されるスタイル シート。 出力ルート案内ファイル パラメーターのファイル接尾辞は、スタイル シートが生成するファイル タイプに一致する必要があります。 このパラメーターが値を持つ場合、ツールは出力ルート案内ファイル パラメーターをオーバーライドします。
ヒント:
カスタム HTML およびテキスト スタイル シートを作成するには、Network Analyst からスタイル シートをコピーして編集します。 スタイル シートは <ArcGIS installation directory>\Pro\Resources\NetworkAnalyst\Directions\Styles ディレクトリーにあります。 HTML スタイル シートは Dir2PHTML.xsl、テキスト スタイル シートは Dir2PlainText.xsl です。
|
File
|
派生した出力
|
名前
|
説明
|
データ タイプ
|
|
output_layer
|
ルートに基づいて更新されたネットワーク解析レイヤー。
|
Network Analyst Layer
|
コードのサンプル
Directions の例 1 (Python ウィンドウ)
次のサンプル コードは、すべてのパラメーターを含む Directions 関数の使用を示しています:
arcpy.na.Directions("Route", "TEXT", "C:/Data/Route_Directions.txt", "Miles",
"REPORT_TIME", "Minutes")
次のスタンドアロン Python スクリプトは、Directions 関数を使用してルート案内を .html ファイルで生成する方法を示しています。
# Name: Directions_Workflow.py
# Description: Generate driving directions in an html file for a route that
# visits the store locations in the best sequence in order to
# minimize the total travel time
# 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 inputs and outputs
input_gdb = "C:/Data/SanFrancisco.gdb"
network = os.path.join(input_gdb, "Transportation", "Streets_ND")
layer_name = "StoreRoute"
travel_mode = "Driving Time"
start_location = os.path.join(input_gdb, "Analysis", "DistributionCenter")
store_locations = os.path.join(input_gdb, "Analysis", "Stores")
output_directions = os.path.join(
output_dir, layer_name + "_Directions.html")
output_layer_file = os.path.join(output_dir, layer_name + ".lyrx")
# Create a new route layer. The route starts at the distribution center and
# visits the stores in the best order to yield the shortest travel time.
result_object = arcpy.na.MakeRouteAnalysisLayer(
network, layer_name, travel_mode, "PRESERVE_FIRST", time_of_day="8:00 AM"
)
# Get the layer object from the result object. The route layer can
# now be referenced using the layer object.
layer_object = result_object.getOutput(0)
# Get the names of all the sublayers within the route layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
stops_layer_name = sublayer_names["Stops"]
# Load the distribution center as the start location using default field
# mappings and search tolerance
arcpy.na.AddLocations(
layer_object, stops_layer_name, start_location, "", ""
)
# Load the store locations as stops. Make sure the store locations are
# appended to the Stops sublayer so the distribution center you just loaded
# isn't overwritten. Map the ServiceTime field from the input data to the
# Attr_[impedance] property in the Stops sublayer so that the time it takes to
# service each store is included in the total travel time for the route.
# Figure out what the impedance attrbute is
solver_props = arcpy.na.GetSolverProperties(layer_object)
impedance = solver_props.impedance
# Handle field mappings
field_mappings = arcpy.na.NAClassFieldMappings(
layer_object, stops_layer_name
)
field_mappings["Name"].mappedFieldName = "Name"
field_mappings["Attr_" + impedance].mappedFieldName = "ServiceTime"
arcpy.na.AddLocations(
layer_object, stops_layer_name, store_locations,
field_mappings, "", append="APPEND"
)
# Generate driving directions in an HTML file
arcpy.na.Directions(
layer_object, "HTML", output_directions, "Miles",
"REPORT_TIME", impedance
)
# Save the solved na 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))