Atributos a transferir (Edición)

Resumen

Busca el lugar dónde las entidades de línea de origen coinciden espacialmente con las de destino y transfiere los atributos especificados de las entidades de origen a las entidades de destino coincidentes.

La transferencia de atributos se utiliza normalmente para copiar los atributos desde las entidades de un dataset a las entidades correspondientes de otro dataset. Por ejemplo, se puede utilizar para transferir los nombres desde entidades de carretera de un dataset previamente conservado y digitalizado a entidades de un nuevo dataset que se han capturado recientemente y son más precisas. Para referirse a los dos datasets se suelen utilizar los términos entidades de origen y entidades de destino. Esta herramienta busca las entidades de línea de origen y destino correspondientes dentro de una distancia de búsqueda especificada y transfiere los atributos especificados de las líneas de origen a las líneas de destino.

Ilustración

Atributos a transferir

Uso

Sintaxis

TransferAttributes_edit (source_features, target_features, transfer_fields, search_distance, {match_fields}, {out_match_table})
ParámetroExplicaciónTipo de datos
source_features

Entidades de línea desde las que se transfieren atributos.

Feature Layer
target_features

Entidades de línea a las que se transfieren atributos. Los campos de transferencia especificados se agregan a las entidades de destino.

Feature Layer
transfer_fields
[field,...]

Lista de campos de origen que se transfieren a entidades de destino. Se debe especificar al menos un campo.

Field
search_distance

Distancia utilizada para buscar candidatos que coinciden. Se debe especificar una distancia, que debe ser mayor que cero. Puede elegir la unidad que prefiera; el valor predeterminado es la unidad de la entidad.

Linear unit
match_fields
[[source_field, target_field],...]
(Opcional)

Listas de campos de entidades de origen y de destino. Si se especifican, cada pareja de campos se comprueba para candidatos coincidentes con el fin de ayudar a determinar la concordancia adecuada.

Value Table
out_match_table
(Opcional)

Tabla de salida que contiene información completa de coincidencia de entidades.

Table

Ejemplo de código

Ejemplo 1 de TransferAttributes (ventana de Python)

La siguiente secuencia de comandos de la ventana de Python demuestra cómo utilizar la función TransferAttributes en el modo inmediato.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.TransferAttributes_edit("source_Roads.shp",
                              "target_Roads.shp", "RoadName, PaveType"
                              "25 Feet")
Ejemplo 2 de TransferAttributes (secuencia de comandos de Python independiente)

La siguiente secuencia de comandos independiente es un ejemplo imple de cómo aplicar la función TransferAttributes en un entorno de secuencias de comandos.

# Name:        TransferAttributes_example_script2.py
# Description: Performs attribute transfer from newly updated roads (source) to existing
#              base roads (target). Where the source and target features are matched in
#              many-to-one or many-to-many (m:n) relationships, attributes are transferred 
#              from only one of the m source features to the n target features. This script
#              includes a post-process that flags resulting target features with the m:n
#              match relationships. You can inspect the flagged features and retrieve the
#              attributes from the desired source features if necessary.
# Author:      Esri
# -----------------------------------------------------------------------

# Import system modules
import arcpy
from arcpy import env

# Set environment settings
env.overwriteOutput = True
env.workspace = r"D:\conflationTools\ScriptExamples\data.gdb"

# Set local variables
sourceFeatures = "updateRoads"
targetFeatures = "baseRoads"
transfer_fields = "RD_NAME; RD_ID"

search_distance = "300 Feet"
match_fields = "RD_NAME FULLNAME"

outMatchTable = "ta_mtbl"

# Make a copy of the targetFeatures for attribute transfer
targetCopy = targetFeatures + "_Copy"
arcpy.CopyFeatures_management(targetFeatures, targetCopy)

# Performs attribute transfer
arcpy.TransferAttributes_edit(sourceFeatures, targetCopy, transfer_fields, search_distance, match_fields, outMatchTable)

# ====================================================================================
# Note 1:  The result of TransferAttributes may contain errors; see tool reference.
#          Additional analysis steps may be necessary to check the results; these steps
#          are not included in this script.
#
#          The following process identifies m:n matches between source and target features 
#          and flag features in targetCopy for inspection.
# ====================================================================================

# Add a field srcM_inMN to the match table to store the m count of source features in m:n relationship
field_srcM_inMN = "srcM_inMN"
arcpy.AddField_management(outMatchTable, field_srcM_inMN)

codeblock = """
def getM(fld):
    x = fld.split(\":\")[0]
    if x.isnumeric():
        if int(x) > 0:
            return int(x)
    return -1
"""

# Calculate values for srcM_inMN
arcpy.CalculateField_management(outMatchTable, field_srcM_inMN, "getM(!FM_MN!)", "PYTHON_9.3", codeblock)

# Make a table view of the match table, selecting srcM_inMN values greater than 1 
# (excluding 1:n relationships which don't need to be inspected)
arcpy.MakeTableView_management(outMatchTable, "mtable_view", field_srcM_inMN + "> 1")

# For the selected records, transfer srcM_inMN and SRC_FID fields and values to the targetCopy
arcpy.JoinField_management(targetCopy, "OBJECTID", "mtable_view", "TGT_FID", field_srcM_inMN + "; SRC_FID")

# ====================================================================================
# Note 2:  Now the fields srcM_inMN and SRC_FID are in the copy of the target features.
#          The srcM_inMN values are the counts of matched source features; the SRC_FID
#          values indicate the source feature IDs from which the transferred attributes
#          come from.
#
#          At this point you can interactively review the transferred attributes for the
#          flagged features. If you want to replace any of them by those from a different
#          source feature, you would need to make the edits as needed.
# ====================================================================================

Entornos

Temas relacionados

5/9/2014