ロケーションの追加(Add Locations) (Network Analyst)
サマリ
ネットワーク解析レイヤにネットワーク解析オブジェクトを追加します。これらのオブジェクトは、ストップやバリアなどの特定のサブレイヤに追加されます。オブジェクトは、フィーチャまたはレコードとして入力されます。
使用法
- 
このツールを実行して、ネットワーク解析オブジェクトを同じサブレイヤに繰り返し追加できます。たとえば、ルート レイヤのストップを 2 つのフィーチャクラスから取得する場合、APPEND オプションを使用してツールを 2 回実行します。 
- 
新しいオブジェクトを読み込む前に既存のネットワーク解析オブジェクトを削除したい場合、CLEAR オプションを使用します。 
- 
ネットワーク データセットのネットワーク ソースとして使用されるフィーチャクラスが有効かつ最新の空間インデックスを保持している場合、このツールは非常に高速に実行されます。 
- 車両に取り付けたレシーバから取得した GPS 座標など、移動するポイントを追加する場合、方位の読み取りと方位の許容値を使用して、ネットワーク上のポイントをより正確に特定します。 
構文
| パラメータ | 説明 | データ タイプ | 
| in_network_analysis_layer | ネットワーク解析オブジェクトが追加されるネットワーク解析レイヤ。 | Network Analyst Layer | 
| sub_layer | ネットワーク解析オブジェクトが追加されるネットワーク解析レイヤのサブレイヤ。 | String | 
| in_table | 新しいネットワーク解析オブジェクトのソースとなるフィーチャクラスまたはテーブル。 | Table View | 
| field_mappings | ネットワーク解析オブジェクトのプロパティに値を設定します。プロパティは定数を設定するか、入力フィーチャクラスまたはテーブルのフィールドに割り当てることができます。 NAClassFieldMappings クラスから取得する NAClassFieldMappings オブジェクトは、パラメータ値を指定するのに使用されます。NAClassFieldMappings オブジェクトは NAClassFieldMap オブジェクトのコレクションで、これを使用すると、ネットワーク解析オブジェクトのプロパティに対して、デフォルト値を指定したり、入力フィーチャからフィールド名をマップしたりできます。読み込むデータに、解析に使用するネットワーク データセットに基づくネットワーク ロケーションまたはネットワーク ロケーション範囲属性がある場合、入力フィーチャのネットワーク ロケーション フィールドをネットワーク ロケーション プロパティに割り当てます。フィールド マッピングのネットワーク ロケーション フィールドを指定することは、ツール ダイアログ ボックスの [ジオメトリの代わりにネットワーク ロケーション フィールドを使用する] パラメータを使用するのと同様です。  注意: すべてのネットワーク ロケーション プロパティにフィールド マッピングを指定する場合、残りのネットワーク ロケーション プロパティのフィールド マッピングを指定して、ツール実行エラーを防ぐ必要があります。 | Network Analyst Class FieldMap | 
| search_tolerance | 入力フィーチャをネットワークに配置する際の検索許容値。検索許容値の外側にあるフィーチャは配置されません。パラメータには許容値の値と単位が含まれます。 ライン バリアまたはポリゴン バリアのサブレイヤにロケーションを追加する際には、パラメータは使用されません。この場合、「#」をパラメータ値として使用します。 | Linear unit | 
| sort_field (オプション) | ネットワーク解析オブジェクトをネットワーク解析レイヤに追加する際に、ネットワーク解析オブジェクトをソートする基準となるフィールド。デフォルトは入力フィーチャクラスまたはテーブルの ObjectID フィールドです。 | Field | 
| search_criteria [[Source, SnapType],...] (オプション) | ロケーション検索時に検索するネットワーク データセットのソースと、使用するジオメトリの部分(スナップ タイプとも呼ばれます)を指定します。 パラメータ値は、ネストされたリストとともにリストとして指定されます。ネストしたリストは各ネットワーク ソースの名前とスナップ タイプを示す 2 つの値で構成されます。スナップ タイプは SHAPE、MIDDLE、END、NONE キーワードを使用して指定されます。たとえば、ロケーション検索時には、パラメータ値「[["Streets","SHAPE"],["Streets_ND_Junctions","NONE"]]」は、Streets_ND_Junctions ソースでなく Streets ソースの形状に基づいた検索が可能であることを示します。 1 つのネットワーク ソースに複数のスナップ タイプを指定するには、アンダースコアで区切ったスナップ タイプ キーワードの組み合わせを使用します。たとえば、MIDDLE_END はロケーションがネットワーク ソースの中間または端点にスナップされることを示します。 ラインまたはポリゴン ネットワーク ロケーションを追加する際、他のスナップ タイプが指定されていても Shape スナップ タイプのみが使用されます。 | Value Table | 
| match_type (オプション) | 
 ライン バリアまたはポリゴン バリアのサブレイヤにロケーションを追加する際には、パラメータは使用されません。この場合、「#」をパラメータ値として使用します。 | Boolean | 
| append (オプション) | 新しいネットワーク解析オブジェクトを既存のオブジェクトに追加するかどうかを指定します。 
 | Boolean | 
| snap_to_position_along_network (オプション) | ネットワーク データセットに沿ってネットワーク ロケーションをスナップするか、ネットワーク データセットから指定したオフセットにネットワーク ロケーションをスナップするかを指定します。 
 ライン バリアまたはポリゴン バリアのサブレイヤにロケーションを追加する際には、パラメータは使用されません。この場合、「#」をパラメータ値として使用します。 | Boolean | 
| snap_offset (オプション) | ポイントをネットワークにスナップする際、オフセット距離を適用できます。オフセット距離が 0 だと、ポイントはネットワーク フィーチャ(一般的にライン)と一致します。ネットワーク フィーチャからポイントをオフセットする場合、オフセット距離を入力します。オフセットは、元のポイントの場所に関連しています。つまり、元のポイントが左側にあった場合、新しい場所は左にオフセットされます。元のポイントが右側にあれば、新しいロケーションも右側にオフセットされます。 ライン バリアまたはポリゴン バリアのサブレイヤにロケーションを追加する際には、パラメータは使用されません。この場合、「#」をパラメータ値として使用します。 | Linear unit | 
| exclude_restricted_elements (オプション) | 
 | Boolean | 
| search_query [[Source, Expression],...] (オプション) | 検索をソース フィーチャクラス内のフィーチャのサブセットに制限するクエリを定義します。この機能は、ネットワーク ロケーションとして適切でないフィーチャを検索したくない場合に有用です。たとえば、ポリゴンの重心を読み込む場合に、生活道路に配置したくない場合は、一般道路のみを検索するクエリを定義できます。 パラメータ値は、ネストされたリストとともにリストとして指定されます。ネストしたリストはすべてのネットワーク ソースの名前と SQL 式を示す 2 つの値で構成されます。SQL 式の構文はネットワーク ソース フィーチャクラスのタイプによって少し異なります。たとえば、クエリ対象がファイル ジオデータベース、ArcSDE ジオデータベース、シェープファイル、または SDC に格納されたソース フィーチャクラスである場合は、フィールド名を二重引用符で囲みます(「"CFCC"」)。クエリ対象がパーソナル ジオデータベースの場合は、フィールドを角括弧で囲みます(「[CFCC]」)。 特定のソースに対してクエリを定義したくない場合、SQL 式に値として「"#"」を入力するか、またはパラメータ値からソース名と SQL 式を除外します。すべてのネットワーク ソースに対してクエリを定義したくない場合、パラメータ値として「"#"」を入力します。 たとえば、パラメータ値「[["Streets","\"CFCC\" = 'A15'"], ["Streets_ND_Junctions",""]]」では、Streets ソース フィーチャクラスに対する SQL 式を定義し、Streets_ND_Junctions ソース フィーチャクラスには SQL 式を定義しません。フィールド名 CFCC を囲むために使用される二重引用符は、Python インタープリタで構文解析エラーが発生しないようバック スラッシュ文字でエスケープされます。 | Value Table | 
コードのサンプル
必須パラメータのみを使用してツールを実行します。
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.na.AddLocations("Route","Stops","Analysis/Hospital","","")
すべてのパラメータを使用してツールを実行します。
import arcpy
arcpy.env.workspace = "C:/ArcTutor/Network Analyst/Tutorial/SanFrancisco.gdb"
arcpy.na.AddLocations("Route","Stops","Analysis/Hospital",
                      "Name Name #;Attr_Minutes VisitTime 0;CurbApproach # 0",
                      "2 Miles","FID",
                      [["Streets","SHAPE"],["Streets_ND_Junctions","NONE"]],
                      "MATCH_TO_CLOSEST","CLEAR","SNAP","10 Feet","EXCLUDE",
                      [["Streets",'"FREEWAY" = 0'],["Streets_ND_Junctions",""]])
次のスタンドアロン Python スクリプトは、AddLocations(ロケーションの追加)ツールを使用して起点と終点を OD コスト マトリックス レイヤに読み込む方法を示しています。
# Name: AddLocations_Workflow.py
# Description: The scenario shows how to calculate a travel time matrix between 
#              store features. Use the Add Locations tool to load origins and 
#              destinations into an OD Cost Matrix layer. Since the origins and 
#              destinations are the same in this case, the origins are first loaded 
#              from the store features using their geometry and the destinations
#              are loaded from the origins using network location fields to 
#              speed up the load times. 
# 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"
    outNALayerName = "StoreTravelTimeMatrix"
    impedanceAttribute = "TravelTime"
    inFeatures = "Analysis/Stores"
    searchTolerance = "500 Meters"
    searchQuery = [["Streets",'"FREEWAY" = 0'],["Streets_ND_Junctions",""]]
    odOrigins = "Origins"
    outLayerFile = "C:/data/output" + "/" + outNALayerName + ".lyr"
    
    #Create a new OD cost matrix analysis layer. For this scenario, the default 
    #value for all the remaining parameters statisfies the analysis requirements
    outNALayer = arcpy.na.MakeODCostMatrixLayer(inNetworkDataset, outNALayerName,
                                   impedanceAttribute)
    
    #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[odOrigins]
    destinationsLayerName = subLayerNames["Destinations"]
    
    #Get the origin layer object from within the OD cost matrix layer
    #The first layer returned by ListLayers is the OD cost matrix layer itself
    #which we don't want to use.
    for layer in arcpy.mapping.ListLayers(outNALayer)[1:]:
        if layer.datasetName == odOrigins:
            originsLayer = layer
            break
    else:
        raise Exception("Failed to get the origins layer object.")
    
    #Load store features as origins using the geometry of store features.
    #Ensure that the stores are not located on freeways by using a search query.
    #The OD cost matrix layer created previously is referred using its name. 
    arcpy.na.AddLocations(outNALayer,originsLayerName,inFeatures,"",
                          searchTolerance, exclude_restricted_elements = "EXCLUDE",
                          search_query = searchQuery)
    
    #Load origins as destinations using the network locations fields from 
    #origins. This is much faster than loading destinations from the store 
    #features using their geometry as their network locations have already been
    #calculated while loading them origins.
    #Create a field mappings object that supports network location fields from 
    #origins layer using the candidate fields from origins
    originsLayer = arcpy.management.MakeFeatureLayer(originsLayer,
                                                     outNALayerName+originsLayerName)
    candidateFields = arcpy.ListFields(originsLayer.getOutput(0))
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer,
                                                  destinationsLayerName, True,
                                                  candidateFields)
    arcpy.na.AddLocations(outNALayer,destinationsLayerName,originsLayer,
                          fieldMappings,"")
    
    #Solve the od cost matrix layer. Halt the execution if there is an 
    #invalid location 
    arcpy.na.Solve(outNALayer,"HALT")
    
    #Save the solved na 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 occured on line %i" % tb.tb_lineno
    print str(e)