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—フィールド タイプが Long になります。 Long フィールドには、-2,147,483,648 ~ 2,147,483,647 の整数を指定できます。
TEXT—フィールド タイプが Text になります。 Text フィールドには、文字列を指定できます。
FLOAT—フィールド タイプが Float になります。 Float フィールドには、-3.4E38 ~ 1.2E38 の有理数を指定できます。
DOUBLE—フィールド タイプが Double になります。 Double フィールドには、-2.2E308 ~ 1.8E308 の有理数を指定できます。
SHORT—フィールド タイプが Short になります。 Short フィールドには、-32,768 ~ 32,767 の整数を指定できます。
DATE—フィールド タイプが Date になります。 Date フィールドには、日付値と時間値を指定できます。
BLOB—フィールド タイプが BLOB になります。 BLOB フィールドには、長いバイナリー数値列として格納されるデータを指定できます。 BLOB フィールドにアイテムを読み込む、または BLOB フィールドの内容を参照するには、カスタム ローダー、カスタム ビューアー、またはサードパーティー アプリケーションが必要です。
GUID—フィールド タイプが GUID になります。 GUID フィールドには、中括弧 () で囲まれた 36 文字のレジストリー形式の文字列が格納されます。
BIGINTEGER—フィールド タイプが Big Integer になります。 Big Integer フィールドには、-(253) ~ 253 の整数を指定できます。
TIMEONLY—フィールド タイプが time only になります。 Time only フィールドには、時間値を指定できます。日付値は指定できません。
DATEONLY—フィールド タイプが date only になります。 Date Only フィールドには、日付値を指定できます。時間値は指定できません。
TIMESTAMPOFFSET—フィールド タイプが Timestamp Offset になります。 Timestamp Offset フィールドは、日付、時刻、および UTC 値からのオフセットを指定できます。
|
String
|
|
field_precision
(オプション)
|
レガシー:
このパラメーターは非推奨であり、後方互換性のみのために維持されています。
|
Long
|
|
field_scale
(オプション)
|
レガシー:
このパラメーターは非推奨であり、後方互換性のみのために維持されています。
|
Long
|
|
field_length
(オプション)
|
フィールドの長さ。 この値は、フィールドの各レコードに許容される文字の最大数を設定します。 フィールドの長さが指定されない場合、長さ 255 が使用されます。
フィールドの長さは、テキスト フィールドにのみ適用されます。
|
Long
|
|
field_alias
(オプション)
|
フィールドの代替名。 この名前は、わかりにくいフィールド名を説明するために使用します。 このパラメーターはジオデータベースにのみ適用されます。
|
String
|
|
field_is_nullable
(オプション)
|
このフィールドに NULL 値を含めることができるかどうかを指定します。 NULL 値は、ゼロや空のフィールドとは異なり、ジオデータベースのフィールドのみでサポートされます。
|
Boolean
|
派生した出力
|
名前
|
説明
|
データ タイプ
|
|
output_layer
|
更新されたネットワーク解析レイヤー。
|
Network Analyst Layer
|
コードのサンプル
AddFieldToAnalysisLayer の例 1 (Python ウィンドウ)
次の Python ウィンドウ スクリプトは、UniqueID フィールドを到達圏ネットワーク解析レイヤーの施設サブレイヤーに追加する方法を示しています。
arcpy.na.AddFieldToAnalysisLayer("Service Area", "Facilities", "UniqueID",
"LONG")
AddFieldToAnalysisLayer の例 2 (ワークフロー)
次のスタンドアロン Python スクリプトは、AddFieldToAnalysisLayer 関数を使用して、入力の消防署フィーチャの StationID フィールドを到達圏解析から計算される 2 分、3 分、5 分以内の到達圏ポリゴン フィーチャに転送する方法を示しています。 StationID フィールドは、消防署フィーチャの他の属性を到達圏ポリゴン フィーチャと結合するために使用することができます。
レガシー:
GetNASublayer 関数を使用して、ネットワーク解析レイヤーのサブレイヤーを取得できます。 これは ArcGIS Pro 2.7 で導入されました。 以前のソフトウェア バージョンでは、サブレイヤー名をワイルドカードとして使用するネットワーク解析の Layer オブジェクトの listLayers メソッドを使用することがネットワーク解析レイヤーのサブレイヤー オブジェクトを取得する最適な方法でした。
# 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
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/SanFrancisco.gdb"
network = os.path.join(input_gdb, "Transportation", "Streets_ND")
layer_name = "FireStationsCoverage"
travel_mode = "Driving Time"
cutoffs = [2, 3, 5] #minutes
field_to_add = "Address"
field_type = "TEXT"
facilities = os.path.join(input_gdb, "Analysis", "FireStations")
search_tolerance = "2 Miles"
out_featureclass = os.path.join(output_dir, "Output.gdb",
"FireStationsCoverageArea")
#Create a new service area analysis layer. For this scenario, the default
#value for all the remaining parameters statisfies the analysis requirements
result_object = arcpy.na.MakeServiceAreaAnalysisLayer(network, layer_name,
travel_mode, cutoffs=cutoffs)
#Get the layer object from the result object. The service area layer can now
#be referenced using the layer object.
layer_object = result_object.getOutput(0)
#Get the names of all the sublayers within the service area layer.
sublayer_names = arcpy.na.GetNAClassNames(layer_object)
#Stores the layer names that we will use later
facilities_layer_name = sublayer_names["Facilities"]
polygons_layer_name = sublayer_names["SAPolygons"]
#Add the 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.
arcpy.na.AddFieldToAnalysisLayer(layer_object, facilities_layer_name,
field_to_add, field_type)
#Add the fire station features as Facilities and map the Name and the
#Address fields from the fire station features to the Name and Address
#properties on the Facilities sublayer
field_mappings = arcpy.na.NAClassFieldMappings(layer_object,
facilities_layer_name)
field_mappings['Name'].mappedFieldName = "Name"
field_mappings['Address'].mappedFieldName = "Address"
arcpy.na.AddLocations(layer_object, facilities_layer_name, facilities,
field_mappings, search_tolerance)
#Solve the service area layer
arcpy.na.Solve(layer_object)
#Get the layer objects for all the sublayers within the service area layer
facilities_sublayer = layer_object.listLayers(facilities_layer_name)[0]
polygons_sublayer = layer_object.listLayers(polygons_layer_name)[0]
#Transfer the Address field from the Facilities sublayer to the Polygons
#sublayer of the service area layer since we wish to export the polygons.
#The FacilityID field in the Polygons sublayer is related to the ObjectID
#field in the Facilities sublayer.
arcpy.management.JoinField(polygons_sublayer, "FacilityID",
facilities_sublayer, "ObjectID", field_to_add)
#Export the Polygons sublayer to a feature class on disk.
arcpy.management.CopyFeatures(polygons_sublayer, out_featureclass)
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))