查找相同的 (Data Management)

许可等级:BasicStandardAdvanced

摘要

报告要素类或表中在一系列字段中具有相同值的所有记录并生成一个列表文件以列出记录。如果选择了 Shape 字段,将会对要素几何进行比较。

删除相同的工具可用于查找并删除相同记录。

插图

Find Identical illustration
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.

用法

语法

FindIdentical_management (in_dataset, out_dataset, fields, {xy_tolerance}, {z_tolerance}, {output_record_option})
参数说明数据类型
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
(可选)

当仅需要在输出表中包含重复记录时选择。

  • ALL所有输入记录在输出表中都有对应的记录。这是默认设置。
  • ONLY_DUPLICATES仅重复记录在输出表中有对应的记录。无重复记录时输出为空。
Boolean

代码实例

FindIdentical 示例 1(Python 窗口)

以下 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 示例 2(独立脚本)

以下独立脚本演示了如何使用 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]
FindIdentical 示例 3:仅输出重复记录(独立脚本)

演示如何使用仅输出重复记录的可选参数。如果在工具对话框中选中或设置了 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 示例 4:利用 FEAT_SEQ 值将相同记录分组

读取 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

环境

相关主题

许可信息

ArcGIS for Desktop Basic: 否
ArcGIS for Desktop Standard: 否
ArcGIS for Desktop Advanced: 是
5/10/2014