ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / CubicBezierBuilderEx Class / ToSegment Method
Example

In This Topic
    ToSegment Method (CubicBezierBuilderEx)
    In This Topic
    Returns a CubicBezierSegment instance representing the current state of the builder.
    Syntax
    public new CubicBezierSegment ToSegment()
    Public Shadows Function ToSegment() As CubicBezierSegment

    Return Value

    Example
    Construct a Cubic Bezier - from Coordinates
    // Use a builderEx convenience method or a builderEx constructor.
    
    MapPoint startPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0, 3.0);
    MapPoint endPt = MapPointBuilderEx.CreateMapPoint(2.0, 2.0, 3.0);
    
    Coordinate2D ctrl1Pt = new Coordinate2D(1.0, 2.0);
    Coordinate2D ctrl2Pt = new Coordinate2D(2.0, 1.0);
    
    // BuilderEx convenience methods don't need to run on the MCT
    CubicBezierSegment bezier = CubicBezierBuilderEx.CreateCubicBezierSegment(startPt, ctrl1Pt, ctrl2Pt, endPt, SpatialReferences.WGS84);
    
    // without a SR
    bezier = CubicBezierBuilderEx.CreateCubicBezierSegment(startPt, ctrl1Pt, ctrl2Pt, endPt);
    
    
    // builderEx constructors don't need to run on the MCT
    CubicBezierBuilderEx cbbEx = new CubicBezierBuilderEx(startPt, ctrl1Pt, ctrl2Pt, endPt);
    bezier = cbbEx.ToSegment() as CubicBezierSegment;
    
    // another alternative
    cbbEx = new CubicBezierBuilderEx(startPt, ctrl1Pt.ToMapPoint(), ctrl2Pt.ToMapPoint(), endPt);
    bezier = cbbEx.ToSegment() as CubicBezierSegment;
    
    
    Construct a Cubic Bezier - from MapPoints
    // Use a builderEx convenience method or a builderEx constructor.
    
    MapPoint startPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0, SpatialReferences.WGS84);
    MapPoint endPt = MapPointBuilderEx.CreateMapPoint(2.0, 2.0, SpatialReferences.WGS84);
    
    MapPoint ctrl1Pt = MapPointBuilderEx.CreateMapPoint(1.0, 2.0, SpatialReferences.WGS84);
    MapPoint ctrl2Pt = MapPointBuilderEx.CreateMapPoint(2.0, 1.0, SpatialReferences.WGS84);
    
    // BuilderEx convenience methods don't need to run on the MCT
    CubicBezierSegment bezier = CubicBezierBuilderEx.CreateCubicBezierSegment(startPt, ctrl1Pt, ctrl2Pt, endPt);
    
    // builderEx constructors don't need to run on the MCT
    CubicBezierBuilderEx cbbEx = new CubicBezierBuilderEx(startPt, ctrl1Pt, ctrl2Pt, endPt);
    bezier = cbbEx.ToSegment() as CubicBezierSegment;
    
    Construct a Cubic Bezier - from an enumeration of MapPoints
    // Use a buildeExr convenience method or use a builderEx constructor.
    
    MapPoint startPt = MapPointBuilderEx.CreateMapPoint(1.0, 1.0, SpatialReferences.WGS84);
    MapPoint endPt = MapPointBuilderEx.CreateMapPoint(2.0, 2.0, SpatialReferences.WGS84);
    
    MapPoint ctrl1Pt = MapPointBuilderEx.CreateMapPoint(1.0, 2.0, SpatialReferences.WGS84);
    MapPoint ctrl2Pt = MapPointBuilderEx.CreateMapPoint(2.0, 1.0, SpatialReferences.WGS84);
    
    List<MapPoint> listMapPoints = new List<MapPoint>();
    listMapPoints.Add(startPt);
    listMapPoints.Add(ctrl1Pt);
    listMapPoints.Add(ctrl2Pt);
    listMapPoints.Add(endPt);
    
    // BuilderEx convenience methods don't need to run on the MCT
    CubicBezierSegment bezier = CubicBezierBuilderEx.CreateCubicBezierSegment(listMapPoints);
    
    // builderEx constructors don't need to run on the MCT
    CubicBezierBuilderEx cbbEx = new CubicBezierBuilderEx(listMapPoints);
    bezier = cbbEx.ToSegment() as CubicBezierSegment;
    
    Create_BezierCurve
    //Create a bezier curve element with a simple line style.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D pt1 = new Coordinate2D(1, 7.5);
      Coordinate2D pt2 = new Coordinate2D(1.66, 8);
      Coordinate2D pt3 = new Coordinate2D(2.33, 7.1);
      Coordinate2D pt4 = new Coordinate2D(3, 7.5);
      //At 2.x - CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
      var bez = new CubicBezierBuilderEx(pt1, pt2, pt3, pt4);
      CubicBezierSegment bezSeg = bez.ToSegment();
      //At 2.x - Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg);
      Polyline bezPl = PolylineBuilderEx.CreatePolyline(bezSeg);
    
      //Set symbology, create and add element to layout
      CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 4.0, SimpleLineStyle.DashDot);
      //At 2.x - GraphicElement bezElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, bezPl, lineSym);
      //         bezElm.SetName("New Bezier Curve");
      GraphicElement bezElm = ElementFactory.Instance.CreateGraphicElement(layout, bezPl, lineSym, "New Bezier Curve");
    });
    Create_CurveText
    //Create curve text with basic text properties.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D pt1 = new Coordinate2D(3.6, 7.5);
      Coordinate2D pt2 = new Coordinate2D(4.26, 8);
      Coordinate2D pt3 = new Coordinate2D(4.93, 7.1);
      Coordinate2D pt4 = new Coordinate2D(5.6, 7.5);
      //At 2.x - CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
      var bez = new CubicBezierBuilderEx(pt1, pt2, pt3, pt4);
      CubicBezierSegment bezSeg = bez.ToSegment();
      //At 2.x - Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg);
      Polyline bezPl = PolylineBuilderEx.CreatePolyline(bezSeg);
    
      //Set symbolology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular");
      //At 2.x - GraphicElement bezTxtElm = LayoutElementFactory.Instance.CreateCurvedTextGraphicElement(layout, bezPl, "Curved Text", sym);
      //         bezTxtElm.SetName("New Splinned Text");
      GraphicElement bezTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
                                    layout, TextType.SplinedText, bezPl, sym, "Curved Text", "New Splinned Text");
    });
    Create Bezier Curve Element
    //Must be on QueuedTask.Run(() => { ...
    //Build geometry
    Coordinate2D pt1 = new Coordinate2D(1, 7.5);
    Coordinate2D pt2 = new Coordinate2D(1.66, 8);
    Coordinate2D pt3 = new Coordinate2D(2.33, 7.1);
    Coordinate2D pt4 = new Coordinate2D(3, 7.5);
    var bez = new CubicBezierBuilderEx(pt1, pt2, pt3, pt4);
    var bezSeg = bez.ToSegment();
    Polyline bezPl = PolylineBuilderEx.CreatePolyline(bezSeg, AttributeFlags.AllAttributes);
    
    //Set symbology, create and add element to layout
    CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(
      ColorFactory.Instance.RedRGB, 4.0, SimpleLineStyle.DashDot);
    
    ElementFactory.Instance.CreateGraphicElement(container, bezPl, lineSym, "New Bezier");
    
    Create Bezier Text Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D pt1 = new Coordinate2D(3.5, 7.5);
    Coordinate2D pt2 = new Coordinate2D(4.16, 8);
    Coordinate2D pt3 = new Coordinate2D(4.83, 7.1);
    Coordinate2D pt4 = new Coordinate2D(5.5, 7.5);
    var bez = new CubicBezierBuilderEx(pt1, pt2, pt3, pt4);
    var bezSeg = bez.ToSegment();
    Polyline bezPl = PolylineBuilderEx.CreatePolyline(bezSeg, AttributeFlags.AllAttributes);
    
    //Set symbolology, create and add element to layout
    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
      ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular");
    
    var ge = ElementFactory.Instance.CreateTextGraphicElement(
      container, TextType.SplinedText, bezPl, sym, "this is the bezier text",
            "New Bezier Text", true, new ElementInfo() { Anchor = Anchor.CenterPoint });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also