传递属性 (Editing)
摘要
查找源线要素与目标线要素空间上匹配的位置,并将指定属性从源要素传递到互相匹配的目标要素。
属性传递一般用于将属性从某数据集中的要素复制到另一数据集中的对应要素。例如,可以用于将道路要素的名称从之前数字化并维护的数据集传递到新收集的、具有更高精度的新数据集中的道路要素。这两个数据集通常称为源要素与目标要素。该工具在指定搜索距离内查找相应的源线要素与目标线要素,并将指定属性从源线传递到目标线。
插图
用法
-
输入范围的并集用作处理范围。参与源要素与目标要素的计数会在处理消息中报告。
-
必须在传递字段参数中指定一个或多个字段。如果传递字段的名称与目标要素表中某字段的名称相同,为使名称唯一,传递字段的名称将追加 _1(或 _2、_3 等)。
当多个源要素与一个或多个目标要素匹配时,仅会将来自其中一个源要素的字段值传递至目标要素。如果源字段值丢失,则不会发生任何属性传递。
-
搜索距离参数用于查找匹配候选项。使用足以获取相应要素间大多数偏移的距离,但是距离不可过大,以防止出现对过多候选项的不必要处理并避免得出错误匹配的潜在风险。
-
输出匹配表为可选项。此匹配表可提供完整的要素匹配信息,其中包括源 FID 与目标 FID、匹配组、匹配关系以及从空间和属性匹配条件中获取的匹配置信度级别。此信息能够帮助您了解匹配情况,并有助于进行后检查、后编辑和进一步分析。有关详细信息,请参阅 About_feature_matching_and_the_match_table。
要素匹配精度取决于两个输入的数据质量、复杂程度和相似程度。
在预处理过程中,您需要尽可能减少数据错误,并选择相关要素作为输入。通常情况下,如果某个输入数据集内的要素具有正确的拓扑结构和有效的几何,且本身为单部件而无重复,这将非常有用;否则可能会出现意外结果。
此工具用于修改输入数据。有关详细信息以及避免数据被意外更改的策略,请参阅无输出的工具。
所有输入必须处于同一坐标系。
语法
参数 | 说明 | 数据类型 |
source_features |
传递属性的源线要素。 | Feature Layer |
target_features |
传递属性的目标线要素。指定的传递字段会添加到目标要素。 | Feature Layer |
transfer_fields [field,...] |
要传递至目标要素的源字段列表。必须至少指定一个字段。 | Field |
search_distance |
用于搜索匹配候选项的距离。必须指定一个距离,且此距离必须大于零。可以选择首选单位;默认为要素单位。 | Linear unit |
match_fields [[source_field, target_field],...] (可选) |
来自源要素与目标要素的字段的列表。在经过指定的情况下,检查每对字段是否为匹配候选项,从而帮助确定正确的匹配。 | Value Table |
out_match_table (可选) |
包含完整要素匹配信息的输出表。 | Table |
代码实例
下面的 Python 窗口脚本演示了如何在即时模式下使用传递属性 (TransferAttributes) 函数。
import arcpy
arcpy.env.workspace = "C:/data"
arcpy.TransferAttributes_edit("source_Roads.shp",
"target_Roads.shp", "RoadName, PaveType"
"25 Feet")
下面的独立脚本演示了如何在脚本环境中应用传递属性 (TransferAttributes) 函数。
# Name: TransferAttributes_example_script2.py
# Description: Performs attribute transfer from newly updated roads (source) to existing
# base roads (target). Where the source and target features are matched in
# many-to-one or many-to-many (m:n) relationships, attributes are transferred
# from only one of the m source features to the n target features. This script
# includes a post-process that flags resulting target features with the m:n
# match relationships. You can inspect the flagged features and retrieve the
# attributes from the desired source features if necessary.
# Author: Esri
# -----------------------------------------------------------------------
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.overwriteOutput = True
env.workspace = r"D:\conflationTools\ScriptExamples\data.gdb"
# Set local variables
sourceFeatures = "updateRoads"
targetFeatures = "baseRoads"
transfer_fields = "RD_NAME; RD_ID"
search_distance = "300 Feet"
match_fields = "RD_NAME FULLNAME"
outMatchTable = "ta_mtbl"
# Make a copy of the targetFeatures for attribute transfer
targetCopy = targetFeatures + "_Copy"
arcpy.CopyFeatures_management(targetFeatures, targetCopy)
# Performs attribute transfer
arcpy.TransferAttributes_edit(sourceFeatures, targetCopy, transfer_fields, search_distance, match_fields, outMatchTable)
# ====================================================================================
# Note 1: The result of TransferAttributes may contain errors; see tool reference.
# Additional analysis steps may be necessary to check the results; these steps
# are not included in this script.
#
# The following process identifies m:n matches between source and target features
# and flag features in targetCopy for inspection.
# ====================================================================================
# Add a field srcM_inMN to the match table to store the m count of source features in m:n relationship
field_srcM_inMN = "srcM_inMN"
arcpy.AddField_management(outMatchTable, field_srcM_inMN)
codeblock = """
def getM(fld):
x = fld.split(\":\")[0]
if x.isnumeric():
if int(x) > 0:
return int(x)
return -1
"""
# Calculate values for srcM_inMN
arcpy.CalculateField_management(outMatchTable, field_srcM_inMN, "getM(!FM_MN!)", "PYTHON_9.3", codeblock)
# Make a table view of the match table, selecting srcM_inMN values greater than 1
# (excluding 1:n relationships which don't need to be inspected)
arcpy.MakeTableView_management(outMatchTable, "mtable_view", field_srcM_inMN + "> 1")
# For the selected records, transfer srcM_inMN and SRC_FID fields and values to the targetCopy
arcpy.JoinField_management(targetCopy, "OBJECTID", "mtable_view", "TGT_FID", field_srcM_inMN + "; SRC_FID")
# ====================================================================================
# Note 2: Now the fields srcM_inMN and SRC_FID are in the copy of the target features.
# The srcM_inMN values are the counts of matched source features; the SRC_FID
# values indicate the source feature IDs from which the transferred attributes
# come from.
#
# At this point you can interactively review the transferred attributes for the
# flagged features. If you want to replace any of them by those from a different
# source feature, you would need to make the edits as needed.
# ====================================================================================