ArcObjects Library Reference  (Geometry)    

IGeometryBridge_ReplaceSegments_Example

[C#]
public void ReplaceSegments()
{
  int length = 10;
  ISegment[] segmentArray = new ISegment[length];
  for (int i = 0; i < length; i++)
  {
    ILine line = new LineClass();
    IPoint fromPoint = new PointClass();
    fromPoint.PutCoords(i * 10, i * 10);
    IPoint toPoint = new PointClass();
    toPoint.PutCoords(i * 15, i * 15);
    line.PutCoords(fromPoint, toPoint);
    segmentArray[i] = line as ISegment;
  }
  ISegmentCollection segmentCollection = new PolylineClass();
  //adds Segments to segmentCollection
  IGeometryBridge geometryBridge = new GeometryEnvironmentClass();
  geometryBridge.AddSegments(segmentCollection, ref segmentArray);
  PrintSegments(segmentCollection, "Segments before replacement");
  int replaceLength = 5;
  ISegment[] replaceSegmentArray = new ISegment[replaceLength];
  for (int i = 0; i < replaceLength; i++)
  {
    ILine replaceLine = new LineClass();
    IPoint replaceFromPoint = new PointClass();
    replaceFromPoint.PutCoords(i * 666, i * 666);
    IPoint replaceToPoint = new PointClass();
    replaceToPoint.PutCoords(i * 333, i * 333);
    replaceLine.PutCoords(replaceFromPoint, replaceToPoint);
    replaceSegmentArray[i] = replaceLine as ISegment;
  }
  int index = 3;
  geometryBridge.ReplaceSegments(segmentCollection, index, replaceLength, ref replaceSegmentArray);
  PrintSegments(segmentCollection, "Segments after replacement");
}
private void PrintSegments(ISegmentCollection segmentCollection, String header)
{
  String report = "";
  for (int i = 0; i < segmentCollection.SegmentCount; i++)
  {
    ISegment currentSegment = segmentCollection.get_Segment(i);
    ILine currentLine = currentSegment as ILine;
    report = report + "index = " + i + " , FromPoint X = " + currentLine.FromPoint.X + " , FromPoint Y = " + currentLine.FromPoint.X;
    report = report + " , ToPoint X = " + currentLine.ToPoint.X + " , ToPoint Y = " + currentLine.ToPoint.X + "\n";
  }
  System.Windows.Forms.MessageBox.Show(header + "\n" +report);
}

[Visual Basic 6.0, Visual Basic .NET, C++]
No example is available for Visual Basic 6.0, Visual Basic .NET, or C++. To view a C# example, click the Language Filter button Language Filter in the upper-left corner of the page.