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

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

解析レイヤーにフィールドを追加 (Add Field to Analysis Layer)

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

概要

ネットワーク解析レイヤーのサブレイヤーにフィールドを追加します。

使用法

  • このツールは [ロケーションの追加 (Add Locations)] ツールとともによく使用され、入力フィーチャからサブレイヤーへフィールドを転送します。たとえば、UniqueID と呼ばれるフィールドを入力フィーチャから到達圏レイヤーの施設サブレイヤーに転送したい場合、このツールを使用して最初に UniqueID フィールドを施設サブレイヤーに追加して、次に [ロケーションの追加 (Add Locations)] ツールのフィールド割り当てを使用して、UniqueID フィールドへの入力値を設定します。

  • フィールドはネットワーク解析レイヤーのすべてのサブレイヤーに追加することができます。

構文

arcpy.na.AddFieldToAnalysisLayer(in_network_analysis_layer, sub_layer, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable})
パラメーター説明データ タイプ
in_network_analysis_layer

新しいフィールドを追加するネットワーク解析レイヤー。

Network Analyst Layer
sub_layer

新しいフィールドを追加するネットワーク解析レイヤーのサブレイヤー。

String
field_name

ネットワーク解析レイヤーの指定されたサブレイヤーに追加されるフィールド名。

String
field_type

新しいフィールドの作成に使用されるフィールドのタイプ。

  • LONG — -2,147,483,648〜2,147,483,647の範囲の整数。
  • TEXT —任意の文字列。
  • FLOAT — -3.4E38〜1.2E38の範囲の有理数。
  • DOUBLE — -2.2E308〜1.8E308の範囲の有理数。
  • SHORT — -32,768〜32,767の範囲の整数。
  • DATE —日付と時刻
  • BLOB —大容量バイナリ オブジェクト。BLOB フィールドにアイテムを読み込む、または BLOB フィールドの内容を参照するには、カスタム ローダー、カスタム ビューアー、またはサードパーティ アプリケーションが必要です。
String
field_precision
(オプション)

フィールドに格納できる桁数。 小数点以下であるかどうかにかかわらず、すべての桁が対象になります。

パラメーター値は数値フィールド タイプのみに有効です。

Long
field_scale
(オプション)

フィールドに格納できる小数点以下の桁数。 このパラメーターは、float タイプと double タイプのデータ フィールドのみで使用します。

Long
field_length
(オプション)

追加するフィールドの長さ。 この値は、フィールドの各レコードに許容される文字の最大数を設定します。 このパラメーターは、タイプがテキストのフィールドに対してのみ適用されます。

Long
field_alias
(オプション)

フィールド名に割り当てる別名。 曖昧なフィールド名を説明するために使用される名前です。 このパラメーターの適用対象となるのは、ジオデータベースだけです。

String
field_is_nullable
(オプション)

このフィールドに NULL 値を含めることができるかどうかを指定します。 NULL 値は、ゼロや空のフィールドとは異なり、ジオデータベースのフィールドのみでサポートされます。

  • NON_NULLABLE —フィールドでは NULL 値を使用できません。
  • NULLABLE —フィールドで NULL 値を使用できます。 これがデフォルトです。
Boolean

派生した出力

名前説明データ タイプ
output_layer

更新されたネットワーク解析レイヤー。

Network Analyst レイヤー

コードのサンプル

AddFieldToAnalysisLayer (解析レイヤーにフィールドを追加) の例 1 (Python ウィンドウ)

次の Python ウィンドウ スクリプトは、UniqueID フィールドを到達圏ネットワーク解析レイヤーの 施設サブレイヤーに追加する方法を示しています。

arcpy.na.AddFieldToAnalysisLayer("Service Area", "Facilities", "UniqueID",
                                    "LONG")
AddFieldToAnalysisLayer (解析レイヤーにフィールドを追加) の例 2 (ワークフロー)

次のスタンドアロン Python スクリプトは、AddFieldToAnalysisLayer (解析レイヤーにフィールドを追加) 機能を使用して、入力の消防署フィーチャの StationID フィールドを到達圏解析から計算される 2 分、3 分、5 分以内の到達圏ポリゴン フィーチャに転送する方法を示しています。StationID フィールドは、消防署フィーチャの他の属性を到達圏ポリゴン フィーチャと結合するために使用することができます。

# Name: AddFieldToAnalysisLayer_Workflow.py
# Description: Transfers the Address field from the input fire station 
#              features to the 2-,3-, and 5-minute service area polygon features
#              calculated from a service area analysis. The Address field can 
#              be used to join other attributes from the fire station features 
#              to the service area polygon features.
# 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 = "FireStationsCoverage"
    impedanceAttribute = "TravelTime"
    defaultBreakValues = "2 3 5"   
    fieldName = "Address"
    fieldType = "TEXT"
    inFeatures = "Analysis/FireStations"
    searchTolerance = "2 Miles"
    outFeatures = outNALayerName + "Area"
    saFacilities = "Facilities"
    saPolygons = "SAPolygons"
    
    #Create a new service area analysis layer. For this scenario, the default 
    #value for all the remaining parameters statisfies the analysis requirements
    outNALayer = arcpy.na.MakeServiceAreaLayer(inNetworkDataset, outNALayerName,
                                               impedanceAttribute,"",
                                               defaultBreakValues)
    
    #Get the layer object from the result object. The service layer can now be
    #referenced using the layer object.
    outNALayer = outNALayer.getOutput(0)
    
    #Get the names of all the sublayers within the service area layer.
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    #Stores the layer names that we will use later
    facilitiesLayerName = subLayerNames[saFacilities]
    polygonLayerName = subLayerNames[saPolygons]
    
    #Get the layer objects for all the sublayers within the service area layer
    #The first layer returned by ListLayers is the Service area layer itself
    #which we don't want to use.
    subLayers = {}
    for layer in arcpy.mapping.ListLayers(outNALayer)[1:]:
        subLayers[layer.datasetName] = layer
    #Store the layer objects that we will use later
    facilitiesLayer = subLayers[saFacilities]
    polygonLayer = subLayers[saPolygons]
    
    #Add a Address field to the Facilities sublayer of the service area layer.
    #This is done before loading the fire stations as facilities so that the 
    #Address values can be transferred from the input features to the 
    #Facilities sublayer. The service area layer created previously is 
    #referred by the layer object.
    arcpy.na.AddFieldToAnalysisLayer(outNALayer,facilitiesLayerName,fieldName,
                                     fieldType)
    
    #Add the fire station features as Facilities and map the Name and the 
    #Address properties from the Name and Address fields from fire station
    #features using the field mappings.
    fieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, facilitiesLayerName)
    fieldMappings['Name'].mappedFieldName = "Name"
    fieldMappings['Address'].mappedFieldName = "Address"
    arcpy.na.AddLocations(outNALayer,facilitiesLayerName,inFeatures,
                          fieldMappings, searchTolerance)
    
    #Solve the service area layer
    arcpy.na.Solve(outNALayer)
    
    #Transfer the Address field from Facilities sublayer to Polygons sublayer 
    #of the service area layer since we wish to export the polygons. The 
    #FacilityID field in Polygons sub layer is related to the ObjectID field in
    #the Facilities sub layer. 
    arcpy.management.JoinField(polygonLayer, "FacilityID",facilitiesLayer,
                               "ObjectID", fieldName)
    
    #Export the Polygons sublayer to a feature class on disk.
    arcpy.management.CopyFeatures(polygonLayer, outFeatures)
    
    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: はい

関連トピック

  • 解析ツールセットの概要

ArcGIS Desktop

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

ArcGIS

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

Esri について

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