ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Geometry Namespace / LineBuilderEx Class / CreateLineSegment Method / CreateLineSegment(Coordinate2D,Coordinate2D,SpatialReference) Method
The start point.
The end point.
(Optional) The SpatialReference. The default value is null.
Example

In This Topic
    CreateLineSegment(Coordinate2D,Coordinate2D,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 Coordinate2D, _
       ByVal endPoint As Coordinate2D, _
       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.

    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.

    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;
    }
    Construct a Circular Arc - using two segments and radius
    {
      // Construct a segment from (100, 100) to (50, 50) and another segment from (100, 100) to (150, 50).
      // Use a builderEx convenience method or use a builderEx constructor.
    
      LineSegment segment1 = LineBuilderEx.CreateLineSegment(new Coordinate2D(100, 100), new Coordinate2D(50, 50));
      LineSegment segment2 = LineBuilderEx.CreateLineSegment(new Coordinate2D(100, 100), new Coordinate2D(150, 50));
    
      // Construct the hint point to determine where the arc will be constructed.
      Coordinate2D hintPoint = new Coordinate2D(100, 75);
    
      // Call QueryFilletRadius to get the minimum and maximum radii that can be used with these segments.
      var minMaxRadii = EllipticArcBuilderEx.QueryFilletRadiusRange(segment1, segment2, hintPoint);
    
      // Use the maximum radius to create the arc.
      double maxRadius = minMaxRadii.Item2;
    
      // BuilderEx convenience methods don't need to run on the MCT.
      //At 2.x - EllipticArcSegment circularArc = EllipticArcBuilderEx.CreateEllipticArcSegment(segment1, segment2, maxRadius, hintPoint);
      EllipticArcSegment circularArc = EllipticArcBuilderEx.CreateCircularArc(
                          segment1, segment2, maxRadius, hintPoint);
    
      // This EllipticArcBuilderEx constructor needs to run on the MCT either.
      EllipticArcBuilderEx cab = new EllipticArcBuilderEx(segment1, segment2, maxRadius, hintPoint);
      EllipticArcSegment otherCircularArc = cab.ToSegment();
    }
    Clip a Polyline
    {
      // clip a polyline by an envelope
    
      Envelope env = EnvelopeBuilderEx.CreateEnvelope(2.0, 2.0, 4.0, 4.0);
      LineSegment line = LineBuilderEx.CreateLineSegment(new Coordinate2D(0, 3), new Coordinate2D(5.0, 3.0));
      polyline = PolylineBuilderEx.CreatePolyline(line);
    
      Geometry clipGeom = GeometryEngine.Instance.Clip(polyline, env);
    }
    QueryPoint
    {
      SpatialReference sr = SpatialReferences.WGS84;
    
      // Horizontal line segment
      Coordinate2D start = new(1, 1);
      Coordinate2D end = new(11, 1);
      LineSegment line = LineBuilderEx.CreateLineSegment(start, end, sr);
    
      polyline = PolylineBuilderEx.CreatePolyline(line);
    
      // Don't extend the segment
    
      MapPoint outPoint = GeometryEngine.Instance.QueryPoint(polyline, SegmentExtensionType.NoExtension, 1.0, AsRatioOrLength.AsLength);
      // outPoint = (2, 1)
    
      // or the segment
      MapPoint outPoint_seg = GeometryEngine.Instance.QueryPoint(line, SegmentExtensionType.NoExtension, 1.0, AsRatioOrLength.AsLength);
      // outPoint_seg = (2, 1)
    
      // Extend infinitely in both directions
      outPoint = GeometryEngine.Instance.QueryPoint(polyline, SegmentExtensionType.ExtendTangents, 1.5, AsRatioOrLength.AsRatio);
      // outPoint = (16, 1)
      outPoint_seg = GeometryEngine.Instance.QueryPoint(line, SegmentExtensionType.ExtendTangents, 1.5, AsRatioOrLength.AsRatio);
      // outPoint_seg = (16, 1)
    }
    QueryTangent
    {
      LineSegment line = LineBuilderEx.CreateLineSegment(new Coordinate2D(0, 0), new Coordinate2D(1, 0));
    
      // No extension, distanceAlongCurve = 0.5
      LineSegment tangent = GeometryEngine.Instance.QueryTangent(line, SegmentExtensionType.NoExtension, 0.5, AsRatioOrLength.AsRatio, 1);
      // tangent.StartCoordinate = (0.5, 0.0)
      // tangent.EndCoordinate = (1.5, 0.0)
    
      tangent = GeometryEngine.Instance.QueryTangent(line, SegmentExtensionType.NoExtension, 1.5, AsRatioOrLength.AsLength, 1);
      // tangent.StartCoordinate = (1.0, 0.0)
      // tangent.EndCoordinate = (2.0, 0.0)
    
      tangent = GeometryEngine.Instance.QueryTangent(line, SegmentExtensionType.ExtendTangentAtTo, 1.5, AsRatioOrLength.AsLength, 1);
      // tangent.StartCoordinate = (1.5, 0.0)
      // tangent.EndCoordinate = (2.5, 0.0)
    
      tangent = GeometryEngine.Instance.QueryTangent(line, SegmentExtensionType.ExtendTangentAtFrom, -1.5, AsRatioOrLength.AsLength, 1);
      // tangent.StartCoordinate = (-1.5, 0.0)
      // tangent.EndCoordinate = (-0.5, 0.0)
    
      tangent = GeometryEngine.Instance.QueryTangent(line, SegmentExtensionType.ExtendTangentAtFrom, -0.5, AsRatioOrLength.AsRatio, 1);
      // tangent.StartCoordinate = (-0.5, 0.0)
      // tangent.EndCoordinate = (0.5, 0.0)
    }
    Reflect a polygon about a line
    {
      SpatialReference sr = SpatialReferences.WGS84;
    
      Coordinate2D start = new(0, 0);
      Coordinate2D end = new(4, 4);
      LineSegment line = LineBuilderEx.CreateLineSegment(start, end, sr);
    
      Coordinate2D[] coords =
      [
        new Coordinate2D(-1, 2),
      new Coordinate2D(-1, 4),
      new Coordinate2D(1, 4),
      new Coordinate2D(-1, 2)
      ];
    
      polygon = PolygonBuilderEx.CreatePolygon(coords, sr);
    
      // reflect a polygon about the line
      Polygon reflectedPolygon = GeometryEngine.Instance.ReflectAboutLine(polygon, line) as Polygon;
    
      // reflectedPolygon points are
      //    (2, -1), (4, -1), (4, 1), (2, -1)
    }
    Determine relationship between two geometries
    {
      // set up some geometries
    
      // points
      MapPoint point0 = MapPointBuilderEx.CreateMapPoint(0, 0, SpatialReferences.WGS84);
      MapPoint point1 = MapPointBuilderEx.CreateMapPoint(1, 1, SpatialReferences.WGS84);
      MapPoint point2 = MapPointBuilderEx.CreateMapPoint(-5, 5, SpatialReferences.WGS84);
    
      // multipoint
      List<MapPoint> points = [point0, point1, point2];
      Multipoint multipoint = MultipointBuilderEx.CreateMultipoint(points, SpatialReferences.WGS84);
    
      // polygon
      List<Coordinate2D> polygonCoords =
      [
          new Coordinate2D(-10, 0),
      new Coordinate2D(0, 10),
      new Coordinate2D(10, 0),
      new Coordinate2D(-10, 0)
      ];
      polygon = PolygonBuilderEx.CreatePolygon(polygonCoords, SpatialReferences.WGS84);
    
      // polylines
      Polyline polyline1 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(-9.1, 0.1), new Coordinate2D(0, 9)), SpatialReferences.WGS84);
      Polyline polyline2 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(-5, 5), new Coordinate2D(0, 5)), SpatialReferences.WGS84);
      Polyline polyline3 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(2.09, -2.04), new Coordinate2D(5, 10)), SpatialReferences.WGS84);
      Polyline polyline4 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(10, -5), new Coordinate2D(10, 5)), SpatialReferences.WGS84);
    
      List<Segment> segments =
      [
          LineBuilderEx.CreateLineSegment(new Coordinate2D(5.05, -2.87), new Coordinate2D(6.35, 1.57)),
      LineBuilderEx.CreateLineSegment(new Coordinate2D(6.35, 1.57), new Coordinate2D(4.13, 2.59)),
      LineBuilderEx.CreateLineSegment(new Coordinate2D(4.13, 2.59), new Coordinate2D(5, 5))
      ];
      Polyline polyline5 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
    
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(5, 5), new Coordinate2D(10, 10)));
    
      Polyline polyline6 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
      Polyline polyline7 = PolylineBuilderEx.CreatePolyline(polyline5);
      Polyline polyline8 = PolylineBuilderEx.CreatePolyline(LineBuilderEx.CreateLineSegment(new Coordinate2D(5, 5), new Coordinate2D(10, 10)), SpatialReferences.WGS84);
    
      segments.Clear();
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(0.6, 3.5), new Coordinate2D(0.7, 7)));
      segments.Add(LineBuilderEx.CreateLineSegment(new Coordinate2D(0.7, 7), new Coordinate2D(3, 9)));
    
      Polyline polyline9 = PolylineBuilderEx.CreatePolyline(segments, SpatialReferences.WGS84);
    
      // now do the Related tests
    
      // Interior/Interior Intersects
      string scl = "T********";
      bool related = GeometryEngine.Instance.Relate(polygon, polyline1, scl);     // related = true
      related = GeometryEngine.Instance.Relate(point0, point1, scl);              // related = false
      related = GeometryEngine.Instance.Relate(point0, multipoint, scl);          // related = true
      related = GeometryEngine.Instance.Relate(multipoint, polygon, scl);         // related = true
      related = GeometryEngine.Instance.Relate(multipoint, polyline1, scl);       // related = false
      related = GeometryEngine.Instance.Relate(polyline2, point2, scl);           // related = false
      related = GeometryEngine.Instance.Relate(point1, polygon, scl);             // related = true
    
      // Interior/Boundary Intersects
      scl = "*T*******";
      related = GeometryEngine.Instance.Relate(polygon, polyline2, scl);          // related = true
      related = GeometryEngine.Instance.Relate(polygon, polyline3, scl);          // related = false
      related = GeometryEngine.Instance.Relate(point1, polygon, scl);             // related = false
    
      // Boundary/Boundary Interior intersects
      scl = "***T*****";
      related = GeometryEngine.Instance.Relate(polygon, polyline4, scl);          // related = true
    
      // Overlaps Dim1
      scl = "1*T***T**";
      related = GeometryEngine.Instance.Relate(polygon, polyline5, scl);          // related = true
    
      // Crosses Area/Line (LineB crosses PolygonA)
      scl = "1020F1102";
      related = GeometryEngine.Instance.Relate(polygon, polyline6, scl);          // related = false
      related = GeometryEngine.Instance.Relate(polygon, polyline9, scl);          // related = true
    
      // Boundary/Boundary Touches
      scl = "F***T****";
      related = GeometryEngine.Instance.Relate(polygon, polyline7, scl);          // related = false
      related = GeometryEngine.Instance.Relate(polygon, polyline8, scl);          // related = true
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also