This document is archived and information here might be outdated.  Recommended version.


IAttributeTransfer Interface (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Editor > ESRI.ArcGIS.Editor > Interfaces > IA > IAttributeTransfer Interface
ArcGIS Developer Help

IAttributeTransfer Interface

Provides access to members that control the behavior of the attribute transfer tools.

Product Availability

Available with ArcGIS Desktop.

When To Use

Use this interface to perform an Attribute Transfer via the Transfer method. This method requires a fieldmap which can either be created programmatically or retrieved from the Attribute Transfer environment if set by the dialog on the Spatial Adjustment menu.

Members

Name Description
Method DeleteFieldMap Delete a field map.
Write-only property FieldMap Adds a field map. This will overwrite any existing field map with the same pair of source and target object classes.
Method FindFieldMap Finds a stored field mapping. A field map with any source or target can be found by place a null for the argument.
Read-only property Name Name of the current attribute type.
Method Transfer Transfer attributes between rows based on the field map.

Classes that implement IAttributeTransfer

Classes Description
AttributeTransfer (esriEditorExt) Transfers attribute values from one row to another based on a fieldmap.
[C#]

The following code shows an example of transferring attributes between two line layers. It assumes an attribute transfer map (FieldMap) has been setup via the Spatial Adjustment Attribute Transfer Mapping dialog and that the source and target line layers are aligned (via rubbersheeting for example). The code will transfer attributes from selected source features to underlying target features.Public Sub AttribTrans()

public override void OnClick()
{
IMxDocument mxDoc = m_app.Document as IMxDocument;
IMap map = mxDoc.FocusMap;
      //Get the editor.
if (m_app == null)
return;
      IEditor editor = m_app.FindExtensionByName("ESRI Object Editor") as IEditor;

//Cast for Attribute Transfer Type and get IAttributeTransfer.
IAttributeTransferType attTransType = editor as IAttributeTransferType;
IAttributeTransfer attTransfer = attTransType.AttributeTransfer;
      //Cast for default settings and return source/target layers.
IAttributeTransferDefaultSettings attTransDefSettings = attTransfer as
IAttributeTransferDefaultSettings;
IFeatureLayer2 sourceFL = ReturnLayer(map, attTransDefSettings.SourceName);
      //If no mapping set, sourceFL will be null (null sourcename) so bail
if (sourceFL == null)
{
System.Windows.Forms.MessageBox.Show
("Attribute Transfer field mapping not set");
return;
}
      //Get target feature layer.
IFeatureLayer2 tFLayer = ReturnLayer(map, attTransDefSettings.TargetName);
      //Get the fieldmap for the source layer.
IFieldMap fieldMap = attTransfer.FindFieldMap(sourceFL.FeatureClass, null);
      //Enumerate through each selected feature (selection from source layer)
IEnumFeature featEnum = editor.EditSelection as IEnumFeature;
featEnum.Reset();
IFeature sourceFeature = featEnum.Next();
if (sourceFeature == null)
{
System.Windows.Forms.MessageBox.Show("Please Selecet a Source Feature");
}
      editor.StartOperation();
while (sourceFeature != null)
{
//Get the midpoint of the selected polyline.
ICurve curve = sourceFeature.Shape as ICurve;
IPoint curveMidPoint = new ESRI.ArcGIS.Geometry.Point();
curve.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, curveMidPoint);
        //Setup spatial filter.
ISpatialFilter spatialFilter = new SpatialFilter();
spatialFilter.Geometry = curveMidPoint;
spatialFilter.GeometryField = "SHAPE";
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
        //Search target layer.
IFeatureCursor targetFeatCursor = tFLayer.Search(spatialFilter, true);
IFeature targetFeature = targetFeatCursor.NextFeature();
//Transfer attributes to first target feature.
bool success;
try
{
if (targetFeature != null)
{
attTransfer.Transfer(fieldMap, sourceFeature, targetFeature, out success);
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
sourceFeature = featEnum.Next();
}
editor.StopOperation("Attribute Transfer");
}
/// <summary>
/// Find a layer in a map document
/// Return the layer or nothing if not found
/// </summary>
private IFeatureLayer2 ReturnLayer(IMap map, String layerName)
{
IEnumLayer layerEnumeration = map.get_Layers(null, true);
layerEnumeration.Reset();
ILayer currentLayer = layerEnumeration.Next();
      while (currentLayer != null)
{
if (currentLayer.Name == layerName)
{
return (IFeatureLayer2)currentLayer;
}
currentLayer = layerEnumeration.Next();
}
return null;
}
[Visual Basic .NET]

Public Overrides Sub OnClick()
    Dim mxDoc As IMxDocument
    Dim map As IMap

    mxDoc = m_application.Document
    map = mxDoc.FocusMap

    'QI for Attribute Transfer Type and get IAttributeTransfer
    Dim attTransType As IAttributeTransferType
    attTransType = CType(m_editor, IAttributeTransferType)
    Dim attTrans As IAttributeTransfer
    attTrans = attTransType.AttributeTransfer

    'QI for default settings and return source/target layers
    Dim attTDSettings As IAttributeTransferDefaultSettings
    attTDSettings = CType(attTrans, IAttributeTransferDefaultSettings)
    Dim sFL As IFeatureLayer2
    sFL = ReturnLayer(map, attTDSettings.SourceName)

    'If no mapping set, pSfl will be nothing (null sourcename) so bail
    If sFL Is Nothing Then
      System.Windows.Forms.MessageBox.Show("Attribute Transfer field mapping not set")
      Exit Sub
    End If

    'get target feature layer
    Dim tFl As IFeatureLayer2
    tFl = ReturnLayer(map, attTDSettings.TargetName)

    'Get the fieldmap for the source layer
    Dim fieldMap As IFieldMap
    fieldMap = attTrans.FindFieldMap(sFL.FeatureClass, Nothing)

    'Enumerate through each selected feature (source)
    Dim enumFeat As IEnumFeature
    Dim sourceFeature As IFeature
    enumFeat = m_editor.EditSelection
    enumFeat.Reset()
    sourceFeature = enumFeat.Next

    m_editor.StartOperation()

    Do Until sourceFeature Is Nothing

      'Get the midpoint of the selected polyline
      Dim curve As ICurve
      Dim curveMidPoint As IPoint
      curve = sourceFeature.Shape
      curveMidPoint = New ESRI.ArcGIS.Geometry.Point
      curve.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, True, curveMidPoint)

      'Setup spatial filter
      Dim spatialFilter As ISpatialFilter
      spatialFilter = New SpatialFilter
      With spatialFilter
        .Geometry = curveMidPoint
        .GeometryField = "SHAPE"
        .SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects
      End With

      'Search target layer
      Dim targetFeatCursor As IFeatureCursor
      Dim targetFeature As IFeature
      Dim bATSucess As Boolean
      targetFeatCursor = tFl.Search(spatialFilter, True)
      targetFeature = targetFeatCursor.NextFeature

      If Not (targetFeature Is Nothing) Then
        'Transfer attributes to first target feature
        attTrans.Transfer(fieldMap, sourceFeature, targetFeature, bATSucess)
      End If

      sourceFeature = enumFeat.Next
    Loop

    m_editor.StopOperation("Attribute Transfer")

  End Sub

  Private Function ReturnLayer(ByVal pMap As IMap, ByVal sLayerName As String) As ILayer

    'Find a layer in a map document
    'Return the layer or nothing if not found

    Dim enumLayers As IEnumLayer
    Dim layer As ILayer

    enumLayers = pMap.Layers(Nothing, True)
    enumLayers.Reset()
    layer = enumLayers.Next

    ReturnLayer = Nothing

    Do Until layer Is Nothing
      If layer.Name = sLayerName Then
        ReturnLayer = layer
        Exit Do
      End If
      layer = enumLayers.Next
    Loop
  End Function

  Public Overrides Sub OnCreate(ByVal hook As Object)
    If Not hook Is Nothing Then
      m_application = CType(hook, IApplication)

      'Disable if it is not ArcMap
      If TypeOf hook Is IMxApplication Then
        MyBase.m_enabled = True
      Else
        MyBase.m_enabled = False
      End If
    End If

    Dim uID As New UID

    m_application = hook
    uID.Value = "esriEditor.Editor"
    m_editor = m_application.FindExtensionByCLSID(uID)
  End Sub