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

Adjusting feature locations with spatial adjustment (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Editing data > ArcGIS for Desktop editing for developers > Updating existing features > Adjusting feature locations with spatial adjustment

Adjusting feature locations with spatial adjustment

This topic discusses defining displacement links and adjusting feature geometry using spatial adjustment methods.

In this topic

About adjusting features using spatial adjustment methods

In the ArcMap user interface (UI), spatial adjustments are performed by defining displacement links, the features that will be adjusted, and the transformation method that will be applied.
In the application programming interface (API), you define the links as two point arrays representing the from and to ends of displacement links. The number of required displacement links is based on the type of transformation to be applied. Each transformation defines this number, which can be accessed via ITransformationMethod.MinNumDisplacementPoints.
The transformation is then defined by the methods and properties on ITransformationMethod. To perform the transformation, call ITransformationMethod.Transform passing a feature cursor of the features you want to adjust.
The following transformations are supported in ArcGIS:
The following code shows an example of these steps:
Make sure to change the x,y coordinates for the control points and the query filter's WHERE clause based on your data.
// This method performs an affine transformation on features.

//Create control points for the transformation.
//Normally, these come from the from/to ends of displacement links.
List < IPoint > fromPoints=new List < IPoint > ();
fromPoints.Add(CreatePoint(5566626.728, 4948245.103));
fromPoints.Add(CreatePoint(5566858.655, 4948246.713));
fromPoints.Add(CreatePoint(5566686.32, 4948088.874));
IPoint[] fromPointsArray=fromPoints.ToArray();

List < IPoint > toPoints=new List < IPoint > ();
toPoints.Add(CreatePoint(5566895.699, 4948111.423));
toPoints.Add(CreatePoint(5566744.302, 4947960.026));
toPoints.Add(CreatePoint(5567013.273, 4947989.017));
IPoint[] toPointsArray=toPoints.ToArray();

//Define control points.
ITransformationMethodGEN transformMethod=new AffineTransformationMethodClass();
IMxDocument mxDoc=m_application.Document as IMxDocument;
    transformMethod.DefineFromControlPoints(ref fromPointsArray, ref toPointsArray,
        null, mxDoc.ActiveView.Extent);

catch (Exception ex)
    System.Windows.Forms.MessageBox.Show("Define Control Points failed.");

//Create a feature cursor based on the predefined query.
IFeatureLayer featureLayer=mxDoc.FocusMap.get_Layer(0)as IFeatureLayer;
if (featureLayer == null)
        "Please load a feature layer as the first layer in TOC.");
    return ;

IFeatureClass featureClass=featureLayer.FeatureClass;
IQueryFilter queryFilter=new QueryFilterClass();
IFeatureCursor featureCursor=featureClass.Search(queryFilter, false);

//Transform features.
IWorkspaceEdit workspaceEdit=featureClass.FeatureDataset.Workspace as
transformMethod.Transform(featureCursor, null);

//Refresh the active view.

private IPoint CreatePoint(double xVal, double yVal)
    //This function creates a point.
    IPoint point=new PointClass();
    return point;
'Perform an affine transformation on features.
'Create control points for the transformation.
'Normally, these come from the from/to ends of displacement links.
Dim fromPoints As List(Of IPoint)=New List(Of IPoint)
fromPoints.Add(CreatePoint(5566626.728, 4948245.103))
fromPoints.Add(CreatePoint(5566858.655, 4948246.713))
fromPoints.Add(CreatePoint(5566686.32, 4948088.874))
Dim fromPointsArray() As IPoint=fromPoints.ToArray()

Dim toPoints As List(Of IPoint)=New List(Of IPoint)
toPoints.Add(CreatePoint(5566895.699, 4948111.423))
toPoints.Add(CreatePoint(5566744.302, 4947960.026))
toPoints.Add(CreatePoint(5567013.273, 4947989.017))
Dim toPointsArray() As IPoint=toPoints.ToArray()

'Define control points.
Dim transformMethod As ITransformationMethodGEN=New AffineTransformationMethodClass()
Dim mxDoc As IMxDocument=TryCast(m_application.Document, IMxDocument)
transformMethod.DefineFromControlPoints(fromPointsArray, _
                                        toPointsArray, Nothing, mxDoc.ActiveView.Extent)
Catch ex As Exception
System.Windows.Forms.MessageBox.Show("Define Control Points failed.")
End Try

'Create a feature cursor based on the predefined query.
Dim featureLayer As IFeatureLayer=TryCast(mxDoc.FocusMap.Layer(0), IFeatureLayer)
If (featureLayer Is Nothing) Then
    System.Windows.Forms.MessageBox.Show("Please load a feature layer as the first layer in TOC.")
End If
Dim featureClass As IFeatureClass=featureLayer.FeatureClass
Dim queryFilter As IQueryFilter=New QueryFilterClass()
Dim featureCursor As IFeatureCursor=featureClass.Search(queryFilter, False)

'Transform features.
Dim workspaceEdit As IWorkspaceEdit=TryCast(featureClass.FeatureDataset.Workspace, IWorkspaceEdit)
transformMethod.Transform(featureCursor, Nothing)

'Refresh the active view.

Private Function CreatePoint(ByVal xVal As Double, ByVal yVal As Double) As IPoint
    'This function creates a point.
    Dim point As IPoint=New PointClass()
    Return point
End Function

Creating displacement links

In some cases, it might be advantageous when working with large numbers of known coordinates to define displacement links programmatically rather than manually entering a pair of coordinates.
The following code example shows how to create displacement links:
public void CreateDisplacementLink()
    //Create a displacement link from two points.
    //Get the map and reset graphics container.
    IMxDocument mxDocument=m_application.Document as IMxDocument;
    IMap map=mxDocument.FocusMap;
    IGraphicsContainer graphicsContainer=map as IGraphicsContainer;

    //Get the link symbol from the adjustment extension.
    IAdjustment adjustment=m_application.FindExtensionByName(
        "ESRI Adjustment Tools")as IAdjustment;
    IAdjustProperties adjustmentProperties=adjustment as IAdjustProperties;
    ILineSymbol linkSymbol=adjustmentProperties.DisplacementLinkSymbol;

    //Create the polyline from two points.
    IPoint fromPoint=new PointClass();
    fromPoint.PutCoords(115,  - 32);
    IPoint toPoint=new PointClass();
    toPoint.PutCoords(116,  - 31);

    IPolyline polyLine=new PolylineClass();

    //Instantiate a new displacement link and set symbology.
    IDisplacementLinkElement link=new DisplacementLinkElementClass();
    IElement element=link as IElement;
    //Set the geometry and add to the graphics container.
    graphicsContainer.AddElement(element, 0);

    //Refresh the graphics.
    mxDocument.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null,
'Create a displacement link from two points
'Get the map and graphics container
Dim pMxDoc As IMxDocument=My.ArcMap.Document
Dim pMap As IMap=pMxDoc.FocusMap
Dim pGraCon As IGraphicsContainer=pMap

'Get the link symbol from the adjustment extension
Dim pAdjust As IAdjustment=My.ArcMap.Application.FindExtensionByName("ESRI Adjustment Tools")
Dim pAdjustProp As IAdjustProperties=pAdjust
Dim pLinkSymbol As ILineSymbol=pAdjustProp.DisplacementLinkSymbol

'Create the polyline from two points
Dim pFromPoint As IPoint
pFromPoint=New Point
pFromPoint.PutCoords(115, -32)

Dim pToPoint As IPoint
pToPoint=New Point
pToPoint.PutCoords(116, -31)

Dim pPolyLine As IPolyline
pPolyLine=New Polyline

'Instantiate a new displacement link and set symbology
Dim pLink As IDisplacementLinkElement
pLink=New DisplacementLinkElement
Dim pElement As IElement=pLink

'Set the geometry and add to the graphics container
pGraCon.AddElement(pElement, 0)

'Refresh the graphics
pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)

To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced