查找相同的 (Data Management)
插图
![]() |
In this example, points with the OBJECTIDs of 1,2, 3, 8, 9, and 10 are spatially coincident (blue highlight). The output table identifies those spatially coincident points that share the same CATEGORY. |
用法
-
如果选定的输入字段值与这些记录值相同,则这些记录为相同记录。可对输入数据集中多个字段的值进行比较。如果指定了多个字段,则记录将首先按第一个字段中的值进行匹配,然后按第二个字段的值进行匹配,依此类推。
-
对于要素类或要素图层输入,请选择字段参数中的 Shape 字段来比较要素几何,以按位置查找相同的要素。仅当“Shape”被选作其中一个输入字段时,XY 容差和 Z 容差参数才有效。
如果选择了 Shape 字段并且输入要素的 M 值或 Z 值可用,则也可利用 M 值或 Z 值确定相同要素。
如果在输出表中仅需要重复的记录,则选中仅输出重复记录参数。如果未选中此参数(默认),则输出的记录数与输入数据集的记录数相同。
-
输出表含有两个字段:IN_FID 和 FEAT_SEQ。
- IN_FID 字段可用于将输出表的记录连接到输入数据集。
- 相同的记录具有相同的 FEAT_SEQ 值,而不相同的记录具有顺序值。FEAT_SEQ 值与输入记录 ID 无关。
语法
参数 | 说明 | 数据类型 |
in_dataset |
要查找相同记录的表或要素类。 | Table View |
out_dataset |
用于报告相同记录的输出表。在输出表中,相同记录的 FEAT_SEQ 字段具有相同值。 | Table |
fields [fields,...] | 将对字段值进行比较以查找相同记录的一个或多个字段。 | Field |
xy_tolerance (可选) |
在计算时应用于每个折点的 xy 容差(如果另一要素中存在相同的折点)。仅当“Shape”被选作其中一个输入字段时,此参数才可用。 | Linear unit |
z_tolerance (可选) |
在计算时应用于每个折点的 z 容差(如果另一要素中存在相同的折点)。仅当“Shape”被选作其中一个输入字段时,此参数才可用。 | Double |
output_record_option (可选) |
当仅需要在输出表中包含重复记录时选择。
| Boolean |
代码实例
以下 Python 窗口脚本演示了如何在即时模式下使用 FindIdentical 函数。
import arcpy
# Find identical records based on a text field and a numeric field.
arcpy.FindIdentical_management("C:/data/fireincidents.shp", "C:/output/duplicate_incidents.dbf", ["ZONE", "INTENSITY"])
以下独立脚本演示了如何使用 FindIdentical 工具识别表或要素类的重复记录。
# Name: FindIdentical_Example2.py
# Description: Finds duplicate features in a dataset based on location (Shape field) and fire intensity
import arcpy
from arcpy import env
env.overwriteOutput = True
# Set workspace environment
env.workspace = "C:/data/findidentical.gdb"
try:
# Set input feature class
in_dataset = "fireincidents"
# Set the fields upon which the matches are found
fields = ["Shape", "INTENSITY"]
# Set xy tolerance
xy_tol = ".02 Meters"
out_table = "duplicate_incidents"
# Execute Find Identical
arcpy.FindIdentical_management(in_dataset, out_table, fields, xy_tol)
print arcpy.GetMessages()
except arcpy.ExecuteError:
print arcpy.GetMessages(2)
except Exception as ex:
print ex.args[0]
演示如何使用仅输出重复记录的可选参数。如果在工具对话框中选中或设置了 ONLY_DUPLICATES 值,则删除所有的唯一记录,仅保留输出中的重复记录。
# Name: FindIdentical_Example3.py
# Description: Demonstrates the use of the optional parameter Output only duplicated records.
import arcpy
from arcpy import env
env.overwriteOutput = True
# Set workspace environment
env.workspace = "C:/data/redlands.gdb"
try:
in_data = "crime"
out_data = "crime_dups"
# Note that XY Tolerance and Z Tolerance parameters are not used
# In that case, any optional parameter after them must assign
# the value with the name of that parameter
arcpy.FindIdentical_management(in_data, out_data, ["Shape"], output_record_option="ONLY_DUPLICATES")
print arcpy.GetMessages()
except Exception as ex:
print arcpy.GetMessages(2)
print ex.args[0]
读取 FindIdentical 工具的输出并利用 FEAT_SEQ 值将相同记录分组。
import arcpy
from itertools import groupby
from operator import itemgetter
# Set workspace environment
arcpy.env.workspace = r"C:\data\redlands.gdb"
# Run Find Identical on feature geometry only.
result = arcpy.FindIdentical_management("parcels", "parcels_dups", ["Shape"])
# List of all output records as IN_FID and FEAT_SEQ pair - a list of lists
out_records = []
for row in arcpy.SearchCursor(result.getOutput(0), fields="IN_FID; FEAT_SEQ"):
out_records.append([row.IN_FID, row.FEAT_SEQ])
# Sort the output records by FEAT_SEQ values
# Example of out_records = [[3, 1], [5, 3], [1, 1], [4, 3], [2, 2]]
out_records.sort(key = itemgetter(1))
# records after sorted by FEAT_SEQ: [[3, 1], [1, 1], [2, 2], [5, 3], [4, 3]]
# records with same FEAT_SEQ value will be in the same group (i.e., identical)
identicals_iter = groupby(out_records, itemgetter(1))
# now, make a list of identical groups - each group in a list.
# example identical groups: [[3, 1], [2], [5, 4]]
# i.e., IN_FID 3, 1 are identical, and 5, 4 are identical.
identical_groups = [[item[0] for item in data] for (key, data) in identicals_iter]
print identical_groups