添加附件 (Data Management)

许可等级:BasicStandardAdvanced

摘要

向地理数据库要素类或表的记录中添加文件附件。附件以单独附件表的形式存储在地理数据库中,该表与目标数据集保持连接。使用匹配表将附件添加到目标数据集中,该表指定了针对每个输入记录(或记录的属性组)向该记录中添加的附件文件的路径。

了解有关地理数据库附件的详细信息

了解有关使用附件地理处理工具的详细信息

插图

Add Attachment tool illustration
Add Attachments illustration

用法

语法

AddAttachments_management (in_dataset, in_join_field, in_match_table, in_match_join_field, in_match_path_field, {in_working_folder})
参数说明数据类型
in_dataset

要添加附件的地理数据库表或要素类。附件不直接添加到该表中,而是添加到关联的附件表,该附件表保持与输入数据集的连接。

输入数据集必须存储在 10.0 或更高版本的地理数据库中,而且表的附件必须已经启用。

Table View
in_join_field

输入数据集中值与匹配连接字段中的值相匹配的字段。输入数据集匹配表之间的连接字段值匹配的记录将添加附件。该字段可以是“对象 ID”字段或其他任何标识属性。

Field
in_match_table

用于确定将为哪些输入记录添加附件并确定附件路径的表文件。

Table View
in_match_join_field

匹配表中的字段,指示输入数据集中的哪些记录将添加指定附件。该字段的值可与输入数据集“对象 ID”或某些其他标识属性相匹配。

Field
in_match_path_field

匹配表中的字段,包含要添加到输入数据集记录中的附件的路径。

Field
in_working_folder
(可选)

集中存放附件文件的文件夹或工作空间。通过指定工作文件夹,匹配路径字段中的路径可以是相对于工作文件夹的短文件名称。

例如,如果加载路径为 C:\MyPictures\image1.jpgC:\MyPictures\image2.jpg 的附件,将工作文件夹设置为 C:\MyPictures 后,匹配路径字段中的路径就可以使用 image1.jpgimage2.jpg 等短名称,而不必使用较长的完整路径。

Folder

代码实例

AddAttachments 示例(Python 窗口)

以下代码片段说明了如何在 Python 窗口中使用 AddAttachments 工具。

import arcpy
arcpy.AddAttachments_management(r"C:\Data\City.gdb\Parcels", "ParcelID", r"C:\Data\matchtable.csv", "ParcelID","Picture" , r"C:\Pictures")
AddAttachments 示例(独立 Python 脚本)

以下脚本说明了如何在独立脚本中使用 AddAttachments 工具。

"""
Example: we have a folder of digital photographs of vacant homes; the photos
are named according to the ParcelID of the house in the picture. Let's add
these photos to a parcel feature class as attachments.
"""

import csv
import arcpy
import os
import sys

input = r"C:\Data\City.gdb\Parcels"
inputField = "ParcelID"
matchTable = r"C:\Data\matchtable.csv"
matchField = "ParcelID"
pathField = "Picture" 
picFolder = r"C:\Pictures"

try:
    # create a new Match Table csv file
    writer = csv.writer(open(matchTable, "wb"), delimiter=",")

    # write a header row (the table will have two columns: ParcelID and Picture)
    writer.writerow([matchField, pathField])

    # iterate through each picture in the directory and write a row to the table
    for file in os.listdir(picFolder):
        if str(file).find(".jpg") > -1:
            writer.writerow([str(file).replace(".jpg", ""), file])

    del writer

    # the input feature class must first be GDB attachments enabled
    arcpy.EnableAttachments_management(input)

    # use the match table with the Add Attachments tool
    arcpy.AddAttachments_management(input, inputField, matchTable, matchField, pathField, picFolder)
except:
    print arcpy.GetMessages(2)

环境

相关主题

许可信息

ArcGIS for Desktop Basic:否
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013