Merge

Title  Merge

Summary

Combina múltiplas entradas em único dado de saída.


Illustration

Merge tool

Usage


Syntax

Parameter Explanation
inputs

Dados de entrada podem ser ponto, linha, polígono ou tabela.

output (Optional)

Conjunto de dados que irá conter os dados de entrada combinados.

field_mappings (Optional)

Controls how the attribute fields from the input datasets are mapped and transferred to the output dataset.You can add, rename, or delete output fields as well as set properties, such as data type and merge rule.Merge rules allow you to specify how values from two or more input fields are merged or combined into a single output value. There are several merge rules that determine how the output field is populated with values.First—Use the input fields' first value.Last—Use the input fields' last value.Join—Concatenate (join) the input fields' values.Sum—Calculate the total of the input fields' values.Mean—Calculate the mean (average) of the input fields' values.Median—Calculate the median (middle) of the input fields' values.Mode—Use the value with the highest frequency.Min—Use the minimum value of all input fields' values.Max—Use the maximum value of all input fields' values.Standard deviation—Use the standard deviation classification method on all input fields' values.Count—Find the number of records included in the calculation.

add_source (Optional)

Specifies whether source information will be added to the output dataset in a new text field, MERGE_SRC. The values in the MERGE_SRC field will indicate the input dataset path or layer name that is the source of each record in the output. Unchecked—Source information will not be added to the output dataset in a MERGE_SRC field. This is the default.Checked—Source information will be added to the output dataset in a MERGE_SRC field.

esri_out_feature_service_name (Optional)

The name of the optional feature service to create on the federated server containing the result of this tool. If no name is specified an output feature service will not be created.

Code Samples

Merge example 1 (Python window)

The following Python window script demonstrates how to use the Merge tool.


import arcpy
arcpy.env.workspace = "C:/data"
arcpy.Merge_management(["majorrds.shp", "Habitat_Analysis.gdb/futrds"], 
                       "C:/output/Output.gdb/allroads", "", "ADD_SOURCE_INFO")

                    

Merge example 2 (stand-alone script)

Use the Merge tool to move features from two street feature classes into a single dataset.


# 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

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

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

# 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, 
                       addSourceInfo)

                    

Tags

Credits

Use limitations