ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / PolylineBuilderEx Class / CreatePolyline Method / CreatePolyline(IEnumerable<MapPoint>,AttributeFlags,SpatialReference) Method
Points to create the polyline. Line segments are created from the coordinates of the points.
AttributeFlags to set the HasZ, HasM and HasID attributes. If no attributes should be set, pass AttributeFlags.None. If all attributes should be set, pass AttributeFlags.AllAttributes. Use the bitwise OR operator to set two attributes. For example, to set HasZ = true and HasM = true, pass AttributeFlags.HasZ | AttributeFlags.HasM. For performance reasons, the attributes of the input points are not used. However, if an attribute is specified, then the attribute values of the input points is used. For example, if AttributeFlags.HasZ is specified, then the Z-values of the input points is used for the newly created polyline.
(Optional) The SpatialReference. The default value is null. For performance reasons, the spatial references of the input points are ignored.
Example

In This Topic
    CreatePolyline(IEnumerable<MapPoint>,AttributeFlags,SpatialReference) Method
    In This Topic
    Convenience method to create a new instance of the Polyline class.
    Syntax
    Public Overloads Shared Function CreatePolyline( _
       ByVal points As IEnumerable(Of MapPoint), _
       ByVal attributes As AttributeFlags, _
       Optional ByVal spatialReference As SpatialReference _
    ) As Polyline

    Parameters

    points
    Points to create the polyline. Line segments are created from the coordinates of the points.
    attributes
    AttributeFlags to set the HasZ, HasM and HasID attributes. If no attributes should be set, pass AttributeFlags.None. If all attributes should be set, pass AttributeFlags.AllAttributes. Use the bitwise OR operator to set two attributes. For example, to set HasZ = true and HasM = true, pass AttributeFlags.HasZ | AttributeFlags.HasM. For performance reasons, the attributes of the input points are not used. However, if an attribute is specified, then the attribute values of the input points is used. For example, if AttributeFlags.HasZ is specified, then the Z-values of the input points is used for the newly created polyline.
    spatialReference
    (Optional) The SpatialReference. The default value is null. For performance reasons, the spatial references of the input points are ignored.

    Return Value

    Exceptions
    ExceptionDescription
    points is null.
    Example
    Builder Properties
    // list of points
    List<MapPoint> points = new List<MapPoint>
    {
      MapPointBuilderEx.CreateMapPoint(0, 0, 2, 3, 1),
      MapPointBuilderEx.CreateMapPoint(1, 1, 5, 6),
      MapPointBuilderEx.CreateMapPoint(2, 1, 6),
      MapPointBuilderEx.CreateMapPoint(0, 0)
    };
    
    // will have attributes because it is created with convenience method
    Polyline polylineWithAttrs = PolylineBuilderEx.CreatePolyline(points);
    bool hasZ = polylineWithAttrs.HasZ;          // hasZ = true
    bool hasM = polylineWithAttrs.HasM;          // hasM = true
    bool hasID = polylineWithAttrs.HasID;        // hasID = true
    
    // will not have attributes because it is specified as a parameter
    Polyline polylineWithoutAttrs = 
      PolylineBuilderEx.CreatePolyline(points, AttributeFlags.None);
    hasZ = polylineWithoutAttrs.HasZ;          // hasZ = false
    hasM = polylineWithoutAttrs.HasM;          // hasM = false
    hasID = polylineWithoutAttrs.HasID;        // hasID = false
    
    // will have attributes because it is created with convenience method
    Polygon polygonWithAttrs = PolygonBuilderEx.CreatePolygon(points);
    hasZ = polygonWithAttrs.HasZ;               // hasZ = true
    hasM = polygonWithAttrs.HasM;               // hasM = true
    hasID = polygonWithAttrs.HasID;             // hasID = true
    
    // will not have attributes because it is specified as a parameter
    Polygon polygonWithoutAttrs = 
          PolygonBuilderEx.CreatePolygon(points, AttributeFlags.None);
    hasZ = polygonWithoutAttrs.HasZ;               // hasZ = false
    hasM = polygonWithoutAttrs.HasM;               // hasM = false
    hasID = polygonWithoutAttrs.HasID;             // hasID = false
    
    // will not have attributes because it is specified as a parameter
    PolylineBuilderEx polylineB = 
               new PolylineBuilderEx(points, AttributeFlags.None);
    hasZ = polylineB.HasZ;                      // hasZ = false
    hasM = polylineB.HasM;                      // hasM = false
    hasID = polylineB.HasID;                    // hasID = false
    
    // will have attributes because it is passed an attributed polyline
    polylineB = new PolylineBuilderEx(polylineWithAttrs);
    hasZ = polylineB.HasZ;                      // hasZ = true
    hasM = polylineB.HasM;                      // hasM = true
    hasID = polylineB.HasID;                    // hasID = true
    
    // will not have attributes because it is passed a non-attributed polyline
    polylineB = new PolylineBuilderEx(polylineWithoutAttrs);
    hasZ = polylineB.HasZ;                      // hasZ = false
    hasM = polylineB.HasM;                      // hasM = false
    hasID = polylineB.HasID;                    // hasID = false
    
    // will not have attributes because it is specified as a parameter
    PolygonBuilderEx polygonB = new PolygonBuilderEx(points, AttributeFlags.None);
    hasZ = polygonB.HasZ;                       // hasZ = false
    hasM = polygonB.HasM;                       // hasM = false
    hasID = polygonB.HasID;                     // hasID = false
    
    // will have attributes because it is passed an attributed polygon
    polygonB = new PolygonBuilderEx(polygonWithAttrs);
    hasZ = polygonB.HasZ;                       // hasZ = true
    hasM = polygonB.HasM;                       // hasM = true
    hasID = polygonB.HasID;                     // hasID = true
    
    // will not have attributes because it is passed a non-attributed polygon
    polygonB = new PolygonBuilderEx(polygonWithoutAttrs);
    hasZ = polygonB.HasZ;                       // hasZ = true
    hasM = polygonB.HasM;                       // hasM = true
    hasID = polygonB.HasID;                     // hasID = true
    
    Create_freehand
    //Create a graphic freehand element with a simple line style.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      List<Coordinate2D> plCoords = new List<Coordinate2D>();
      plCoords.Add(new Coordinate2D(1.5, 10.5));
      plCoords.Add(new Coordinate2D(1.25, 9.5));
      plCoords.Add(new Coordinate2D(1, 10.5));
      plCoords.Add(new Coordinate2D(0.75, 9.5));
      plCoords.Add(new Coordinate2D(0.5, 10.5));
      plCoords.Add(new Coordinate2D(0.5, 1));
      plCoords.Add(new Coordinate2D(0.75, 2));
      plCoords.Add(new Coordinate2D(1, 1));
      //At 2.x - Polyline linePl = PolylineBuilder.CreatePolyline(plCoords);
      Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
      //Set symbolology, create and add element to layout
      CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
      //At 2.x - GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym);
      //         lineElm.SetName("New Freehand"); 
      GraphicElement lineElm = ElementFactory.Instance.CreateGraphicElement(layout, linePl, lineSym, "New Freehand");
    });
    Create_ellipse
    //Create an ellipse graphic with simple line and fill styles.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D center = new Coordinate2D(2, 2.75);
      //At 2.x - EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
      var eabElp = new EllipticArcBuilderEx(center, 0, 1, 0.45, ArcOrientation.ArcClockwise);
      EllipticArcSegment ellipse = eabElp.ToSegment();
    
      //Set symbolology, create and add element to layout
      CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2.0, SimpleLineStyle.Dot);
      CIMPolygonSymbol ellipseSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB, SimpleFillStyle.Vertical, outline);
      //At 2.x - GraphicElement elpElm = LayoutElementFactory.Instance.CreateEllipseGraphicElement(layout, ellipse, ellipseSym);
      //         elpElm.SetName("New Ellipse");
    
      var polyLine = PolylineBuilderEx.CreatePolyline(ellipse);
      GraphicElement elpElm = ElementFactory.Instance.CreateGraphicElement(layout, polyLine, ellipseSym, "New Ellipse");
    });
    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 Lasso Line, Freehand Graphic Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    List<Coordinate2D> plCoords = new List<Coordinate2D>();
    plCoords.Add(new Coordinate2D(1.5, 10.5));
    plCoords.Add(new Coordinate2D(1.25, 9.5));
    plCoords.Add(new Coordinate2D(1, 10.5));
    plCoords.Add(new Coordinate2D(0.75, 9.5));
    plCoords.Add(new Coordinate2D(0.5, 10.5));
    plCoords.Add(new Coordinate2D(0.5, 1));
    plCoords.Add(new Coordinate2D(0.75, 2));
    plCoords.Add(new Coordinate2D(1, 1));
    Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
    //Set symbolology, create and add element to layout
    CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(
              ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid);
    //var graphic = GraphicFactory.Instance.CreateShapeGraphic(linePl, lineSym);
    
    var ge = ElementFactory.Instance.CreateGraphicElement(
                            container, linePl, lineSym, "New Freehand");
    Create Line Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    List<Coordinate2D> plCoords = new List<Coordinate2D>();
    plCoords.Add(new Coordinate2D(1, 8.5));
    plCoords.Add(new Coordinate2D(1.66, 9));
    plCoords.Add(new Coordinate2D(2.33, 8.1));
    plCoords.Add(new Coordinate2D(3, 8.5));
    Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords);
    
    //Reference a line symbol in a style
    var ProjectStyles = Project.Current.GetItems<StyleProjectItem>();
    StyleProjectItem style = ProjectStyles.First(x => x.Name == "ArcGIS 2D");
    var symStyle = style.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0];
    CIMLineSymbol lineSym = symStyle.Symbol as CIMLineSymbol;
    lineSym.SetSize(20);
    
    //Set symbolology, create and add element to layout
    //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid);
    ElementFactory.Instance.CreateGraphicElement(
      container, linePl, lineSym, "New Line");
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also