ArcGIS for Desktop

  • 文档
  • 合约
  • 支持

  • My Profile
  • 帮助
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS for Desktop

全面的专业性 GIS

ArcGIS for Server

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 合约
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

帮助

  • 主页
  • 入门
  • 制图
  • 分析
  • 管理数据
  • 工具
  • 更多...

FieldMappings

  • 摘要
  • 讨论
  • 语法
  • 属性
  • 方法概述
  • 方法
  • 代码实例

摘要

FieldMappings 对象是一组 FieldMap 对象,用作制图工具的参数值,例如“合并”。

讨论

FieldMappings 对象是一组 FieldMap 对象,它用作执行字段映射的工具的参数值,如 Merge。要处理这些对象,最简单的方法就是先创建 FieldMappings 对象,然后通过添加要组合的输入要素类或表对 FieldMap 对象进行初始化。提供了所有输入后,FieldMappings 对象将为所有输入中的每个唯一字段名提供一个 FieldMap 对象或输出字段。可对此列表进行修改,具体方法有添加新字段、更改输出字段的属性和/或内容,或移除任何不需要的输出字段。

FieldMap 对象的属性包括输入文本值的起始位置和结束位置,因此可以使用一组输入值创建新的输出值。如果 FieldMap 对象包含多个来自同一表或要素类的输入字段,则将使用 mergeRule 属性合并每个记录的值。这样可以方便地连接各个值,例如保存在一个字段中的街道名称以及保存在另一个字段中的街道类型,如 Eureka 和 Street。如果将 mergeRule 的值指定为 Join,则使用 FieldMap 的 joinDelimiter 属性。任何字符集(如空格)都可用作分隔符。在以上示例中,将会创建值 Eureka Street。

语法

 FieldMappings  ()

属性

属性说明数据类型
fieldCount
(只读)

The number of output fields.

Integer
fieldMappings
(读写)

A list of FieldMap objects that make up the FieldMappings object.

FieldMap
fieldValidationWorkspace
(读写)

The workspace type that defines the rules for attribute field naming. These rules are used when determining the output field names, which are based on the names of the input fields. For example, setting the fieldValidationWorkspace property to the path of a folder on disk containing the input shapefiles will result in the output field names being truncated to 10 characters. Setting the fieldValidationWorkspace property to the path of a file geodatabase will allow for much longer field names. The fieldValidationWorkspace property should be set with a consideration for the output format.

String
fields
(只读)

A list of Field objects. Each field object represents the properties of each output field.

Field

方法概述

方法说明
addFieldMap (field_map)

向字段映射中添加一个字段映射。

addTable (table_dataset)

将表添加到字段映射对象。

exportToString ()

将对象导出至其字符串表示。

findFieldMapIndex (field_map_name)

按名称查找字段映射内的字段映射。

getFieldMap (index)

获取多个字段映射中的一个字段映射。

loadFromString (string)

使用对象的字符串表示来恢复对象。可以使用 exportToString 方法创建字符串表示。

removeAll ()

移除所有值并创建一个空对象。

removeFieldMap (index)

从字段映射中移除一个字段映射。

replaceFieldMap (index, value)

在字段映射内替换一个字段映射。

方法

addFieldMap (field_map)
参数说明数据类型
field_map

要添加到字段映射中的字段映射

FieldMap
addTable (table_dataset)
参数说明数据类型
table_dataset

要添加到字段映射对象中的表。

String
exportToString ()

返回值

数据类型说明
String

对象的字符串表示。

findFieldMapIndex (field_map_name)
参数说明数据类型
field_map_name

按名称查找字段映射。

String

返回值

数据类型说明
Integer

字段映射的索引位置。

getFieldMap (index)
参数说明数据类型
index

字段映射的索引位置。

Integer

返回值

数据类型说明
FieldMap

多个字段映射中的一个字段映射。

loadFromString (string)
参数说明数据类型
string

对象的字符串表示。

String
removeAll ()
removeFieldMap (index)
参数说明数据类型
index

字段映射的索引位置。

Integer
replaceFieldMap (index, value)
参数说明数据类型
index

待替换的字段映射的索引位置。

Integer
value

替换字段映射。

FieldMap

代码实例

FieldMappings 示例

需要将相似数据集合并到一个无所不包的数据集中时,通常使用 FieldMap 对象。在该示例中,要素类 Trees 和 shapefile Plants.shp 合并至一个要素类:Vegetation。两个初始要素类均有两个属性:类型与直径。两个属性都必须通过合并进行维护。

import arcpy

# Set the workspace
arcpy.env.workspace = 'c:/base'

in_file1 = 'data.gdb/Trees'
in_file2 = 'Plants.shp'
output_file = 'data.gdb/Vegetation'

# Create the required FieldMap and FieldMappings objects
fm_type = arcpy.FieldMap()
fm_diam = arcpy.FieldMap()
fms = arcpy.FieldMappings()

# Get the field names of vegetation type and diameter for both original
# files
tree_type = "Tree_Type"
plant_type = "Plant_Type"

tree_diam = "Tree_Diameter"
plant_diam = "Diameter"

# Add fields to their corresponding FieldMap objects
fm_type.addInputField(in_file1, tree_type)
fm_type.addInputField(in_file2, plant_type)

fm_diam.addInputField(in_file1, tree_diam)
fm_diam.addInputField(in_file2, plant_diam)

# Set the output field properties for both FieldMap objects
type_name = fm_type.outputField
type_name.name = 'Veg_Type'
fm_type.outputField = type_name

diam_name = fm_diam.outputField
diam_name.name = 'Veg_Diam'
fm_diam.outputField = diam_name

# Add the FieldMap objects to the FieldMappings object
fms.addFieldMap(fm_type)
fms.addFieldMap(fm_diam)

# Merge the two feature classes
arcpy.Merge_management([in_file1, in_file2], output_file, fms)
FieldMappings 示例 2

此示例使用 FeatureClassToFeatureClass 工具显示使用 FieldMap 对象合并字段的选项。在本示例中,要素类包含城市交叉点事故数量的信息。在一个字段中维护各年数据。用户想要在不更改现有表的情况下,查找各交叉点的平均事故数量。

import arcpy

# Set the workspace
arcpy.env.workspace = 'c:/base/data.gdb'

in_file = 'AccidentData'
out_file = 'AverageAccidents'

# Create the necessary FieldMap and FieldMappings objects
fm = arcpy.FieldMap()
fm1 = arcpy.FieldMap()
fms = arcpy.FieldMappings()

# Each field with accident data begins with 'Yr' (from Yr2007 to Yr2012).
# The next step loops through each of the fields beginning with 'Yr',
# and adds them to the FieldMap Object
for field in arcpy.ListFields(in_file, 'Yr*'):
    fm.addInputField(in_file, field.name)

# Set the merge rule to find the mean value of all fields in the
# FieldMap object
fm.mergeRule = 'Mean'

# Set properties of the output name.
f_name = fm.outputField
f_name.name = 'AvgAccidents'
f_name.aliasName = 'AvgAccidents'
fm.outputField = f_name

# Add the intersection field to the second FieldMap object
fm1.addInputField(in_file, "Intersection")

# Add both FieldMaps to the FieldMappings Object
fms.addFieldMap(fm)
fms.addFieldMap(fm1)

# Create the output feature class, using the FieldMappings object
arcpy.FeatureClassToFeatureClass_conversion(
    in_file, arcpy.env.workspace, out_file, field_mapping=fms)

相关主题

  • 将输入字段映射到输出字段
  • FieldMap
有关此主题的反馈?

ArcGIS for Desktop

  • 主页
  • 文档
  • 合约
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • 内部人员博客
  • 用户大会
  • 开发者峰会
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | 隐私政策 | 法律声明