FieldMap

サマリ

The FieldMap object provides a field definition and a list of input fields taken from a set of tables or feature classes.

説明

FieldMappings オブジェクトは FieldMap オブジェクトのコレクションで、マージ などのフィールド マッピングを実行するツールのパラメータ値として使用されます。これらのオブジェクトを操作する最も簡単な方法は、まず FieldMappings オブジェクトを作成した後、結合対象の入力フィーチャクラスまたはテーブルを追加することにより、そのオブジェクトの FieldMap オブジェクトを初期化することです。すべての入力が指定された後、FieldMappings オブジェクトには、そのすべての入力の一意なフィールド名ごとに FieldMap オブジェクトまたは出力フィールドを 1 つずつ含まれます。このリストは、新しいフィールドを追加する、出力フィールドのプロジェクトまたは内容を変更する、必要のない出力フィールドを削除することにより、変更できます。

FieldMap オブジェクトのプロパティには、入力テキスト値の開始位置と終了位置が含まれるため、入力値の一部を使って新しい出力値を作成することができます。FieldMap オブジェクトに同じテーブルまたはフィーチャクラスからの複数入力フィールドが含まれる場合、各レコードの値は mergeRule プロパティを使用してマージされます。これは、たとえば「国道」と「1 号」のように、道路タイプが含まれているフィールドと道路名が含まれているフィールドの値を結合するのに役立ちます。FieldMapjoinDelimiter プロパティは、mergeRule の値として Join が指定されている場合に使用されます。スペースなど、任意の文字のセットを区切り文字として使用できます。前記の例では、「国道 1 号」という値が作成されます。

構文

FieldMap ()

プロパティ

プロパティ説明データ タイプ
inputFieldCount
(読み取り専用)

Get the count of subfields.

Integer
joinDelimiter
(読み書き)

Join delimiter for the subfields.

String
mergeRule
(読み書き)

Merge rule for the subfields.

String
outputField
(読み書き)

Get the properties field.

Field

メソッドの概要

メソッド説明
addInputField (table_dataset, field_name, {start_position}, {end_position})

Adds input field to the field map.

findInputFieldIndex (table_dataset, field_name)

Finds an input field from the field map.

getEndTextPosition (index)

Gets end text position from the field map.

getInputFieldName (index)

Gets the name of an input field from the field map, based on the field's index.

getInputTableName (index)

Gets the name of an input table from the field map, based on the table's index.

getStartTextPosition (index)

Gets start text position from the field map.

removeAll ()

Removes all values and creates an empty object.

removeInputField (index)

Removes an input field from the field map.

setEndTextPosition (index, end_position)

Sets end text position for the field map.

setStartTextPosition (index, start_position)

Sets the start text position from the field map.

メソッド

addInputField (table_dataset, field_name, {start_position}, {end_position})
パラメータ説明データ タイプ
table_dataset

The table added to the field map.

String
field_name

The input field name.

String
start_position

The start position of an input text value.

(デフォルト値は -1)

Integer
end_position

The end position of an input text value.

(デフォルト値は -1)

Integer
findInputFieldIndex (table_dataset, field_name)
パラメータ説明データ タイプ
table_dataset

The table added to the field map.

String
field_name

The field name.

String
リターン
データ タイプ説明
Integer

The index position of the field name.

getEndTextPosition (index)
パラメータ説明データ タイプ
index

The index position.

Integer
リターン
データ タイプ説明
Integer

The end text position.

getInputFieldName (index)
パラメータ説明データ タイプ
index

The index position.

Integer
リターン
データ タイプ説明
String

The input field name.

getInputTableName (index)
パラメータ説明データ タイプ
index

The index position.

Integer
リターン
データ タイプ説明
String

The input table name.

getStartTextPosition (index)
パラメータ説明データ タイプ
index

The index position.

Integer
リターン
データ タイプ説明
Integer

The start text position.

removeAll ()
removeInputField (index)
パラメータ説明データ タイプ
index

The index position.

Integer
setEndTextPosition (index, end_position)
パラメータ説明データ タイプ
index

The index position.

Integer
end_position

The end position of an input text value.

Integer
setStartTextPosition (index, start_position)
パラメータ説明データ タイプ
index

The index position.

Integer
start_position

The start position of an input text value.

Integer

コードのサンプル

FieldMap example
import arcpy
from arcpy import env

# Input feature classes contain a PID field that is a composite of
#   the Township, Range, Section, QuarterSection, Block, Lot, and SubLot values.
#   We need to define how to break the PID field into two fields: TWNSHIP and BLOCK,
#   then run the Merge tool.
#   PID field and field map. 
#                    1 1 1 1 1 1 1
#  1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
# +-------------------------------+
# |2|0|3|0|8|2|1|0|0|1|0|0|5|0|0|0|
# +-------------------------------+
# +---TWNSHIP---+-------BLOCK-----+

infc1 = "C:/Data/NewParcels.shp"
infc2 = "Parcels"
outfc = "Parcels_Merge"

# Create a fieldmappings object and two fieldmap objects
#
fieldmappings = arcpy.FieldMappings()
fldmap_TWNSHIP = arcpy.FieldMap()
fldmap_BLOCK = arcpy.FieldMap()

# Create a value table to hold names of input feature classes for Merge tool.
#
vt = arcpy.ValueTable()

# Add all fields from first input feature class to fieldmappings object
#   AddTable is the most efficient way.
#
fieldmappings.addTable(infc1)

# Add the TWNSHIP and BLOCK field from the first input feature class 
#   to fieldmap object.
#
fldmap_TWNSHIP.addInputField(infc1)
fldmap_BLOCK.addInputField(infc1)
vt.addRow(infc1)

# Add all fields from second input feature class to fieldmappings object
#
env.workspace = "C:/Data/Boulder.gdb"
fieldmappings.addTable(infc2)

# Add the TWNSHIP and BLOCK field from the second input feature class 
#   to fieldmap object.
#
fldmap_TWNSHIP.addInputField(infc2)
fldmap_BLOCK.addInputField(infc2)
vt.addRow(infc2)

# Set the starting and ending positions of the input field in the fieldmap.
#   This is for TWNSHIP
for x in range(0, fldmap_TWNSHIP.inputFieldCount):
    fldmap_TWNSHIP.setStartTextPosition(x, 0)
    fldmap_TWNSHIP.setEndFieldPosition(x, 6)

# Set the starting and ending positions of the input field in the fieldmap.
#   This is for BLOCK
for x in range(0, fldmap_BLOCK.inputFieldCount):
    fldmap_BLOCK.setStartTextPosition(x, 7)
    fldmap_BLOCK.setEndFieldPosition(x, 15)

# Get the new field object from fieldmap, set field name, place back in fieldmap.
#
fld_TWNSHIP = fldmap_TWNSHIP.outputField
fld_TWNSHIP.name = "TWNSHIP"
fldmap_TWNSHIP.outputField = fld_TWNSHIP
fld_BLOCK = fldmap_BLOCK.outputField
fld_BLOCK.name = "BLOCK"
fldmap_BLOCK.outputField = fld_BLOCK

# Add the new fieldmap object to fieldmappings object.
fieldmappings.addFieldMap(fldmap_TWNSHIP)
fieldmappings.addFieldMap(fldmap_BLOCK)

#Run the Merge tool
arcpy.Merge_management(vt, outfc, fieldmappings) 

関連項目


7/10/2012