ルート案内(Directions) (Network Analyst)
サマリ
ルートに基づいて、ネットワーク解析レイヤからルート案内情報を生成します。ルート案内情報は、XML 形式またはテキスト形式のファイルに書き込まれます。
使用法
- 
[ルート案内 (Directions)] ツールはネットワーク解析レイヤに有効な結果がない場合に、ネットワーク解析レイヤの解析を実行します。このため、ルート案内を生成する前にネットワーク解析レイヤの解析を実行する必要はありません。 
- 
ルート案内が含まれる出力 XML ファイルは、ArcGIS インストール フォルダにあるスタイルシートを使用して適切な形式の HTML ファイルに変換することができます。たとえば、XML 形式によるルート案内の出力は、スタイルシート「Dir2WebDocument.xsl」または「Dir2PlainText.xsl」(通常 C:\Program Files\ArcGIS\Desktop10.0\NetworkAnalyst\Directions\Styles にあります)を使用してそれぞれ HTML ファイルまたはテキスト ファイルに変換することができます。これには、スタイルシートを使用して XML ファイルを HTML ファイルに変換するカスタム ツールが必要です。 
構文
| パラメータ | 説明 | データ タイプ | 
| in_network_analysis_layer | ルート案内を生成するネットワーク解析レイヤ。ルート案内は、[ルート]、[最寄り施設の検出]、[配車ルート(VRP)] ネットワーク解析レイヤに対してのみ生成することができます。 | Network Analyst Layer | 
| file_type | 出力されるルート案内ファイルの形式。 
 | String | 
| out_directions_file | 書き込みが行われるルート案内ファイルの絶対パス名。 | File | 
| report_units | ルート案内ファイルで距離の情報を出力する際の距離単位を指定します。たとえば、インピーダンスがメートル単位の場合でも、ルート案内をマイル単位で表示することができます。 | String | 
| report_time (オプション) | 
 | Boolean | 
| time_attribute (オプション) | ルート案内の移動時間を提供する時間ベースのコスト属性。入力ネットワーク解析レイヤで使用されるネットワーク データセットには、コスト属性が必ず存在する必要があります。 | String | 
コードのサンプル
すべてのパラメータを付与して、Directions(ルート案内)ツールを実行します。
import arcpy
arcpy.Directions_na("Route","TEXT","C:/temp/Route_Directions.txt","Miles",
                    "REPORT_TIME","Minutes")
次のスタンドアロン Python スクリプトは、Directions(ルート案内)ツールを使用してルートの道順案内をテキスト ファイルで生成する方法を示しています。
# Name: Directions_Workflow.py
# Description: Generate driving directions in a text file for a route that 
#              visits the store locations in the best sequence that minimizes 
#              the total travel time
# 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/SanFrancisco.gdb"
    env.overwriteOutput = True
    
    #Set local variables
    inNetworkDataset = "Transportation/Streets_ND"
    outNALayer = "StoreRoute"
    impedanceAttribute = "TravelTime"
    startLocation = "Analysis/DistributionCenter"
    storeLocations = "Analysis/Stores"
    fieldMappings = "Name Name #; Attr_TravelTime ServiceTime #"
    outDirectionsFile = "C:/data/output" + "/" + outNALayer + "Directions.txt"
    outLayerFile = "C:/data/output" + "/" + outNALayer + ".lyr"
    
    #Create a new route layer. The route starts at the distribution center and 
    #takes the best sequence to visit the store locations.
    arcpy.MakeRouteLayer_na(inNetworkDataset,outNALayer,impedanceAttribute,
                            "FIND_BEST_ORDER","PRESERVE_FIRST","",['Meters'],
                            "NO_UTURNS",start_date_time="8 AM")
    
    #Load the distribution center as the start location using default field 
    #mappings and search tolerance
    arcpy.AddLocations_na(outNALayer,"Stops",startLocation,"","")
    
    #Load the store locations as stops. Make sure the store locations are 
    #appended to the Stops sublayer which already contains the distribution 
    #center location. Map the Attr_TravelTime property from the ServiceTime 
    #field so that the total travel time for the route will also contain the 
    #service time
    arcpy.AddLocations_na(outNALayer,"Stops",storeLocations,fieldMappings,"","",
                          "","","APPEND")
    
    #Generate driving directions in a text file
    arcpy.Directions_na(outNALayer,"TEXT",outDirectionsFile,"Miles",
                        "REPORT_TIME","TravelTime")
    
    #Save the solved na layer as a layer file on disk using 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)