ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / LineBuilderEx Class / CreateLineSegment Method / CreateLineSegment(MapPoint,MapPoint,SpatialReference) Method
The start point.
The end point.
(Optional) The SpatialReference. The default value is null. The spatial references of the start point and end point are ignored.
Example

In This Topic
    CreateLineSegment(MapPoint,MapPoint,SpatialReference) Method
    In This Topic
    Convenience method to create a new instance of the LineSegment class.
    Syntax
    Public Overloads Shared Function CreateLineSegment( _
       ByVal startPoint As MapPoint, _
       ByVal endPoint As MapPoint, _
       Optional ByVal spatialReference As SpatialReference _
    ) As LineSegment

    Parameters

    startPoint
    The start point.
    endPoint
    The end point.
    spatialReference
    (Optional) The SpatialReference. The default value is null. The spatial references of the start point and end point are ignored.

    Return Value

    Exceptions
    ExceptionDescription
    startPoint or endPoint is null or empty.
    Remarks
    The new instance will build a straight line segment between the start and end point. Attributes are inherited from the start and end points.

    Line Segment

    Example
    Construct a LineSegment using two MapPoints
    {
      // Use a builderEx convenience method or use a builderEx constructor.
    
      MapPoint startPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0);
      MapPoint endPt = MapPointBuilderEx.CreateMapPoint(2.0, 1.0);
    
      // BuilderEx convenience methods don't need to run on the MCT.
      LineSegment lineFromMapPoint = LineBuilderEx.CreateLineSegment(startPt, endPt);
    
      // coordinate2D
      Coordinate2D start2d = (Coordinate2D)startPt;
      Coordinate2D end2d = (Coordinate2D)endPt;
    
      LineSegment lineFromCoordinate2D = LineBuilderEx.CreateLineSegment(start2d, end2d);
    
      // coordinate3D
      Coordinate3D start3d = (Coordinate3D)startPt;
      Coordinate3D end3d = (Coordinate3D)endPt;
    
      LineSegment lineFromCoordinate3D = LineBuilderEx.CreateLineSegment(start3d, end3d);
    
      // lineSegment
      LineSegment anotherLineFromLineSegment = LineBuilderEx.CreateLineSegment(lineFromCoordinate3D);
    
    
      // 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;
    }
    Clip a Polyline by a Polygon
    {
      // clip a polyline by a polygon
    
      List<Coordinate2D> list =
      [
        new Coordinate2D(1.0, 1.0),
        new Coordinate2D(1.0, 4.0),
        new Coordinate2D(4.0, 4.0),
        new Coordinate2D(4.0, 1.0),
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(list, SpatialReferences.WGS84);
    
      LineSegment crossingLine = LineBuilderEx.CreateLineSegment(MapPointBuilderEx.CreateMapPoint(0, 3), MapPointBuilderEx.CreateMapPoint(5.0, 3.0));
      Polyline p = PolylineBuilderEx.CreatePolyline(crossingLine);
      Geometry geometry = GeometryEngine.Instance.Clip(p, polygon.Extent);
    }
    Cut a geometry with a polyline
    {
        SpatialReference sr = SpatialReferences.WGS84;
    
        List<MapPoint> list =
        [
          MapPointBuilderEx.CreateMapPoint(1.0, 1.0, sr),
      MapPointBuilderEx.CreateMapPoint(1.0, 4.0, sr),
      MapPointBuilderEx.CreateMapPoint(4.0, 4.0, sr),
      MapPointBuilderEx.CreateMapPoint(4.0, 1.0, sr),
    ];
    
        List<Geometry> cutGeometries;
    
        LineSegment line = LineBuilderEx.CreateLineSegment(MapPointBuilderEx.CreateMapPoint(0, 0, sr), MapPointBuilderEx.CreateMapPoint(3, 6, sr));
        Polyline cutter = PolylineBuilderEx.CreatePolyline(line);
    
        // polyline
        polyline = PolylineBuilderEx.CreatePolyline(list);
        bool isSimple = GeometryEngine.Instance.IsSimpleAsFeature(polyline);
        cutGeometries = GeometryEngine.Instance.Cut(polyline, cutter) as List<Geometry>;
    
        Polyline leftPolyline = cutGeometries[0] as Polyline;
        Polyline rightPolyline = cutGeometries[1] as Polyline;
    
        // leftPolyline.Points[0] = 1, 2
        // leftPolyline.Points[1] = 1, 4
        // leftPolyline.Points[2] = 2, 4
    
        // rightPolyline.Points.Count = 5
        // rightPolyline.Parts.Count = 2
    
        ReadOnlySegmentCollection segments0 = rightPolyline.Parts[0];
        // segments0[0].StartCoordinate = 1, 1
        // segments0[0].EndCoordinate = 1, 2
    
        ReadOnlySegmentCollection segments1 = rightPolyline.Parts[1];
        // segments1.Count = 2
        // segments1[0].StartCoordinate = 2, 4
        // segments1[0].EndCoordinate = 4, 4
        // segments1[1].StartCoordinate = 4, 4
        // segments1[1].EndCoordinate = 4, 1
    
        // polygon
        polygon = PolygonBuilderEx.CreatePolygon(list);
        isSimple = GeometryEngine.Instance.IsSimpleAsFeature(polygon);
        cutGeometries = GeometryEngine.Instance.Cut(polygon, cutter) as List<Geometry>;
      }
    Densify by Length
    {
      // densify a line segment
      MapPoint startPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0);
      MapPoint endPt = MapPointBuilderEx.CreateMapPoint(1, 21);
      LineSegment line = LineBuilderEx.CreateLineSegment(startPt, endPt);
      polyline = PolylineBuilderEx.CreatePolyline(line);
    
      Geometry geom = GeometryEngine.Instance.DensifyByLength(polyline, 2);
      Polyline result = geom as Polyline;
    
      // densify a circular arc
      MapPoint fromPt = MapPointBuilderEx.CreateMapPoint(2, 1);
      MapPoint toPt = MapPointBuilderEx.CreateMapPoint(1, 2);
      Coordinate2D interiorPt = new(1 + Math.Sqrt(2) / 2, 1 + Math.Sqrt(2) / 2);
    
      EllipticArcBuilderEx cab = new(fromPt, toPt, interiorPt);
      EllipticArcSegment circularArc = cab.ToSegment();
      polyline = PolylineBuilderEx.CreatePolyline(circularArc);
      geom = GeometryEngine.Instance.DensifyByLength(polyline, 2);
      result = geom as Polyline;
    }
    Determine Length, Length3D of line
    {
      MapPoint c1 = MapPointBuilderEx.CreateMapPoint(1, 2, 3);
      MapPoint c2 = MapPointBuilderEx.CreateMapPoint(4, 2, 4);
    
      // line segment
      LineSegment line = LineBuilderEx.CreateLineSegment(c1, c2);
      double len = line.Length;     // = 3
      double len3D = line.Length3D;   // = Math.Sqrt(10)
    
      // polyline
      Polyline p = PolylineBuilderEx.CreatePolyline(line);
      double p_len = p.Length;        // = len = 3
      double p_len3D = p.Length3D;    // = len3D = Math.Sqrt(10)
    
      double ge_len = GeometryEngine.Instance.Length(p);      // = p_len = len = 3
      double ge_len3d = GeometryEngine.Instance.Length3D(p);    // = p_len3D = len3D = Math.Sqrt(10)
    }
    MovePointAlongLine
    {
      LineSegment line = LineBuilderEx.CreateLineSegment(MapPointBuilderEx.CreateMapPoint(0, 3), MapPointBuilderEx.CreateMapPoint(5.0, 3.0));
      polyline = PolylineBuilderEx.CreatePolyline(line);
      bool simple = GeometryEngine.Instance.IsSimpleAsFeature(polyline);
    
      // ratio = false
      MapPoint pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 1.0, false, 0.0, SegmentExtensionType.NoExtension);
      // pt = 1.0, 3.0
    
      pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 1.0, false, -1.0, SegmentExtensionType.NoExtension);
      // pt = 1.0, 4.0
    
      pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 1.0, false, 2.0, SegmentExtensionType.NoExtension);
      // pt = 1.0, 1.0
    
      // ratio = true
      pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 0.5, true, 0, SegmentExtensionType.NoExtension);
      // pt = 2.5, 3.0
    
      // move past the line
      pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 7, false, 0, SegmentExtensionType.NoExtension);
      // pt = 5.0, 3.0
    
      // move past the line with extension at "to" point
      pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 7, false, 0, SegmentExtensionType.ExtendEmbeddedAtTo);
      // pt = 7.0, 3.0
    
      // negative distance with extension at "from" point
      pt = GeometryEngine.Instance.MovePointAlongLine(polyline, -2, false, 0, SegmentExtensionType.ExtendEmbeddedAtFrom);
      // pt = -2.0, 3.0
    
      // ratio = true
      pt = GeometryEngine.Instance.MovePointAlongLine(polyline, 0.5, true, 0, SegmentExtensionType.NoExtension);
      // pt = 2.5, 3.0
    
      // line with Z
      List<Coordinate3D> coords3D = [new Coordinate3D(0, 0, 0), new Coordinate3D(1113195, 1118890, 5000)];
      Polyline polylineZ = PolylineBuilderEx.CreatePolyline(coords3D, SpatialReferences.WebMercator);
      // polylineZ.HasZ = true
    
      // ratio = true, no offset
      pt = GeometryEngine.Instance.MovePointAlongLine(polylineZ, 0.5, true, 0, SegmentExtensionType.NoExtension);
      // pt.X = 556597.5
      // pt.Y = 559445
      // pt.Z = 2500
    
      // ratio = true, past the line with "to" extension, no offset
      pt = GeometryEngine.Instance.MovePointAlongLine(polylineZ, 1.5, true, 0, SegmentExtensionType.ExtendEmbeddedAtTo);
      // pt.X = 1669792.5
      // pt.Y = 1678335
      // pt.Z = 7500
    
      // ratio = true, negative distance past the line with no extension, no offset
      pt = GeometryEngine.Instance.MovePointAlongLine(polylineZ, -1.5, true, 0, SegmentExtensionType.NoExtension);
      // pt.X = 0
      // pt.Y = 0
      // pt.Z = -7500
    
      // polyline with Z but 2d distance = 0
      MapPoint pt3 = MapPointBuilderEx.CreateMapPoint(5, 5, 0);
      MapPoint pt4 = MapPointBuilderEx.CreateMapPoint(5, 5, 10);
      List<MapPoint> pts = [pt3, pt4];
    
      polyline = PolylineBuilderEx.CreatePolyline(pts);
      // polyline.HasZ = true
      // polyline.Length3D = 10
      // polyline.Length = 0
    
      MapPoint result = GeometryEngine.Instance.MovePointAlongLine(polyline, 2, false, 0, SegmentExtensionType.NoExtension);
      // result = 5, 5, 2
    
      // polyline with length2d = 0 and length3d = 0
      MapPoint pt5 = MapPointBuilderEx.CreateMapPoint(5, 5, 10);
      MapPoint pt6 = MapPointBuilderEx.CreateMapPoint(5, 5, 10);
      pts.Clear();
      pts.Add(pt5);
      pts.Add(pt6);
    
      polyline = PolylineBuilderEx.CreatePolyline(pts);
      // polyline.HasZ = true
      // polyline.Length3D = 0
      // polyline.Length = 0
    
      result = GeometryEngine.Instance.MovePointAlongLine(polyline, 3, true, 0, SegmentExtensionType.NoExtension);
      // result = 5, 5, 10
    
      result = GeometryEngine.Instance.MovePointAlongLine(polyline, 3, true, 0, SegmentExtensionType.ExtendEmbeddedAtFrom);
      // result = 5, 5, 10
    
      // polyline with Z and M
      List<MapPoint> inputPoints =
      [
          MapPointBuilderEx.CreateMapPoint(1, 2, 3, 4),
        MapPointBuilderEx.CreateMapPoint(1, 2, 33, 44),
    ];
    
      Polyline polylineZM = PolylineBuilderEx.CreatePolyline(inputPoints, SpatialReferences.WGS84);
      // polylineZM.HasZ = true
      // polylineZM.HasM = true
    
      // ratio = true, no offset
      MapPoint pointAlong = GeometryEngine.Instance.MovePointAlongLine(polylineZM, 0.5, true, 0, SegmentExtensionType.NoExtension);
      // pointAlong = 1, 2, 18, 24
    
      // ratio = true with offset
      pointAlong = GeometryEngine.Instance.MovePointAlongLine(polylineZM, 0.2, true, 2.23606797749979, SegmentExtensionType.NoExtension);
      // pointAlong = 1, 2, 9, 12
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also