解析レイヤにフィールドを追加(Add Field to Analysis Layer) (Network Analyst)
サマリ
ネットワーク解析レイヤのサブレイヤにフィールドを追加します。
使用法
-
このツールは [ロケーションの追加 (Add Locations)] ツールとともによく使用され、入力フィーチャからサブレイヤへフィールドを転送します。たとえば、UniqueID と呼ばれるフィールドを入力フィーチャから到達圏レイヤの 施設サブレイヤに転送したい場合、このツールを使用して最初に UniqueID フィールドを 施設サブレイヤに追加して、次に [ロケーションの追加 (Add Locations)] ツールのフィールド割り当てを使用して、UniqueID フィールドへの入力値を設定します。
-
フィールドはネットワーク解析レイヤのすべてのサブレイヤに追加することができます。
構文
| パラメータ | 説明 | データ タイプ |
in_network_analysis_layer |
新しいフィールドを追加するネットワーク解析レイヤ。 | Network Analyst Layer |
sub_layer |
新しいフィールドを追加するネットワーク解析レイヤのサブレイヤ。 | String |
field_name |
ネットワーク解析レイヤの指定されたサブレイヤに追加されるフィールド名。 | String |
field_type |
新しいフィールドの作成に使用されるフィールドのタイプ。
| String |
field_precision (オプション) |
フィールドに格納できる桁数を指定します。小数点以下であるかどうかにかかわらず、すべての桁が対象になります。 パラメータ値は数値フィールド タイプのみに有効です。 | Long |
field_scale (オプション) |
フィールドに格納できる小数点以下の桁数を設定します。このパラメータは、Float タイプと Double タイプのデータ フィールドのみで使用します。 | Long |
field_length (オプション) |
追加するフィールドの長さ。この値は、フィールドの各レコードに許容される文字の最大数を設定します。このオプションは、タイプがテキストまたはブロブのフィールドに対してのみ適用されます。 | Long |
field_alias (オプション) |
フィールド名に割り当てる別名。この名前は、あいまいなフィールド名にわかりやすい名前を付けるために使用します。フィールド エイリアスのパラメータは、ジオデータベースとカバレッジに対してのみ適用されます。 | String |
field_is_nullable (オプション) |
関連付けられている属性情報がない状態のジオグラフィック フィーチャ。ゼロや空のフィールドとは異なるもので、ジオデータベースのフィールドのみでサポートされます。
| Boolean |
コードのサンプル
次の Python ウィンドウ スクリプトは、UniqueID フィールドを到達圏ネットワーク解析レイヤの 施設サブレイヤに追加する方法を示しています。
import arcpy
arcpy.AddFieldToAnalysisLayer_na("Service Area","Facilities","UniqueID","LONG")
次のスタンドアロン Python スクリプトは、AddFieldToAnalysisLayer(解析レイヤにフィールドを追加)機能を使用して、入力の消防署フィーチャの StationID フィールドを到達圏解析から計算される 2 分、3 分、5 分以内の到達圏ポリゴン フィーチャに転送する方法を示しています。StationID フィールドは、消防署フィーチャの他の属性を到達圏ポリゴン フィーチャと結合するために使用することができます。
# Name: AddFieldToAnalysisLayer_Workflow.py
# Description: Transfers the StationID field from the input fire station
# features to the 2,3,5 minute service area polygon features
# calculated from a service area analysis. The StationID 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"
outNALayer = "FireStationsCoverage"
impedanceAttribute = "TravelTime"
defaultBreakValues = "2 3 5"
fieldName = "StationID"
fieldType = "LONG"
inFeatures = "Analysis/FireStations"
fieldMappings = "Name StationName #; StationID StationID #"
searchTolerance = "2 Miles"
polygonLayer = outNALayer + "/" + "Polygons"
facilitiesLayer = outNALayer + "/" + "Facilities"
calculateField = "SAPolygons." + fieldName
expression = "!Facilities." + fieldName + "!"
outFeatures = outNALayer + "Area"
#Create a new service area analysis layer. For this scenario, the default
#value for all the remaining parameters statisfies the analysis requirements
arcpy.MakeServiceAreaLayer_na(inNetworkDataset, outNALayer,
impedanceAttribute,"",defaultBreakValues)
#Add a StationID field to the Facilities sublayer of the service area layer.
#This is done before loading the fire stations as facilities so that the
#StationID values can be transferred from the input features to the
#Facilities sublayer. The service area layer created previously is
#referred by its name.
arcpy.AddFieldToAnalysisLayer_na(outNALayer,"Facilities",fieldName,
fieldType)
#Add the fire station features as Facilities and map the Name and the
#StationID properties from the StationName and StationID fields.
arcpy.AddLocations_na(outNALayer,"Facilities",inFeatures,fieldMappings,
searchTolerance)
#Solve the service area layer
arcpy.Solve_na(outNALayer)
#Transfer the StationID field from Facilities sublayer to Polygons sublayer
#of the service area layer since we wish to export the polygons.
#First add "StationID" field to the Polygons sublayer
arcpy.AddFieldToAnalysisLayer_na(outNALayer,"Polygons",fieldName,fieldType)
#Join Facilities to Polygons based on FacilityID and ObjectID fields
arcpy.AddJoin_management(polygonLayer,"FacilityID",facilitiesLayer,
"ObjectID")
#Calculate the StationID field in Polygons based on the StationID field from
#facilities.
arcpy.CalculateField_management(polygonLayer,calculateField,expression,
"PYTHON")
#Remove the join so that the Polygons sublayer will not have all the fields
#from the Facilities sublayer when Polygons are exported to a feature class.
arcpy.RemoveJoin_management(polygonLayer,"Facilities")
#Export the Polygons sublayer to a feature class on disk.
arcpy.CopyFeatures_management(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 occured on line %i" % tb.tb_lineno
print str(e)