合并 (Data Management)

许可等级:BasicStandardAdvanced

摘要

将数据类型相同的多个输入数据集合并为新的单个输出数据集。此工具可以合并点、线或面要素类或表。

使用追加工具可将输入数据集合并到现有数据集。

插图

Merge Illustration

用法

语法

Merge_management (inputs, output, {field_mappings})
参数说明数据类型
inputs
[inputs,...]

要合并为新的输出数据集的输入数据集。输入数据集可为点、线或面要素类或是表。所有输入数据集的数据类型必须一致。

Table View
output

包含所有合并后输入数据集的输出数据集。

Feature Class;Table
field_mappings
(可选)

从输入数据中选出的字段及字段内容。“字段映射”窗口将列出每一个唯一输入字段,展开后您将看到所有输入字段的列表。

对于每个“字段映射”,均可添加、重命名或删除输出字段,还可设置诸如数据类型和合并规则等属性。您也可删除出现的输出字段并设置任何输出字段的值的格式。

Field Mappings

代码实例

Merge 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何使用“合并”工具。

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.Merge_management(["majorrds.shp", "Habitat_Analysis.gdb/futrds"], "C:/output/Output.gdb/allroads")
Merge 示例 2(独立脚本)

使用“合并”工具可将两个街区要素类中的要素移动到一个单独的数据集中。

# Name: Merge.py
# Description: Use Merge tool to move features from two street
#                    feature classes into a single dataset with field mapping

# import system modules 
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Street feature classes to be merged
oldStreets = "majorrds.shp"
newStreets = "Habitat_Analysis.gdb/futrds"

# Create FieldMappings object to manage merge output fields
fieldMappings = arcpy.FieldMappings()

# Add all fields from both oldStreets and newStreets
fieldMappings.addTable(oldStreets)
fieldMappings.addTable(newStreets)

# Add input fields "STREET_NAM" & "NM" into new output field
fldMap_streetName = arcpy.FieldMap()
fldMap_streetName.addInputField(oldStreets,"STREET_NAM")
fldMap_streetName.addInputField(newStreets,"NM")
# Set name of new output field "Street_Name"
streetName = fldMap_streetName.outputField
streetName.name = "Street_Name"
fldMap_streetName.outputField = streetName
# Add output field to field mappings object
fieldMappings.addFieldMap(fldMap_streetName)

# Add input fields "CLASS" & "IFC" into new output field
fldMap_streetClass = arcpy.FieldMap()
fldMap_streetClass.addInputField(oldStreets,"CLASS")
fldMap_streetClass.addInputField(newStreets,"IFC")
# Set name of new output field "Street_Class"
streetClass = fldMap_streetClass.outputField
streetClass.name = "Street_Class"
fldMap_streetClass.outputField = streetClass  
# Add output field to field mappings object
fieldMappings.addFieldMap(fldMap_streetClass)  

# Remove all output fields from the field mappings, except fields "Street_Class", "Street_Name", & "Distance"
for field in fieldMappings.fields:
    if field.name not in ["Street_Class","Street_Name","Distance"]:
        fieldMappings.removeFieldMap(fieldMappings.findFieldMapIndex(field.name))

# Since both oldStreets and newStreets have field "Distance", no field mapping is required

# Use Merge tool to move features into single dataset
uptodateStreets = "C:/output/Output.gdb/allroads"
arcpy.Merge_management([oldStreets, newStreets], uptodateStreets, fieldMappings)

环境

相关主题

许可信息

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