ArcGIS Pro 2.8 API Reference Guide
CreateLineSegment(MapPoint,MapPoint,SpatialReference) Method
Example 

ArcGIS.Core.Geometry Namespace > LineBuilder Class > CreateLineSegment Method : CreateLineSegment(MapPoint,MapPoint,SpatialReference) Method
The start point.
The end point.
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference is inherited from startPt or endPt.
Convenience method to create a new instance of the LineSegment class.
Syntax
Public Overloads Shared Function CreateLineSegment( _
   ByVal startPt As MapPoint, _
   ByVal endPt As MapPoint, _
   Optional ByVal spatialReference As SpatialReference _
) As LineSegment

Parameters

startPt
The start point.
endPt
The end point.
spatialReference
(Optional) The SpatialReference. The default value is null. If spatialReference is null, then the spatial reference is inherited from startPt or endPt.

Return Value

Exceptions
ExceptionDescription
Incompatible spatial references.
startPt or endPt is null.
Remarks
The new instance will build a straight line segment between the start and end point. This method will throw an exception if spatialReference is null and the spatial references of startPt and endPt are not equal. Null spatial references are ignored.

Line Segment

Example
// Use a builder convenience method or use a builder constructor.

MapPoint startPt = MapPointBuilder.CreateMapPoint(1.0, 1.0);
MapPoint endPt = MapPointBuilder.CreateMapPoint(2.0, 1.0);

// Builder convenience methods don't need to run on the MCT.
LineSegment lineFromMapPoint = LineBuilder.CreateLineSegment(startPt, endPt);

// coordinate2D
Coordinate2D start2d = (Coordinate2D)startPt;
Coordinate2D end2d = (Coordinate2D)endPt;

LineSegment lineFromCoordinate2D = LineBuilder.CreateLineSegment(start2d, end2d);

// coordinate3D
Coordinate3D start3d = (Coordinate3D)startPt;
Coordinate3D end3d = (Coordinate3D)endPt;

LineSegment lineFromCoordinate3D = LineBuilder.CreateLineSegment(start3d, end3d);

// lineSegment
LineSegment anotherLineFromLineSegment = LineBuilder.CreateLineSegment(lineFromCoordinate3D);

// Builder constructors need to run on the MCT.
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
  using (LineBuilder lb = new LineBuilder(startPt, endPt))
  {
    // do something with the builder

    lineFromMapPoint = lb.ToSegment();
  }

  using (LineBuilder lb = new LineBuilder(start2d, end2d))
  {
    // do something with the builder

    lineFromCoordinate2D = lb.ToSegment();
  }

  using (LineBuilder lb = new LineBuilder(start3d, end3d))
  {
    // do something with the builder

    lineFromCoordinate3D = lb.ToSegment();
  }

  using (LineBuilder lb = new LineBuilder(lineFromCoordinate3D))
  {
    // do something with the builder

    anotherLineFromLineSegment = lb.ToSegment();
  }
});


// builderEx constructors don't need to run on the MCT
LineBuilderEx lbEx = new LineBuilderEx(startPt, endPt);
lineFromMapPoint = lbEx.ToSegment() as LineSegment;

lbEx = new LineBuilderEx(start2d, end2d);
lineFromCoordinate2D = lbEx.ToSegment() as LineSegment;

lbEx = new LineBuilderEx(start3d, end3d);
lineFromCoordinate3D = lbEx.ToSegment() as LineSegment;

lbEx = new LineBuilderEx(startPt, endPt);
lineFromMapPoint = lbEx.ToSegment() as LineSegment;

lbEx = new LineBuilderEx(lineFromCoordinate3D);
anotherLineFromLineSegment = lbEx.ToSegment() as LineSegment;


// builderEx convenience methods don't need to run on the MCT
lineFromMapPoint = LineBuilderEx.CreateLineSegment(startPt, endPt);
lineFromCoordinate2D = LineBuilderEx.CreateLineSegment(start2d, end2d);
lineFromCoordinate3D = LineBuilderEx.CreateLineSegment(start3d, end3d);
anotherLineFromLineSegment = LineBuilderEx.CreateLineSegment(lineFromCoordinate3D);
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

LineBuilder Class
LineBuilder Members
Overload List