ArcObjects Library Reference

Transform Point Snippet

Create a multipoint with point elements being copies of the vertices of an existing polyline. It then offsets those elements by user specified number of units to the right using one transformation method, then offsets them up by user specified number of units.

[C#]

///<summary>
///Create a multipoint with point elements being copies of the vertices of 
///an existing polyline. It then offsets those elements by user specified number of units to the right 
///using one transformation method, then offsets them up by user specified number of units.
///</summary>
///<param name="polyline">An IPolyline interface for a polyline to be offset by multipoints</param>
///<param name="xOffset">A System.Double that is the number of units to offset to the right.</param>
///<param name="yOffset">A System.Double that is the number of units to offset up.</param>
///<remarks></remarks>
public ESRI.ArcGIS.Geometry.IPolyline TransformPoint(ESRI.ArcGIS.Geometry.IPolyline polyline, System.Double xOffset, System.Double yOffset)
{

  ESRI.ArcGIS.Geometry.IPointCollection polylinePointCollection = polyline as ESRI.ArcGIS.Geometry.IPointCollection;
  ESRI.ArcGIS.Geometry.IGeometry geometry = new ESRI.ArcGIS.Geometry.MultipointClass();
  geometry.SpatialReference = polyline.SpatialReference;

  ESRI.ArcGIS.Geometry.IPointCollection multipointPointCollection = geometry as ESRI.ArcGIS.Geometry.IPointCollection;

  //Add copies of the polyline vertices to the multipoint.
  multipointPointCollection.AddPointCollection(polylinePointCollection);

  //Shift right by xOffset
  ESRI.ArcGIS.Geometry.IAffineTransformation2D affineTransformation2D = new ESRI.ArcGIS.Geometry.AffineTransformation2DClass();
  affineTransformation2D.Move(xOffset, 0);

  ESRI.ArcGIS.Geometry.ITransform2D transform2D = geometry as ESRI.ArcGIS.Geometry.ITransform2D;
  transform2D.Transform(ESRI.ArcGIS.Geometry.esriTransformDirection.esriTransformForward, affineTransformation2D);

  //Shift up by yOffset 
  transform2D.Move(0, yOffset);
  transform2D.Transform(ESRI.ArcGIS.Geometry.esriTransformDirection.esriTransformForward, affineTransformation2D);

  //Now reconstruct a new polyline
  ESRI.ArcGIS.Geometry.IPointCollection4 transform2DPointCollection4 = (ESRI.ArcGIS.Geometry.IPointCollection4)transform2D;

  //Build polyline from a sequential of points. 
  //At 9.2, the recommended way to add arrays of points to a geometry is to use
  //the IGeometryBridge2 interface on the GeometryEnvironment singleton object.
  ESRI.ArcGIS.Geometry.IGeometryBridge2 geometryBridge2 = (ESRI.ArcGIS.Geometry.IGeometryBridge2)new ESRI.ArcGIS.Geometry.GeometryEnvironment();

  ESRI.ArcGIS.Geometry.IPointCollection4 returnPolyLinePointCollection4 = (ESRI.ArcGIS.Geometry.IPointCollection4)new ESRI.ArcGIS.Geometry.Polyline();

  ESRI.ArcGIS.esriSystem.WKSPoint[] aWKSPointBuffer = new ESRI.ArcGIS.esriSystem.WKSPoint[transform2DPointCollection4.PointCount];

  System.Int32 tempFor1 = transform2DPointCollection4.PointCount;
  for (System.Int32 i = 0; i < tempFor1; i++)
  {
    aWKSPointBuffer[i].X = transform2DPointCollection4.get_Point(i).X;
    aWKSPointBuffer[i].Y = transform2DPointCollection4.get_Point(i).Y;
  }

  geometryBridge2.SetWKSPoints(returnPolyLinePointCollection4, ref aWKSPointBuffer);

  return (ESRI.ArcGIS.Geometry.IPolyline)returnPolyLinePointCollection4;

}
[Visual Basic .NET]

'''<summary>
'''Create a multipoint with point elements being copies of the vertices of 
'''an existing polyline. It then offsets those elements by user specified number of units to the right 
'''using one transformation method, then offsets them up by user specified number of units.
'''</summary>
'''<param name="polyline">An IPolyline interface for a polyline to be offset by multipoints</param>
'''<param name="xOffset">A System.Double that is the number of units to offset to the right.</param>
'''<param name="yOffset">A System.Double that is the number of units to offset up.</param>
'''<remarks></remarks>
Public Function TransformPoint(ByVal polyline As ESRI.ArcGIS.Geometry.IPolyline, ByVal xOffset As System.Double, ByVal yOffset As System.Double) As ESRI.ArcGIS.Geometry.IPolyline

  Dim polylinePointCollection As ESRI.ArcGIS.Geometry.IPointCollection = TryCast(polyline, ESRI.ArcGIS.Geometry.IPointCollection)
  Dim geometry As ESRI.ArcGIS.Geometry.IGeometry = New ESRI.ArcGIS.Geometry.MultipointClass()
  geometry.SpatialReference = polyline.SpatialReference

  Dim multipointPointCollection As ESRI.ArcGIS.Geometry.IPointCollection = TryCast(geometry, ESRI.ArcGIS.Geometry.IPointCollection)

  'Add copies of the polyline vertices to the multipoint.
  multipointPointCollection.AddPointCollection(polylinePointCollection)

  'Shift right by xOffset
  Dim affineTransformation2D As ESRI.ArcGIS.Geometry.IAffineTransformation2D = New ESRI.ArcGIS.Geometry.AffineTransformation2DClass()
  affineTransformation2D.Move(xOffset, 0)

  Dim transform2D As ESRI.ArcGIS.Geometry.ITransform2D = TryCast(geometry, ESRI.ArcGIS.Geometry.ITransform2D)
  transform2D.Transform(ESRI.ArcGIS.Geometry.esriTransformDirection.esriTransformForward, affineTransformation2D)

  'Shift up by yOffset 
  transform2D.Move(0, yOffset)
  transform2D.Transform(ESRI.ArcGIS.Geometry.esriTransformDirection.esriTransformForward, affineTransformation2D)

  'Now reconstruct a new polyline
  Dim transform2DPointCollection4 As ESRI.ArcGIS.Geometry.IPointCollection4 = CType(transform2D, ESRI.ArcGIS.Geometry.IPointCollection4)

  'Build polyline from a sequential of points. 
  'At 9.2, the recommended way to add arrays of points to a geometry is to use
  'the IGeometryBridge2 interface on the GeometryEnvironment singleton object.
  Dim geometryBridge2 As ESRI.ArcGIS.Geometry.IGeometryBridge2 = New ESRI.ArcGIS.Geometry.GeometryEnvironment

  Dim returnPolyLinePointCollection4 As ESRI.ArcGIS.Geometry.IPointCollection4 = New ESRI.ArcGIS.Geometry.Polyline

  Dim aWKSPointBuffer(transform2DPointCollection4.PointCount - 1) As ESRI.ArcGIS.esriSystem.WKSPoint

  For i As System.Int32 = 0 To transform2DPointCollection4.PointCount - 1
    aWKSPointBuffer(i).X = transform2DPointCollection4.Point(i).X
    aWKSPointBuffer(i).Y = transform2DPointCollection4.Point(i).Y
  Next

  geometryBridge2.SetWKSPoints(returnPolyLinePointCollection4, aWKSPointBuffer)

  Return CType(returnPolyLinePointCollection4, ESRI.ArcGIS.Geometry.IPolyline)

End Function


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Geometry
  • ESRI.ArcGIS.System
  • System